3 test_description
='miscellaneous rev-list tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success setup
'
11 echo content1 >wanted_file &&
12 echo content2 >unwanted_file &&
13 git add wanted_file unwanted_file &&
18 test_expect_success
'rev-list --objects heeds pathspecs' '
19 git rev-list --objects HEAD -- wanted_file >output &&
20 grep wanted_file output &&
21 ! grep unwanted_file output
24 test_expect_success
'rev-list --objects with pathspecs and deeper paths' '
31 git rev-list --objects HEAD -- foo >output &&
32 grep foo/file output &&
34 git rev-list --objects HEAD -- foo/file >output &&
35 grep foo/file output &&
36 ! grep unwanted_file output
39 test_expect_success
'rev-list --objects with pathspecs and copied files' '
40 git checkout --orphan junio-testcase &&
46 git add one two/three &&
50 ONE=$(git rev-parse HEAD:one) &&
51 git rev-list --objects HEAD two >output &&
52 grep "$ONE two/three" output &&
56 test_expect_success
'rev-list --objects --no-object-names has no space/names' '
57 git rev-list --objects --no-object-names HEAD >output &&
58 ! grep wanted_file output &&
59 ! grep unwanted_file output &&
63 test_expect_success
'rev-list --objects --no-object-names works with cat-file' '
64 git rev-list --objects --no-object-names --all >list-output &&
65 git cat-file --batch-check <list-output >cat-output &&
66 ! grep missing cat-output
69 test_expect_success
'--no-object-names and --object-names are last-one-wins' '
70 git rev-list --objects --no-object-names --object-names --all >output &&
71 grep wanted_file output &&
72 git rev-list --objects --object-names --no-object-names --all >output &&
73 ! grep wanted_file output
76 test_expect_success
'rev-list A..B and rev-list ^A B are the same' '
78 git commit --allow-empty -m another &&
79 git tag -a -m "annotated" v1.0 &&
80 git rev-list --objects ^v1.0^ v1.0 >expect &&
81 git rev-list --objects v1.0^..v1.0 >actual &&
82 test_cmp expect actual
85 test_expect_success
'propagate uninteresting flag down correctly' '
86 git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
87 test_must_be_empty actual
90 test_expect_success
'symleft flag bit is propagated down from tag' '
91 git log --format="%m %s" --left-right v1.0...main >actual &&
92 cat >expect <<-\EOF &&
98 test_cmp expect actual
101 test_expect_success
'rev-list can show index objects' '
102 # Of the blobs and trees in the index, note:
104 # - we do not show two/three, because it is the
105 # same blob as "one", and we show objects only once
107 # - we do show the tree "two", because it has a valid cache tree
108 # from the last commit
110 # - we do not show the root tree; since we updated the index, it
111 # does not have a valid cache tree
113 echo only-in-index >only-in-index &&
114 test_when_finished "git reset --hard" &&
115 rev1=$(git rev-parse HEAD:one) &&
116 rev2=$(git rev-parse HEAD:two) &&
117 revi=$(git hash-object only-in-index) &&
118 cat >expect <<-EOF &&
123 git add only-in-index &&
124 git rev-list --objects --indexed-objects >actual &&
125 test_cmp expect actual
128 test_expect_success
'rev-list can negate index objects' '
129 git rev-parse HEAD >expect &&
130 git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
131 test_cmp expect actual
134 test_expect_success
'--bisect and --first-parent can be combined' '
135 git rev-list --bisect --first-parent HEAD
138 test_expect_success
'--header shows a NUL after each commit' '
139 # We know that there is no Q in the true payload; names and
140 # addresses of the authors and the committers do not have
141 # any, and object names or header names do not, either.
142 git rev-list --header --max-count=2 HEAD |
145 cat >expect <<-EOF &&
146 Q$(git rev-parse HEAD~1)
149 test_cmp expect actual
152 test_expect_success
'rev-list --end-of-options' '
153 git update-ref refs/heads/--output=yikes HEAD &&
154 git rev-list --end-of-options --output=yikes >actual &&
155 test_path_is_missing yikes &&
156 git rev-list HEAD >expect &&
157 test_cmp expect actual
160 test_expect_success
'rev-list --count' '
161 count=$(git rev-list --count HEAD) &&
162 git rev-list HEAD >actual &&
163 test_line_count = $count actual
166 test_expect_success
'rev-list --count --objects' '
167 count=$(git rev-list --count --objects HEAD) &&
168 git rev-list --objects HEAD >actual &&
169 test_line_count = $count actual
172 test_expect_success
'rev-list --unpacked' '
174 test_commit unpacked &&
176 git rev-list --objects --no-object-names unpacked^.. >expect.raw &&
177 sort expect.raw >expect &&
179 git rev-list --all --objects --unpacked --no-object-names >actual.raw &&
180 sort actual.raw >actual &&
182 test_cmp expect actual