3 test_description
='miscellaneous rev-list tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
12 echo content1 >wanted_file &&
13 echo content2 >unwanted_file &&
14 git add wanted_file unwanted_file &&
19 test_expect_success
'rev-list --objects heeds pathspecs' '
20 git rev-list --objects HEAD -- wanted_file >output &&
21 grep wanted_file output &&
22 ! grep unwanted_file output
25 test_expect_success
'rev-list --objects with pathspecs and deeper paths' '
32 git rev-list --objects HEAD -- foo >output &&
33 grep foo/file output &&
35 git rev-list --objects HEAD -- foo/file >output &&
36 grep foo/file output &&
37 ! grep unwanted_file output
40 test_expect_success
'rev-list --objects with pathspecs and copied files' '
41 git checkout --orphan junio-testcase &&
47 git add one two/three &&
51 ONE=$(git rev-parse HEAD:one) &&
52 git rev-list --objects HEAD two >output &&
53 grep "$ONE two/three" output &&
57 test_expect_success
'rev-list --objects --no-object-names has no space/names' '
58 git rev-list --objects --no-object-names HEAD >output &&
59 ! grep wanted_file output &&
60 ! grep unwanted_file output &&
64 test_expect_success
'rev-list --objects --no-object-names works with cat-file' '
65 git rev-list --objects --no-object-names --all >list-output &&
66 git cat-file --batch-check <list-output >cat-output &&
67 ! grep missing cat-output
70 test_expect_success
'--no-object-names and --object-names are last-one-wins' '
71 git rev-list --objects --no-object-names --object-names --all >output &&
72 grep wanted_file output &&
73 git rev-list --objects --object-names --no-object-names --all >output &&
74 ! grep wanted_file output
77 test_expect_success
'rev-list A..B and rev-list ^A B are the same' '
79 git commit --allow-empty -m another &&
80 git tag -a -m "annotated" v1.0 &&
81 git rev-list --objects ^v1.0^ v1.0 >expect &&
82 git rev-list --objects v1.0^..v1.0 >actual &&
83 test_cmp expect actual
86 test_expect_success
'propagate uninteresting flag down correctly' '
87 git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
88 test_must_be_empty actual
91 test_expect_success
'symleft flag bit is propagated down from tag' '
92 git log --format="%m %s" --left-right v1.0...main >actual &&
93 cat >expect <<-\EOF &&
99 test_cmp expect actual
102 test_expect_success
'rev-list can show index objects' '
103 # Of the blobs and trees in the index, note:
105 # - we do not show two/three, because it is the
106 # same blob as "one", and we show objects only once
108 # - we do show the tree "two", because it has a valid cache tree
109 # from the last commit
111 # - we do not show the root tree; since we updated the index, it
112 # does not have a valid cache tree
114 echo only-in-index >only-in-index &&
115 test_when_finished "git reset --hard" &&
116 rev1=$(git rev-parse HEAD:one) &&
117 rev2=$(git rev-parse HEAD:two) &&
118 revi=$(git hash-object only-in-index) &&
119 cat >expect <<-EOF &&
124 git add only-in-index &&
125 git rev-list --objects --indexed-objects >actual &&
126 test_cmp expect actual
129 test_expect_success
'rev-list can negate index objects' '
130 git rev-parse HEAD >expect &&
131 git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
132 test_cmp expect actual
135 test_expect_success
'--bisect and --first-parent can be combined' '
136 git rev-list --bisect --first-parent HEAD
139 test_expect_success
'--header shows a NUL after each commit' '
140 # We know that there is no Q in the true payload; names and
141 # addresses of the authors and the committers do not have
142 # any, and object names or header names do not, either.
143 git rev-list --header --max-count=2 HEAD |
146 cat >expect <<-EOF &&
147 Q$(git rev-parse HEAD~1)
150 test_cmp expect actual
153 test_expect_success
'rev-list --end-of-options' '
154 git update-ref refs/heads/--output=yikes HEAD &&
155 git rev-list --end-of-options --output=yikes >actual &&
156 test_path_is_missing yikes &&
157 git rev-list HEAD >expect &&
158 test_cmp expect actual
161 test_expect_success
'rev-list --count' '
162 count=$(git rev-list --count HEAD) &&
163 git rev-list HEAD >actual &&
164 test_line_count = $count actual
167 test_expect_success
'rev-list --count --objects' '
168 count=$(git rev-list --count --objects HEAD) &&
169 git rev-list --objects HEAD >actual &&
170 test_line_count = $count actual
173 test_expect_success
'rev-list --unpacked' '
175 test_commit unpacked &&
177 git rev-list --objects --no-object-names unpacked^.. >expect.raw &&
178 sort expect.raw >expect &&
180 git rev-list --all --objects --unpacked --no-object-names >actual.raw &&
181 sort actual.raw >actual &&
183 test_cmp expect actual