]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1403-show-ref.sh
The third batch
[thirdparty/git.git] / t / t1403-show-ref.sh
CommitLineData
3f3d0cea
DB
1#!/bin/sh
2
3test_description='show-ref'
06d53148 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
9081a421 7TEST_PASSES_SANITIZE_LEAK=true
3f3d0cea
DB
8. ./test-lib.sh
9
10test_expect_success setup '
6cf8d96f 11 test_commit --annotate A &&
3f3d0cea 12 git checkout -b side &&
6cf8d96f 13 test_commit --annotate B &&
06d53148 14 git checkout main &&
3f3d0cea
DB
15 test_commit C &&
16 git branch B A^0
17'
18
19test_expect_success 'show-ref' '
20 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
21
22 git show-ref A >actual &&
23 test_cmp expect actual &&
24
25 git show-ref tags/A >actual &&
26 test_cmp expect actual &&
27
28 git show-ref refs/tags/A >actual &&
29 test_cmp expect actual &&
30
8fb26872 31 test_must_fail git show-ref D >actual &&
d3c6751b 32 test_must_be_empty actual
3f3d0cea
DB
33'
34
35test_expect_success 'show-ref -q' '
3f3d0cea 36 git show-ref -q A >actual &&
d3c6751b 37 test_must_be_empty actual &&
3f3d0cea
DB
38
39 git show-ref -q tags/A >actual &&
d3c6751b 40 test_must_be_empty actual &&
3f3d0cea
DB
41
42 git show-ref -q refs/tags/A >actual &&
d3c6751b 43 test_must_be_empty actual &&
3f3d0cea
DB
44
45 test_must_fail git show-ref -q D >actual &&
d3c6751b 46 test_must_be_empty actual
3f3d0cea
DB
47'
48
49test_expect_success 'show-ref --verify' '
50 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
51
52 git show-ref --verify refs/tags/A >actual &&
53 test_cmp expect actual &&
54
3f3d0cea 55 test_must_fail git show-ref --verify A >actual &&
d3c6751b 56 test_must_be_empty actual &&
3f3d0cea
DB
57
58 test_must_fail git show-ref --verify tags/A >actual &&
d3c6751b 59 test_must_be_empty actual &&
3f3d0cea 60
8fb26872 61 test_must_fail git show-ref --verify D >actual &&
d3c6751b 62 test_must_be_empty actual
3f3d0cea
DB
63'
64
65test_expect_success 'show-ref --verify -q' '
3f3d0cea 66 git show-ref --verify -q refs/tags/A >actual &&
d3c6751b 67 test_must_be_empty actual &&
3f3d0cea
DB
68
69 test_must_fail git show-ref --verify -q A >actual &&
d3c6751b 70 test_must_be_empty actual &&
3f3d0cea
DB
71
72 test_must_fail git show-ref --verify -q tags/A >actual &&
d3c6751b 73 test_must_be_empty actual &&
3f3d0cea 74
8fb26872 75 test_must_fail git show-ref --verify -q D >actual &&
d3c6751b 76 test_must_be_empty actual
3f3d0cea
DB
77'
78
79test_expect_success 'show-ref -d' '
80 {
81 echo $(git rev-parse refs/tags/A) refs/tags/A &&
7abcbcb7 82 echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" &&
3f3d0cea
DB
83 echo $(git rev-parse refs/tags/C) refs/tags/C
84 } >expect &&
85 git show-ref -d A C >actual &&
86 test_cmp expect actual &&
87
88 git show-ref -d tags/A tags/C >actual &&
89 test_cmp expect actual &&
90
91 git show-ref -d refs/tags/A refs/tags/C >actual &&
92 test_cmp expect actual &&
93
f1627040
VP
94 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
95 test_cmp expect actual &&
96
06d53148
JS
97 echo $(git rev-parse refs/heads/main) refs/heads/main >expect &&
98 git show-ref -d main >actual &&
3f3d0cea
DB
99 test_cmp expect actual &&
100
06d53148 101 git show-ref -d heads/main >actual &&
3f3d0cea
DB
102 test_cmp expect actual &&
103
06d53148 104 git show-ref -d refs/heads/main >actual &&
8fb26872 105 test_cmp expect actual &&
3f3d0cea 106
06d53148 107 git show-ref -d --verify refs/heads/main >actual &&
8fb26872 108 test_cmp expect actual &&
3f3d0cea 109
06d53148 110 test_must_fail git show-ref -d --verify main >actual &&
d3c6751b 111 test_must_be_empty actual &&
3f3d0cea 112
06d53148 113 test_must_fail git show-ref -d --verify heads/main >actual &&
d3c6751b 114 test_must_be_empty actual &&
f1627040
VP
115
116 test_must_fail git show-ref --verify -d A C >actual &&
d3c6751b 117 test_must_be_empty actual &&
f1627040
VP
118
119 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
d3c6751b 120 test_must_be_empty actual
3f3d0cea
DB
121
122'
123
124test_expect_success 'show-ref --heads, --tags, --head, pattern' '
06d53148 125 for branch in B main side
3f3d0cea 126 do
db5875aa 127 echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
3f3d0cea
DB
128 done >expect.heads &&
129 git show-ref --heads >actual &&
130 test_cmp expect.heads actual &&
131
132 for tag in A B C
133 do
db5875aa 134 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
3f3d0cea
DB
135 done >expect.tags &&
136 git show-ref --tags >actual &&
137 test_cmp expect.tags actual &&
138
139 cat expect.heads expect.tags >expect &&
140 git show-ref --heads --tags >actual &&
141 test_cmp expect actual &&
142
143 {
144 echo $(git rev-parse HEAD) HEAD &&
145 cat expect.heads expect.tags
146 } >expect &&
147 git show-ref --heads --tags --head >actual &&
148 test_cmp expect actual &&
149
150 {
151 echo $(git rev-parse HEAD) HEAD &&
7abcbcb7 152 echo $(git rev-parse refs/heads/B) refs/heads/B &&
3f3d0cea
DB
153 echo $(git rev-parse refs/tags/B) refs/tags/B
154 } >expect &&
155 git show-ref --head B >actual &&
156 test_cmp expect actual &&
157
158 {
159 echo $(git rev-parse HEAD) HEAD &&
7abcbcb7
ES
160 echo $(git rev-parse refs/heads/B) refs/heads/B &&
161 echo $(git rev-parse refs/tags/B) refs/tags/B &&
3f3d0cea
DB
162 echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
163 } >expect &&
164 git show-ref --head -d B >actual &&
165 test_cmp expect actual
166'
167
ec7c51bc
VP
168test_expect_success 'show-ref --verify HEAD' '
169 echo $(git rev-parse HEAD) HEAD >expect &&
170 git show-ref --verify HEAD >actual &&
171 test_cmp expect actual &&
172
ec7c51bc 173 git show-ref --verify -q HEAD >actual &&
d3c6751b 174 test_must_be_empty actual
ec7c51bc
VP
175'
176
1dbe4015
PW
177test_expect_success 'show-ref --verify pseudorefs' '
178 git update-ref CHERRY_PICK_HEAD HEAD $ZERO_OID &&
179 test_when_finished "git update-ref -d CHERRY_PICK_HEAD" &&
180 git show-ref -s --verify HEAD >actual &&
181 git show-ref -s --verify CHERRY_PICK_HEAD >expect &&
182 test_cmp actual expect
183'
184
d01b8203
VP
185test_expect_success 'show-ref --verify with dangling ref' '
186 sha1_file() {
187 echo "$*" | sed "s#..#.git/objects/&/#"
188 } &&
189
190 remove_object() {
191 file=$(sha1_file "$*") &&
192 test -e "$file" &&
193 rm -f "$file"
194 } &&
195
196 test_when_finished "rm -rf dangling" &&
197 (
198 git init dangling &&
199 cd dangling &&
200 test_commit dangling &&
201 sha=$(git rev-parse refs/tags/dangling) &&
202 remove_object $sha &&
203 test_must_fail git show-ref --verify refs/tags/dangling
204 )
205'
206
199970e7 207test_expect_success 'show-ref sub-modes are mutually exclusive' '
199970e7 208 test_must_fail git show-ref --verify --exclude-existing 2>err &&
73824973
RS
209 grep "verify" err &&
210 grep "exclude-existing" err &&
211 grep "cannot be used together" err &&
9080a7f1
PS
212
213 test_must_fail git show-ref --verify --exists 2>err &&
73824973
RS
214 grep "verify" err &&
215 grep "exists" err &&
216 grep "cannot be used together" err &&
9080a7f1
PS
217
218 test_must_fail git show-ref --exclude-existing --exists 2>err &&
73824973
RS
219 grep "exclude-existing" err &&
220 grep "exists" err &&
221 grep "cannot be used together" err
9080a7f1
PS
222'
223
224test_expect_success '--exists with existing reference' '
225 git show-ref --exists refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
226'
227
228test_expect_success '--exists with missing reference' '
229 test_expect_code 2 git show-ref --exists refs/heads/does-not-exist
230'
231
232test_expect_success '--exists does not use DWIM' '
233 test_expect_code 2 git show-ref --exists $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err &&
234 grep "reference does not exist" err
235'
236
237test_expect_success '--exists with HEAD' '
238 git show-ref --exists HEAD
239'
240
241test_expect_success '--exists with bad reference name' '
242 test_when_finished "git update-ref -d refs/heads/bad...name" &&
243 new_oid=$(git rev-parse HEAD) &&
244 test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
245 git show-ref --exists refs/heads/bad...name
246'
247
248test_expect_success '--exists with arbitrary symref' '
249 test_when_finished "git symbolic-ref -d refs/symref" &&
250 git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
251 git show-ref --exists refs/symref
252'
253
254test_expect_success '--exists with dangling symref' '
255 test_when_finished "git symbolic-ref -d refs/heads/dangling" &&
256 git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
257 git show-ref --exists refs/heads/dangling
258'
259
260test_expect_success '--exists with nonexistent object ID' '
261 test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION &&
262 git show-ref --exists refs/heads/missing-oid
263'
264
265test_expect_success '--exists with non-commit object' '
266 tree_oid=$(git rev-parse HEAD^{tree}) &&
267 test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION &&
268 git show-ref --exists refs/heads/tree
269'
270
271test_expect_success '--exists with directory fails with generic error' '
272 cat >expect <<-EOF &&
0aabeaa5 273 error: reference does not exist
9080a7f1 274 EOF
0aabeaa5 275 test_expect_code 2 git show-ref --exists refs/heads 2>err &&
199970e7
PS
276 test_cmp expect err
277'
278
668cdc04
PS
279test_expect_success '--exists with non-existent special ref' '
280 test_expect_code 2 git show-ref --exists FETCH_HEAD
281'
282
283test_expect_success '--exists with existing special ref' '
284 test_when_finished "rm .git/FETCH_HEAD" &&
285 git rev-parse HEAD >.git/FETCH_HEAD &&
286 git show-ref --exists FETCH_HEAD
287'
288
3f3d0cea 289test_done