]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6000-rev-list-misc.sh
Merge branch 'pb/ci-matrix-wo-shortcut'
[thirdparty/git.git] / t / t6000-rev-list-misc.sh
CommitLineData
a97a96fc
EN
1#!/bin/sh
2
3test_description='miscellaneous rev-list tests'
4
1550bb6e 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
a97a96fc
EN
8. ./test-lib.sh
9
10test_expect_success setup '
11 echo content1 >wanted_file &&
12 echo content2 >unwanted_file &&
13 git add wanted_file unwanted_file &&
f421e029 14 test_tick &&
a97a96fc
EN
15 git commit -m one
16'
17
18test_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
22'
23
24test_expect_success 'rev-list --objects with pathspecs and deeper paths' '
25 mkdir foo &&
26 >foo/file &&
27 git add foo/file &&
f421e029 28 test_tick &&
a97a96fc
EN
29 git commit -m two &&
30
31 git rev-list --objects HEAD -- foo >output &&
32 grep foo/file output &&
33
34 git rev-list --objects HEAD -- foo/file >output &&
35 grep foo/file output &&
36 ! grep unwanted_file output
37'
38
39test_expect_success 'rev-list --objects with pathspecs and copied files' '
40 git checkout --orphan junio-testcase &&
41 git rm -rf . &&
42
43 mkdir two &&
44 echo frotz >one &&
45 cp one two/three &&
46 git add one two/three &&
47 test_tick &&
48 git commit -m that &&
49
99094a7a 50 ONE=$(git rev-parse HEAD:one) &&
a97a96fc
EN
51 git rev-list --objects HEAD two >output &&
52 grep "$ONE two/three" output &&
53 ! grep one output
54'
55
42357b4e
ES
56test_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 &&
60 ! grep " " output
61'
62
63test_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
67'
68
69test_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
74'
75
895c5ba3 76test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
f421e029 77 test_tick &&
895c5ba3
JH
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
83'
84
2ac5e447
JH
85test_expect_success 'propagate uninteresting flag down correctly' '
86 git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
d3c6751b 87 test_must_be_empty actual
2ac5e447
JH
88'
89
a7435286 90test_expect_success 'symleft flag bit is propagated down from tag' '
1550bb6e 91 git log --format="%m %s" --left-right v1.0...main >actual &&
a7435286 92 cat >expect <<-\EOF &&
a7435286
JH
93 < another
94 < that
f421e029
JK
95 > two
96 > one
a7435286
JH
97 EOF
98 test_cmp expect actual
99'
100
4fe10219
JK
101test_expect_success 'rev-list can show index objects' '
102 # Of the blobs and trees in the index, note:
103 #
104 # - we do not show two/three, because it is the
105 # same blob as "one", and we show objects only once
106 #
107 # - we do show the tree "two", because it has a valid cache tree
108 # from the last commit
109 #
110 # - we do not show the root tree; since we updated the index, it
111 # does not have a valid cache tree
112 #
4fe10219 113 echo only-in-index >only-in-index &&
b4cfcde4 114 test_when_finished "git reset --hard" &&
5db24dcf 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 &&
119 $rev1 one
120 $revi only-in-index
121 $rev2 two
122 EOF
4fe10219
JK
123 git add only-in-index &&
124 git rev-list --objects --indexed-objects >actual &&
125 test_cmp expect actual
126'
127
b4cfcde4
JK
128test_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
132'
133
0fe305a5
AL
134test_expect_success '--bisect and --first-parent can be combined' '
135 git rev-list --bisect --first-parent HEAD
f88851c6
KD
136'
137
98985c69
JK
138test_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 |
143 nul_to_q |
144 grep "^Q" >actual &&
145 cat >expect <<-EOF &&
146 Q$(git rev-parse HEAD~1)
147 Q
148 EOF
149 test_cmp expect actual
150'
151
19e8789b
JK
152test_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
158'
159
55cb10f9
JK
160test_expect_success 'rev-list --count' '
161 count=$(git rev-list --count HEAD) &&
162 git rev-list HEAD >actual &&
163 test_line_count = $count actual
164'
165
166test_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
170'
171
a97a96fc 172test_done