]>
Commit | Line | Data |
---|---|---|
ef5a6fb5 CR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Carlos Rica | |
4 | # | |
5 | ||
d592b315 | 6 | test_description='git tag |
ef5a6fb5 | 7 | |
62e09ce9 | 8 | Tests for operations with tags.' |
ef5a6fb5 | 9 | |
01dc8133 | 10 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
11 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
12 | ||
ef5a6fb5 | 13 | . ./test-lib.sh |
37d3e859 | 14 | . "$TEST_DIRECTORY"/lib-gpg.sh |
11b087ad | 15 | . "$TEST_DIRECTORY"/lib-terminal.sh |
ef5a6fb5 CR |
16 | |
17 | # creating and listing lightweight tags: | |
18 | ||
19 | tag_exists () { | |
20 | git show-ref --quiet --verify refs/tags/"$1" | |
21 | } | |
22 | ||
62e09ce9 CR |
23 | test_expect_success 'listing all tags in an empty tree should succeed' ' |
24 | git tag -l && | |
25 | git tag | |
26 | ' | |
ef5a6fb5 | 27 | |
62e09ce9 | 28 | test_expect_success 'listing all tags in an empty tree should output nothing' ' |
63873a0a EP |
29 | test $(git tag -l | wc -l) -eq 0 && |
30 | test $(git tag | wc -l) -eq 0 | |
62e09ce9 | 31 | ' |
ef5a6fb5 | 32 | |
3bb16a8b NTND |
33 | test_expect_success 'sort tags, ignore case' ' |
34 | ( | |
35 | git init sort && | |
36 | cd sort && | |
37 | test_commit initial && | |
38 | git tag tag-one && | |
39 | git tag TAG-two && | |
40 | git tag -l >actual && | |
41 | cat >expected <<-\EOF && | |
42 | TAG-two | |
43 | initial | |
44 | tag-one | |
45 | EOF | |
46 | test_cmp expected actual && | |
47 | git tag -l -i >actual && | |
48 | cat >expected <<-\EOF && | |
49 | initial | |
50 | tag-one | |
51 | TAG-two | |
52 | EOF | |
53 | test_cmp expected actual | |
54 | ) | |
55 | ' | |
56 | ||
41ac414e JH |
57 | test_expect_success 'looking for a tag in an empty tree should fail' \ |
58 | '! (tag_exists mytag)' | |
ef5a6fb5 CR |
59 | |
60 | test_expect_success 'creating a tag in an empty tree should fail' ' | |
d592b315 | 61 | test_must_fail git tag mynotag && |
ef5a6fb5 CR |
62 | ! tag_exists mynotag |
63 | ' | |
64 | ||
65 | test_expect_success 'creating a tag for HEAD in an empty tree should fail' ' | |
d592b315 | 66 | test_must_fail git tag mytaghead HEAD && |
ef5a6fb5 CR |
67 | ! tag_exists mytaghead |
68 | ' | |
69 | ||
70 | test_expect_success 'creating a tag for an unknown revision should fail' ' | |
d592b315 | 71 | test_must_fail git tag mytagnorev aaaaaaaaaaa && |
ef5a6fb5 CR |
72 | ! tag_exists mytagnorev |
73 | ' | |
74 | ||
75 | # commit used in the tests, test_tick is also called here to freeze the date: | |
76 | test_expect_success 'creating a tag using default HEAD should succeed' ' | |
341fb286 | 77 | test_config core.logAllRefUpdates true && |
ef5a6fb5 CR |
78 | test_tick && |
79 | echo foo >foo && | |
80 | git add foo && | |
81 | git commit -m Foo && | |
144c76fa DT |
82 | git tag mytag && |
83 | test_must_fail git reflog exists refs/tags/mytag | |
84 | ' | |
85 | ||
86 | test_expect_success 'creating a tag with --create-reflog should create reflog' ' | |
df8512ed CW |
87 | git log -1 \ |
88 | --format="format:tag: tagging %h (%s, %cd)%n" \ | |
89 | --date=format:%Y-%m-%d >expected && | |
144c76fa DT |
90 | test_when_finished "git tag -d tag_with_reflog" && |
91 | git tag --create-reflog tag_with_reflog && | |
df8512ed CW |
92 | git reflog exists refs/tags/tag_with_reflog && |
93 | sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && | |
0d75bfe6 | 94 | test_i18ncmp expected actual |
df8512ed CW |
95 | ' |
96 | ||
97 | test_expect_success 'annotated tag with --create-reflog has correct message' ' | |
98 | git log -1 \ | |
99 | --format="format:tag: tagging %h (%s, %cd)%n" \ | |
100 | --date=format:%Y-%m-%d >expected && | |
101 | test_when_finished "git tag -d tag_with_reflog" && | |
102 | git tag -m "annotated tag" --create-reflog tag_with_reflog && | |
103 | git reflog exists refs/tags/tag_with_reflog && | |
104 | sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && | |
0d75bfe6 | 105 | test_i18ncmp expected actual |
144c76fa DT |
106 | ' |
107 | ||
108 | test_expect_success '--create-reflog does not create reflog on failure' ' | |
109 | test_must_fail git tag --create-reflog mytag && | |
110 | test_must_fail git reflog exists refs/tags/mytag | |
ef5a6fb5 CR |
111 | ' |
112 | ||
341fb286 CW |
113 | test_expect_success 'option core.logAllRefUpdates=always creates reflog' ' |
114 | test_when_finished "git tag -d tag_with_reflog" && | |
115 | test_config core.logAllRefUpdates always && | |
116 | git tag tag_with_reflog && | |
117 | git reflog exists refs/tags/tag_with_reflog | |
118 | ' | |
119 | ||
62e09ce9 | 120 | test_expect_success 'listing all tags if one exists should succeed' ' |
d592b315 NS |
121 | git tag -l && |
122 | git tag | |
62e09ce9 | 123 | ' |
ef5a6fb5 | 124 | |
c485b24c ÆAB |
125 | cat >expect <<EOF |
126 | mytag | |
127 | EOF | |
128 | test_expect_success 'Multiple -l or --list options are equivalent to one -l option' ' | |
129 | git tag -l -l >actual && | |
130 | test_cmp expect actual && | |
131 | git tag --list --list >actual && | |
132 | test_cmp expect actual && | |
133 | git tag --list -l --list >actual && | |
134 | test_cmp expect actual | |
135 | ' | |
136 | ||
62e09ce9 | 137 | test_expect_success 'listing all tags if one exists should output that tag' ' |
63873a0a EP |
138 | test $(git tag -l) = mytag && |
139 | test $(git tag) = mytag | |
62e09ce9 | 140 | ' |
ef5a6fb5 CR |
141 | |
142 | # pattern matching: | |
143 | ||
144 | test_expect_success 'listing a tag using a matching pattern should succeed' \ | |
d592b315 | 145 | 'git tag -l mytag' |
ef5a6fb5 | 146 | |
3bb16a8b NTND |
147 | test_expect_success 'listing a tag with --ignore-case' \ |
148 | 'test $(git tag -l --ignore-case MYTAG) = mytag' | |
149 | ||
ef5a6fb5 CR |
150 | test_expect_success \ |
151 | 'listing a tag using a matching pattern should output that tag' \ | |
63873a0a | 152 | 'test $(git tag -l mytag) = mytag' |
ef5a6fb5 | 153 | |
ef5a6fb5 | 154 | test_expect_success \ |
682b29f9 | 155 | 'listing tags using a non-matching pattern should succeed' \ |
d592b315 | 156 | 'git tag -l xxx' |
ef5a6fb5 CR |
157 | |
158 | test_expect_success \ | |
159 | 'listing tags using a non-matching pattern should output nothing' \ | |
63873a0a | 160 | 'test $(git tag -l xxx | wc -l) -eq 0' |
ef5a6fb5 CR |
161 | |
162 | # special cases for creating tags: | |
163 | ||
41ac414e | 164 | test_expect_success \ |
ef5a6fb5 | 165 | 'trying to create a tag with the name of one existing should fail' \ |
d492b31c | 166 | 'test_must_fail git tag mytag' |
ef5a6fb5 CR |
167 | |
168 | test_expect_success \ | |
169 | 'trying to create a tag with a non-valid name should fail' ' | |
63873a0a | 170 | test $(git tag -l | wc -l) -eq 1 && |
d492b31c SB |
171 | test_must_fail git tag "" && |
172 | test_must_fail git tag .othertag && | |
173 | test_must_fail git tag "other tag" && | |
174 | test_must_fail git tag "othertag^" && | |
175 | test_must_fail git tag "other~tag" && | |
63873a0a | 176 | test $(git tag -l | wc -l) -eq 1 |
ef5a6fb5 CR |
177 | ' |
178 | ||
179 | test_expect_success 'creating a tag using HEAD directly should succeed' ' | |
180 | git tag myhead HEAD && | |
181 | tag_exists myhead | |
182 | ' | |
183 | ||
3ae851e6 PH |
184 | test_expect_success '--force can create a tag with the name of one existing' ' |
185 | tag_exists mytag && | |
186 | git tag --force mytag && | |
187 | tag_exists mytag' | |
188 | ||
189 | test_expect_success '--force is moot with a non-existing tag name' ' | |
eba286e3 | 190 | test_when_finished git tag -d newtag forcetag && |
3ae851e6 PH |
191 | git tag newtag >expect && |
192 | git tag --force forcetag >actual && | |
193 | test_cmp expect actual | |
194 | ' | |
3ae851e6 | 195 | |
ef5a6fb5 CR |
196 | # deleting tags: |
197 | ||
198 | test_expect_success 'trying to delete an unknown tag should fail' ' | |
199 | ! tag_exists unknown-tag && | |
d592b315 | 200 | test_must_fail git tag -d unknown-tag |
ef5a6fb5 CR |
201 | ' |
202 | ||
203 | cat >expect <<EOF | |
204 | myhead | |
205 | mytag | |
206 | EOF | |
207 | test_expect_success \ | |
208 | 'trying to delete tags without params should succeed and do nothing' ' | |
3af82863 | 209 | git tag -l > actual && test_cmp expect actual && |
d592b315 | 210 | git tag -d && |
3af82863 | 211 | git tag -l > actual && test_cmp expect actual |
ef5a6fb5 CR |
212 | ' |
213 | ||
214 | test_expect_success \ | |
215 | 'deleting two existing tags in one command should succeed' ' | |
216 | tag_exists mytag && | |
217 | tag_exists myhead && | |
d592b315 | 218 | git tag -d mytag myhead && |
ef5a6fb5 CR |
219 | ! tag_exists mytag && |
220 | ! tag_exists myhead | |
221 | ' | |
222 | ||
223 | test_expect_success \ | |
224 | 'creating a tag with the name of another deleted one should succeed' ' | |
225 | ! tag_exists mytag && | |
d592b315 | 226 | git tag mytag && |
ef5a6fb5 CR |
227 | tag_exists mytag |
228 | ' | |
229 | ||
230 | test_expect_success \ | |
231 | 'trying to delete two tags, existing and not, should fail in the 2nd' ' | |
232 | tag_exists mytag && | |
b0187199 MÅ |
233 | ! tag_exists nonexistingtag && |
234 | test_must_fail git tag -d mytag nonexistingtag && | |
ef5a6fb5 | 235 | ! tag_exists mytag && |
b0187199 | 236 | ! tag_exists nonexistingtag |
ef5a6fb5 CR |
237 | ' |
238 | ||
41ac414e | 239 | test_expect_success 'trying to delete an already deleted tag should fail' \ |
d592b315 | 240 | 'test_must_fail git tag -d mytag' |
ef5a6fb5 CR |
241 | |
242 | # listing various tags with pattern matching: | |
243 | ||
244 | cat >expect <<EOF | |
245 | a1 | |
246 | aa1 | |
247 | cba | |
248 | t210 | |
249 | t211 | |
250 | v0.2.1 | |
251 | v1.0 | |
252 | v1.0.1 | |
253 | v1.1.3 | |
254 | EOF | |
255 | test_expect_success 'listing all tags should print them ordered' ' | |
256 | git tag v1.0.1 && | |
257 | git tag t211 && | |
258 | git tag aa1 && | |
259 | git tag v0.2.1 && | |
260 | git tag v1.1.3 && | |
261 | git tag cba && | |
262 | git tag a1 && | |
263 | git tag v1.0 && | |
264 | git tag t210 && | |
5206d130 | 265 | git tag -l > actual && |
3af82863 | 266 | test_cmp expect actual && |
62e09ce9 | 267 | git tag > actual && |
3af82863 | 268 | test_cmp expect actual |
ef5a6fb5 CR |
269 | ' |
270 | ||
271 | cat >expect <<EOF | |
272 | a1 | |
273 | aa1 | |
274 | cba | |
275 | EOF | |
276 | test_expect_success \ | |
277 | 'listing tags with substring as pattern must print those matching' ' | |
0aaaef7b JS |
278 | rm *a* && |
279 | git tag -l "*a*" > current && | |
280 | test_cmp expect current | |
ef5a6fb5 CR |
281 | ' |
282 | ||
283 | cat >expect <<EOF | |
284 | v0.2.1 | |
285 | v1.0.1 | |
ef5a6fb5 CR |
286 | EOF |
287 | test_expect_success \ | |
18e32b5b | 288 | 'listing tags with a suffix as pattern must print those matching' ' |
d592b315 | 289 | git tag -l "*.1" > actual && |
3af82863 | 290 | test_cmp expect actual |
ef5a6fb5 CR |
291 | ' |
292 | ||
293 | cat >expect <<EOF | |
294 | t210 | |
295 | t211 | |
296 | EOF | |
297 | test_expect_success \ | |
18e32b5b | 298 | 'listing tags with a prefix as pattern must print those matching' ' |
d592b315 | 299 | git tag -l "t21*" > actual && |
3af82863 | 300 | test_cmp expect actual |
ef5a6fb5 CR |
301 | ' |
302 | ||
303 | cat >expect <<EOF | |
304 | a1 | |
ef5a6fb5 CR |
305 | EOF |
306 | test_expect_success \ | |
18e32b5b | 307 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 308 | git tag -l a1 > actual && |
3af82863 | 309 | test_cmp expect actual |
ef5a6fb5 CR |
310 | ' |
311 | ||
312 | cat >expect <<EOF | |
313 | v1.0 | |
ef5a6fb5 CR |
314 | EOF |
315 | test_expect_success \ | |
18e32b5b | 316 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 317 | git tag -l v1.0 > actual && |
3af82863 | 318 | test_cmp expect actual |
ef5a6fb5 CR |
319 | ' |
320 | ||
321 | cat >expect <<EOF | |
18e32b5b | 322 | v1.0.1 |
ef5a6fb5 CR |
323 | v1.1.3 |
324 | EOF | |
325 | test_expect_success \ | |
326 | 'listing tags with ? in the pattern should print those matching' ' | |
d592b315 | 327 | git tag -l "v1.?.?" > actual && |
3af82863 | 328 | test_cmp expect actual |
ef5a6fb5 CR |
329 | ' |
330 | ||
ef5a6fb5 CR |
331 | test_expect_success \ |
332 | 'listing tags using v.* should print nothing because none have v.' ' | |
d592b315 | 333 | git tag -l "v.*" > actual && |
1c5e94f4 | 334 | test_must_be_empty actual |
ef5a6fb5 CR |
335 | ' |
336 | ||
337 | cat >expect <<EOF | |
338 | v0.2.1 | |
339 | v1.0 | |
340 | v1.0.1 | |
341 | v1.1.3 | |
342 | EOF | |
343 | test_expect_success \ | |
344 | 'listing tags using v* should print only those having v' ' | |
d592b315 | 345 | git tag -l "v*" > actual && |
3af82863 | 346 | test_cmp expect actual |
ef5a6fb5 CR |
347 | ' |
348 | ||
588d0e83 JK |
349 | test_expect_success 'tag -l can accept multiple patterns' ' |
350 | git tag -l "v1*" "v0*" >actual && | |
351 | test_cmp expect actual | |
352 | ' | |
353 | ||
c485b24c ÆAB |
354 | # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation |
355 | # could leave you with the impression that "-l <pattern> -l <pattern>" | |
356 | # was how we wanted to accept multiple patterns. | |
357 | # | |
358 | # This test should not imply that this is a sane thing to support. but | |
359 | # since the documentation was worded like it was let's at least find | |
360 | # out if we're going to break this long-documented form of taking | |
361 | # multiple patterns. | |
362 | test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' ' | |
363 | git tag -l "v1*" -l "v0*" >actual && | |
364 | test_cmp expect actual | |
365 | ' | |
366 | ||
d96e3c15 | 367 | test_expect_success 'listing tags in column' ' |
b5d5a567 | 368 | COLUMNS=41 git tag -l --column=row >actual && |
d96e3c15 NTND |
369 | cat >expected <<\EOF && |
370 | a1 aa1 cba t210 t211 | |
371 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
372 | EOF | |
373 | test_cmp expected actual | |
374 | ' | |
375 | ||
376 | test_expect_success 'listing tags in column with column.*' ' | |
9ffda48f SG |
377 | test_config column.tag row && |
378 | test_config column.ui dense && | |
d96e3c15 | 379 | COLUMNS=40 git tag -l >actual && |
d96e3c15 NTND |
380 | cat >expected <<\EOF && |
381 | a1 aa1 cba t210 t211 | |
382 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
383 | EOF | |
384 | test_cmp expected actual | |
385 | ' | |
386 | ||
387 | test_expect_success 'listing tag with -n --column should fail' ' | |
388 | test_must_fail git tag --column -n | |
389 | ' | |
390 | ||
391 | test_expect_success 'listing tags -n in column with column.ui ignored' ' | |
9ffda48f | 392 | test_config column.ui "row dense" && |
d96e3c15 | 393 | COLUMNS=40 git tag -l -n >actual && |
d96e3c15 NTND |
394 | cat >expected <<\EOF && |
395 | a1 Foo | |
396 | aa1 Foo | |
397 | cba Foo | |
398 | t210 Foo | |
399 | t211 Foo | |
400 | v0.2.1 Foo | |
401 | v1.0 Foo | |
402 | v1.0.1 Foo | |
403 | v1.1.3 Foo | |
404 | EOF | |
405 | test_cmp expected actual | |
406 | ' | |
407 | ||
ef5a6fb5 CR |
408 | # creating and verifying lightweight tags: |
409 | ||
410 | test_expect_success \ | |
411 | 'a non-annotated tag created without parameters should point to HEAD' ' | |
d592b315 | 412 | git tag non-annotated-tag && |
5be60078 JH |
413 | test $(git cat-file -t non-annotated-tag) = commit && |
414 | test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) | |
ef5a6fb5 CR |
415 | ' |
416 | ||
41ac414e | 417 | test_expect_success 'trying to verify an unknown tag should fail' \ |
d592b315 | 418 | 'test_must_fail git tag -v unknown-tag' |
ef5a6fb5 | 419 | |
41ac414e | 420 | test_expect_success \ |
ef5a6fb5 | 421 | 'trying to verify a non-annotated and non-signed tag should fail' \ |
d592b315 | 422 | 'test_must_fail git tag -v non-annotated-tag' |
ef5a6fb5 | 423 | |
41ac414e | 424 | test_expect_success \ |
62e09ce9 | 425 | 'trying to verify many non-annotated or unknown tags, should fail' \ |
d592b315 | 426 | 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' |
62e09ce9 | 427 | |
ef5a6fb5 CR |
428 | # creating annotated tags: |
429 | ||
430 | get_tag_msg () { | |
431 | git cat-file tag "$1" | sed -e "/BEGIN PGP/q" | |
432 | } | |
433 | ||
434 | # run test_tick before committing always gives the time in that timezone | |
435 | get_tag_header () { | |
436 | cat <<EOF | |
437 | object $2 | |
438 | type $3 | |
439 | tag $1 | |
440 | tagger C O Mitter <committer@example.com> $4 -0700 | |
441 | ||
442 | EOF | |
443 | } | |
444 | ||
445 | commit=$(git rev-parse HEAD) | |
446 | time=$test_tick | |
447 | ||
448 | get_tag_header annotated-tag $commit commit $time >expect | |
449 | echo "A message" >>expect | |
450 | test_expect_success \ | |
451 | 'creating an annotated tag with -m message should succeed' ' | |
d592b315 | 452 | git tag -m "A message" annotated-tag && |
ef5a6fb5 | 453 | get_tag_msg annotated-tag >actual && |
3af82863 | 454 | test_cmp expect actual |
ef5a6fb5 CR |
455 | ' |
456 | ||
9eed6e40 NMC |
457 | get_tag_header annotated-tag-edit $commit commit $time >expect |
458 | echo "An edited message" >>expect | |
459 | test_expect_success 'set up editor' ' | |
460 | write_script fakeeditor <<-\EOF | |
461 | sed -e "s/A message/An edited message/g" <"$1" >"$1-" | |
462 | mv "$1-" "$1" | |
463 | EOF | |
464 | ' | |
465 | test_expect_success \ | |
466 | 'creating an annotated tag with -m message --edit should succeed' ' | |
467 | GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit && | |
468 | get_tag_msg annotated-tag-edit >actual && | |
469 | test_cmp expect actual | |
470 | ' | |
471 | ||
ef5a6fb5 CR |
472 | cat >msgfile <<EOF |
473 | Another message | |
474 | in a file. | |
475 | EOF | |
476 | get_tag_header file-annotated-tag $commit commit $time >expect | |
477 | cat msgfile >>expect | |
478 | test_expect_success \ | |
479 | 'creating an annotated tag with -F messagefile should succeed' ' | |
d592b315 | 480 | git tag -F msgfile file-annotated-tag && |
ef5a6fb5 | 481 | get_tag_msg file-annotated-tag >actual && |
3af82863 | 482 | test_cmp expect actual |
ef5a6fb5 CR |
483 | ' |
484 | ||
9eed6e40 NMC |
485 | get_tag_header file-annotated-tag-edit $commit commit $time >expect |
486 | sed -e "s/Another message/Another edited message/g" msgfile >>expect | |
487 | test_expect_success 'set up editor' ' | |
488 | write_script fakeeditor <<-\EOF | |
489 | sed -e "s/Another message/Another edited message/g" <"$1" >"$1-" | |
490 | mv "$1-" "$1" | |
491 | EOF | |
492 | ' | |
493 | test_expect_success \ | |
494 | 'creating an annotated tag with -F messagefile --edit should succeed' ' | |
495 | GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit && | |
496 | get_tag_msg file-annotated-tag-edit >actual && | |
497 | test_cmp expect actual | |
498 | ' | |
499 | ||
62e09ce9 CR |
500 | cat >inputmsg <<EOF |
501 | A message from the | |
502 | standard input | |
503 | EOF | |
504 | get_tag_header stdin-annotated-tag $commit commit $time >expect | |
505 | cat inputmsg >>expect | |
506 | test_expect_success 'creating an annotated tag with -F - should succeed' ' | |
d592b315 | 507 | git tag -F - stdin-annotated-tag <inputmsg && |
62e09ce9 | 508 | get_tag_msg stdin-annotated-tag >actual && |
3af82863 | 509 | test_cmp expect actual |
62e09ce9 CR |
510 | ' |
511 | ||
e317cfaf CR |
512 | test_expect_success \ |
513 | 'trying to create a tag with a non-existing -F file should fail' ' | |
514 | ! test -f nonexistingfile && | |
515 | ! tag_exists notag && | |
d592b315 | 516 | test_must_fail git tag -F nonexistingfile notag && |
e317cfaf CR |
517 | ! tag_exists notag |
518 | ' | |
519 | ||
520 | test_expect_success \ | |
39686585 | 521 | 'trying to create tags giving both -m or -F options should fail' ' |
e317cfaf | 522 | echo "message file 1" >msgfile1 && |
e317cfaf | 523 | ! tag_exists msgtag && |
d592b315 | 524 | test_must_fail git tag -m "message 1" -F msgfile1 msgtag && |
e317cfaf | 525 | ! tag_exists msgtag && |
d592b315 | 526 | test_must_fail git tag -F msgfile1 -m "message 1" msgtag && |
e317cfaf | 527 | ! tag_exists msgtag && |
d592b315 | 528 | test_must_fail git tag -m "message 1" -F msgfile1 \ |
d492b31c | 529 | -m "message 2" msgtag && |
e317cfaf CR |
530 | ! tag_exists msgtag |
531 | ' | |
532 | ||
ef5a6fb5 CR |
533 | # blank and empty messages: |
534 | ||
535 | get_tag_header empty-annotated-tag $commit commit $time >expect | |
536 | test_expect_success \ | |
537 | 'creating a tag with an empty -m message should succeed' ' | |
d592b315 | 538 | git tag -m "" empty-annotated-tag && |
ef5a6fb5 | 539 | get_tag_msg empty-annotated-tag >actual && |
3af82863 | 540 | test_cmp expect actual |
ef5a6fb5 CR |
541 | ' |
542 | ||
543 | >emptyfile | |
544 | get_tag_header emptyfile-annotated-tag $commit commit $time >expect | |
545 | test_expect_success \ | |
546 | 'creating a tag with an empty -F messagefile should succeed' ' | |
d592b315 | 547 | git tag -F emptyfile emptyfile-annotated-tag && |
ef5a6fb5 | 548 | get_tag_msg emptyfile-annotated-tag >actual && |
3af82863 | 549 | test_cmp expect actual |
ef5a6fb5 CR |
550 | ' |
551 | ||
552 | printf '\n\n \n\t\nLeading blank lines\n' >blanksfile | |
553 | printf '\n\t \t \nRepeated blank lines\n' >>blanksfile | |
554 | printf '\n\n\nTrailing spaces \t \n' >>blanksfile | |
555 | printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile | |
556 | get_tag_header blanks-annotated-tag $commit commit $time >expect | |
557 | cat >>expect <<EOF | |
558 | Leading blank lines | |
559 | ||
560 | Repeated blank lines | |
561 | ||
562 | Trailing spaces | |
563 | ||
564 | Trailing blank lines | |
565 | EOF | |
566 | test_expect_success \ | |
567 | 'extra blanks in the message for an annotated tag should be removed' ' | |
d592b315 | 568 | git tag -F blanksfile blanks-annotated-tag && |
ef5a6fb5 | 569 | get_tag_msg blanks-annotated-tag >actual && |
3af82863 | 570 | test_cmp expect actual |
ef5a6fb5 CR |
571 | ' |
572 | ||
573 | get_tag_header blank-annotated-tag $commit commit $time >expect | |
574 | test_expect_success \ | |
575 | 'creating a tag with blank -m message with spaces should succeed' ' | |
d592b315 | 576 | git tag -m " " blank-annotated-tag && |
ef5a6fb5 | 577 | get_tag_msg blank-annotated-tag >actual && |
3af82863 | 578 | test_cmp expect actual |
ef5a6fb5 CR |
579 | ' |
580 | ||
581 | echo ' ' >blankfile | |
582 | echo '' >>blankfile | |
583 | echo ' ' >>blankfile | |
584 | get_tag_header blankfile-annotated-tag $commit commit $time >expect | |
585 | test_expect_success \ | |
586 | 'creating a tag with blank -F messagefile with spaces should succeed' ' | |
d592b315 | 587 | git tag -F blankfile blankfile-annotated-tag && |
ef5a6fb5 | 588 | get_tag_msg blankfile-annotated-tag >actual && |
3af82863 | 589 | test_cmp expect actual |
ef5a6fb5 CR |
590 | ' |
591 | ||
592 | printf ' ' >blanknonlfile | |
593 | get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect | |
594 | test_expect_success \ | |
595 | 'creating a tag with -F file of spaces and no newline should succeed' ' | |
d592b315 | 596 | git tag -F blanknonlfile blanknonlfile-annotated-tag && |
ef5a6fb5 | 597 | get_tag_msg blanknonlfile-annotated-tag >actual && |
3af82863 | 598 | test_cmp expect actual |
ef5a6fb5 CR |
599 | ' |
600 | ||
601 | # messages with commented lines: | |
602 | ||
603 | cat >commentsfile <<EOF | |
604 | # A comment | |
605 | ||
606 | ############ | |
607 | The message. | |
608 | ############ | |
609 | One line. | |
610 | ||
611 | ||
612 | # commented lines | |
613 | # commented lines | |
614 | ||
615 | Another line. | |
616 | # comments | |
617 | ||
618 | Last line. | |
619 | EOF | |
620 | get_tag_header comments-annotated-tag $commit commit $time >expect | |
621 | cat >>expect <<EOF | |
622 | The message. | |
623 | One line. | |
624 | ||
625 | Another line. | |
626 | ||
627 | Last line. | |
628 | EOF | |
629 | test_expect_success \ | |
630 | 'creating a tag using a -F messagefile with #comments should succeed' ' | |
d592b315 | 631 | git tag -F commentsfile comments-annotated-tag && |
ef5a6fb5 | 632 | get_tag_msg comments-annotated-tag >actual && |
3af82863 | 633 | test_cmp expect actual |
ef5a6fb5 CR |
634 | ' |
635 | ||
636 | get_tag_header comment-annotated-tag $commit commit $time >expect | |
637 | test_expect_success \ | |
638 | 'creating a tag with a #comment in the -m message should succeed' ' | |
d592b315 | 639 | git tag -m "#comment" comment-annotated-tag && |
ef5a6fb5 | 640 | get_tag_msg comment-annotated-tag >actual && |
3af82863 | 641 | test_cmp expect actual |
ef5a6fb5 CR |
642 | ' |
643 | ||
644 | echo '#comment' >commentfile | |
645 | echo '' >>commentfile | |
646 | echo '####' >>commentfile | |
647 | get_tag_header commentfile-annotated-tag $commit commit $time >expect | |
648 | test_expect_success \ | |
649 | 'creating a tag with #comments in the -F messagefile should succeed' ' | |
d592b315 | 650 | git tag -F commentfile commentfile-annotated-tag && |
ef5a6fb5 | 651 | get_tag_msg commentfile-annotated-tag >actual && |
3af82863 | 652 | test_cmp expect actual |
ef5a6fb5 CR |
653 | ' |
654 | ||
655 | printf '#comment' >commentnonlfile | |
656 | get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect | |
657 | test_expect_success \ | |
658 | 'creating a tag with a file of #comment and no newline should succeed' ' | |
d592b315 | 659 | git tag -F commentnonlfile commentnonlfile-annotated-tag && |
ef5a6fb5 | 660 | get_tag_msg commentnonlfile-annotated-tag >actual && |
3af82863 | 661 | test_cmp expect actual |
ef5a6fb5 CR |
662 | ' |
663 | ||
5206d130 CR |
664 | # listing messages for annotated non-signed tags: |
665 | ||
666 | test_expect_success \ | |
667 | 'listing the one-line message of a non-signed tag should succeed' ' | |
d592b315 | 668 | git tag -m "A msg" tag-one-line && |
5206d130 CR |
669 | |
670 | echo "tag-one-line" >expect && | |
d592b315 | 671 | git tag -l | grep "^tag-one-line" >actual && |
3af82863 | 672 | test_cmp expect actual && |
d592b315 | 673 | git tag -n0 -l | grep "^tag-one-line" >actual && |
3af82863 | 674 | test_cmp expect actual && |
d592b315 | 675 | git tag -n0 -l tag-one-line >actual && |
3af82863 | 676 | test_cmp expect actual && |
5206d130 | 677 | |
6a338149 ÆAB |
678 | git tag -n0 | grep "^tag-one-line" >actual && |
679 | test_cmp expect actual && | |
680 | git tag -n0 tag-one-line >actual && | |
681 | test_cmp expect actual && | |
682 | ||
5206d130 | 683 | echo "tag-one-line A msg" >expect && |
d592b315 | 684 | git tag -n1 -l | grep "^tag-one-line" >actual && |
3af82863 | 685 | test_cmp expect actual && |
d592b315 | 686 | git tag -n -l | grep "^tag-one-line" >actual && |
3af82863 | 687 | test_cmp expect actual && |
d592b315 | 688 | git tag -n1 -l tag-one-line >actual && |
3af82863 | 689 | test_cmp expect actual && |
d592b315 | 690 | git tag -n2 -l tag-one-line >actual && |
3af82863 | 691 | test_cmp expect actual && |
d592b315 | 692 | git tag -n999 -l tag-one-line >actual && |
3af82863 | 693 | test_cmp expect actual |
5206d130 CR |
694 | ' |
695 | ||
6a338149 | 696 | test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' ' |
6a338149 | 697 | git tag -n 100 >actual && |
d3c6751b | 698 | test_must_be_empty actual && |
6a338149 ÆAB |
699 | |
700 | git tag -m "A msg" 100 && | |
701 | echo "100 A msg" >expect && | |
702 | git tag -n 100 >actual && | |
703 | test_cmp expect actual | |
704 | ' | |
705 | ||
5206d130 CR |
706 | test_expect_success \ |
707 | 'listing the zero-lines message of a non-signed tag should succeed' ' | |
d592b315 | 708 | git tag -m "" tag-zero-lines && |
5206d130 CR |
709 | |
710 | echo "tag-zero-lines" >expect && | |
d592b315 | 711 | git tag -l | grep "^tag-zero-lines" >actual && |
3af82863 | 712 | test_cmp expect actual && |
d592b315 | 713 | git tag -n0 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 714 | test_cmp expect actual && |
d592b315 | 715 | git tag -n0 -l tag-zero-lines >actual && |
3af82863 | 716 | test_cmp expect actual && |
5206d130 CR |
717 | |
718 | echo "tag-zero-lines " >expect && | |
d592b315 | 719 | git tag -n1 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 720 | test_cmp expect actual && |
d592b315 | 721 | git tag -n -l | grep "^tag-zero-lines" >actual && |
3af82863 | 722 | test_cmp expect actual && |
d592b315 | 723 | git tag -n1 -l tag-zero-lines >actual && |
3af82863 | 724 | test_cmp expect actual && |
d592b315 | 725 | git tag -n2 -l tag-zero-lines >actual && |
3af82863 | 726 | test_cmp expect actual && |
d592b315 | 727 | git tag -n999 -l tag-zero-lines >actual && |
3af82863 | 728 | test_cmp expect actual |
5206d130 CR |
729 | ' |
730 | ||
731 | echo 'tag line one' >annotagmsg | |
732 | echo 'tag line two' >>annotagmsg | |
733 | echo 'tag line three' >>annotagmsg | |
734 | test_expect_success \ | |
735 | 'listing many message lines of a non-signed tag should succeed' ' | |
d592b315 | 736 | git tag -F annotagmsg tag-lines && |
5206d130 CR |
737 | |
738 | echo "tag-lines" >expect && | |
d592b315 | 739 | git tag -l | grep "^tag-lines" >actual && |
3af82863 | 740 | test_cmp expect actual && |
d592b315 | 741 | git tag -n0 -l | grep "^tag-lines" >actual && |
3af82863 | 742 | test_cmp expect actual && |
d592b315 | 743 | git tag -n0 -l tag-lines >actual && |
3af82863 | 744 | test_cmp expect actual && |
5206d130 CR |
745 | |
746 | echo "tag-lines tag line one" >expect && | |
d592b315 | 747 | git tag -n1 -l | grep "^tag-lines" >actual && |
3af82863 | 748 | test_cmp expect actual && |
d592b315 | 749 | git tag -n -l | grep "^tag-lines" >actual && |
3af82863 | 750 | test_cmp expect actual && |
d592b315 | 751 | git tag -n1 -l tag-lines >actual && |
3af82863 | 752 | test_cmp expect actual && |
5206d130 CR |
753 | |
754 | echo " tag line two" >>expect && | |
d592b315 | 755 | git tag -n2 -l | grep "^ *tag.line" >actual && |
3af82863 | 756 | test_cmp expect actual && |
d592b315 | 757 | git tag -n2 -l tag-lines >actual && |
3af82863 | 758 | test_cmp expect actual && |
5206d130 CR |
759 | |
760 | echo " tag line three" >>expect && | |
d592b315 | 761 | git tag -n3 -l | grep "^ *tag.line" >actual && |
3af82863 | 762 | test_cmp expect actual && |
d592b315 | 763 | git tag -n3 -l tag-lines >actual && |
3af82863 | 764 | test_cmp expect actual && |
d592b315 | 765 | git tag -n4 -l | grep "^ *tag.line" >actual && |
3af82863 | 766 | test_cmp expect actual && |
d592b315 | 767 | git tag -n4 -l tag-lines >actual && |
3af82863 | 768 | test_cmp expect actual && |
d592b315 | 769 | git tag -n99 -l | grep "^ *tag.line" >actual && |
3af82863 | 770 | test_cmp expect actual && |
d592b315 | 771 | git tag -n99 -l tag-lines >actual && |
3af82863 | 772 | test_cmp expect actual |
5206d130 CR |
773 | ' |
774 | ||
31fd8d72 JH |
775 | test_expect_success 'annotations for blobs are empty' ' |
776 | blob=$(git hash-object -w --stdin <<-\EOF | |
777 | Blob paragraph 1. | |
778 | ||
779 | Blob paragraph 2. | |
780 | EOF | |
781 | ) && | |
782 | git tag tag-blob $blob && | |
783 | echo "tag-blob " >expect && | |
784 | git tag -n1 -l tag-blob >actual && | |
785 | test_cmp expect actual | |
786 | ' | |
787 | ||
ef5a6fb5 CR |
788 | # trying to verify annotated non-signed tags: |
789 | ||
a4df22ce | 790 | test_expect_success GPG \ |
ef5a6fb5 CR |
791 | 'trying to verify an annotated non-signed tag should fail' ' |
792 | tag_exists annotated-tag && | |
d592b315 | 793 | test_must_fail git tag -v annotated-tag |
ef5a6fb5 CR |
794 | ' |
795 | ||
a4df22ce | 796 | test_expect_success GPG \ |
ef5a6fb5 CR |
797 | 'trying to verify a file-annotated non-signed tag should fail' ' |
798 | tag_exists file-annotated-tag && | |
d592b315 | 799 | test_must_fail git tag -v file-annotated-tag |
ef5a6fb5 CR |
800 | ' |
801 | ||
a4df22ce | 802 | test_expect_success GPG \ |
62e09ce9 CR |
803 | 'trying to verify two annotated non-signed tags should fail' ' |
804 | tag_exists annotated-tag file-annotated-tag && | |
d592b315 | 805 | test_must_fail git tag -v annotated-tag file-annotated-tag |
62e09ce9 CR |
806 | ' |
807 | ||
ef5a6fb5 CR |
808 | # creating and verifying signed tags: |
809 | ||
ef5a6fb5 CR |
810 | get_tag_header signed-tag $commit commit $time >expect |
811 | echo 'A signed tag message' >>expect | |
812 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 813 | test_expect_success GPG 'creating a signed tag with -m message should succeed' ' |
d592b315 | 814 | git tag -s -m "A signed tag message" signed-tag && |
ef5a6fb5 | 815 | get_tag_msg signed-tag >actual && |
3af82863 | 816 | test_cmp expect actual |
ef5a6fb5 CR |
817 | ' |
818 | ||
be15f505 LT |
819 | get_tag_header u-signed-tag $commit commit $time >expect |
820 | echo 'Another message' >>expect | |
821 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 822 | test_expect_success GPG 'sign with a given key id' ' |
be15f505 LT |
823 | |
824 | git tag -u committer@example.com -m "Another message" u-signed-tag && | |
825 | get_tag_msg u-signed-tag >actual && | |
3af82863 | 826 | test_cmp expect actual |
be15f505 LT |
827 | |
828 | ' | |
829 | ||
a4df22ce | 830 | test_expect_success GPG 'sign with an unknown id (1)' ' |
be15f505 | 831 | |
d492b31c SB |
832 | test_must_fail git tag -u author@example.com \ |
833 | -m "Another message" o-signed-tag | |
be15f505 LT |
834 | |
835 | ' | |
836 | ||
a4df22ce | 837 | test_expect_success GPG 'sign with an unknown id (2)' ' |
be15f505 | 838 | |
d492b31c | 839 | test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag |
be15f505 LT |
840 | |
841 | ' | |
842 | ||
843 | cat >fakeeditor <<'EOF' | |
844 | #!/bin/sh | |
845 | test -n "$1" && exec >"$1" | |
846 | echo A signed tag message | |
847 | echo from a fake editor. | |
848 | EOF | |
849 | chmod +x fakeeditor | |
850 | ||
851 | get_tag_header implied-sign $commit commit $time >expect | |
852 | ./fakeeditor >>expect | |
853 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 854 | test_expect_success GPG '-u implies signed tag' ' |
d592b315 | 855 | GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && |
be15f505 | 856 | get_tag_msg implied-sign >actual && |
3af82863 | 857 | test_cmp expect actual |
be15f505 LT |
858 | ' |
859 | ||
62e09ce9 CR |
860 | cat >sigmsgfile <<EOF |
861 | Another signed tag | |
862 | message in a file. | |
863 | EOF | |
864 | get_tag_header file-signed-tag $commit commit $time >expect | |
865 | cat sigmsgfile >>expect | |
866 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 867 | test_expect_success GPG \ |
62e09ce9 | 868 | 'creating a signed tag with -F messagefile should succeed' ' |
d592b315 | 869 | git tag -s -F sigmsgfile file-signed-tag && |
62e09ce9 | 870 | get_tag_msg file-signed-tag >actual && |
3af82863 | 871 | test_cmp expect actual |
62e09ce9 CR |
872 | ' |
873 | ||
874 | cat >siginputmsg <<EOF | |
875 | A signed tag message from | |
876 | the standard input | |
877 | EOF | |
878 | get_tag_header stdin-signed-tag $commit commit $time >expect | |
879 | cat siginputmsg >>expect | |
880 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 881 | test_expect_success GPG 'creating a signed tag with -F - should succeed' ' |
d592b315 | 882 | git tag -s -F - stdin-signed-tag <siginputmsg && |
62e09ce9 | 883 | get_tag_msg stdin-signed-tag >actual && |
3af82863 | 884 | test_cmp expect actual |
62e09ce9 CR |
885 | ' |
886 | ||
10507857 JK |
887 | get_tag_header implied-annotate $commit commit $time >expect |
888 | ./fakeeditor >>expect | |
889 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 890 | test_expect_success GPG '-s implies annotated tag' ' |
d592b315 | 891 | GIT_EDITOR=./fakeeditor git tag -s implied-annotate && |
10507857 | 892 | get_tag_msg implied-annotate >actual && |
3af82863 | 893 | test_cmp expect actual |
10507857 JK |
894 | ' |
895 | ||
61c2fe0c LA |
896 | get_tag_header forcesignannotated-implied-sign $commit commit $time >expect |
897 | echo "A message" >>expect | |
898 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
899 | test_expect_success GPG \ | |
900 | 'git tag -s implied if configured with tag.forcesignannotated' \ | |
901 | 'test_config tag.forcesignannotated true && | |
902 | git tag -m "A message" forcesignannotated-implied-sign && | |
903 | get_tag_msg forcesignannotated-implied-sign >actual && | |
904 | test_cmp expect actual | |
905 | ' | |
906 | ||
907 | test_expect_success GPG \ | |
908 | 'lightweight with no message when configured with tag.forcesignannotated' \ | |
909 | 'test_config tag.forcesignannotated true && | |
910 | git tag forcesignannotated-lightweight && | |
911 | tag_exists forcesignannotated-lightweight && | |
912 | test_must_fail git tag -v forcesignannotated-no-message | |
913 | ' | |
914 | ||
915 | get_tag_header forcesignannotated-annotate $commit commit $time >expect | |
916 | echo "A message" >>expect | |
917 | test_expect_success GPG \ | |
918 | 'git tag -a disable configured tag.forcesignannotated' \ | |
919 | 'test_config tag.forcesignannotated true && | |
920 | git tag -a -m "A message" forcesignannotated-annotate && | |
921 | get_tag_msg forcesignannotated-annotate >actual && | |
922 | test_cmp expect actual && | |
923 | test_must_fail git tag -v forcesignannotated-annotate | |
924 | ' | |
925 | ||
926 | get_tag_header forcesignannotated-disabled $commit commit $time >expect | |
927 | echo "A message" >>expect | |
928 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
929 | test_expect_success GPG \ | |
930 | 'git tag --sign enable GPG sign' \ | |
931 | 'test_config tag.forcesignannotated false && | |
932 | git tag --sign -m "A message" forcesignannotated-disabled && | |
933 | get_tag_msg forcesignannotated-disabled >actual && | |
934 | test_cmp expect actual | |
935 | ' | |
936 | ||
1c6b565f TM |
937 | get_tag_header gpgsign-enabled $commit commit $time >expect |
938 | echo "A message" >>expect | |
939 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
940 | test_expect_success GPG \ | |
941 | 'git tag configured tag.gpgsign enables GPG sign' \ | |
942 | 'test_config tag.gpgsign true && | |
943 | git tag -m "A message" gpgsign-enabled && | |
944 | get_tag_msg gpgsign-enabled>actual && | |
945 | test_cmp expect actual | |
946 | ' | |
947 | ||
948 | get_tag_header no-sign $commit commit $time >expect | |
949 | echo "A message" >>expect | |
950 | test_expect_success GPG \ | |
951 | 'git tag --no-sign configured tag.gpgsign skip GPG sign' \ | |
952 | 'test_config tag.gpgsign true && | |
953 | git tag -a --no-sign -m "A message" no-sign && | |
954 | get_tag_msg no-sign>actual && | |
955 | test_cmp expect actual | |
956 | ' | |
957 | ||
a4df22ce | 958 | test_expect_success GPG \ |
e317cfaf CR |
959 | 'trying to create a signed tag with non-existing -F file should fail' ' |
960 | ! test -f nonexistingfile && | |
961 | ! tag_exists nosigtag && | |
d592b315 | 962 | test_must_fail git tag -s -F nonexistingfile nosigtag && |
e317cfaf CR |
963 | ! tag_exists nosigtag |
964 | ' | |
965 | ||
a4df22ce | 966 | test_expect_success GPG 'verifying a signed tag should succeed' \ |
d592b315 | 967 | 'git tag -v signed-tag' |
ef5a6fb5 | 968 | |
a4df22ce | 969 | test_expect_success GPG 'verifying two signed tags in one command should succeed' \ |
d592b315 | 970 | 'git tag -v signed-tag file-signed-tag' |
62e09ce9 | 971 | |
a4df22ce | 972 | test_expect_success GPG \ |
62e09ce9 | 973 | 'verifying many signed and non-signed tags should fail' ' |
d592b315 NS |
974 | test_must_fail git tag -v signed-tag annotated-tag && |
975 | test_must_fail git tag -v file-annotated-tag file-signed-tag && | |
976 | test_must_fail git tag -v annotated-tag \ | |
d492b31c | 977 | file-signed-tag file-annotated-tag && |
d592b315 | 978 | test_must_fail git tag -v signed-tag annotated-tag file-signed-tag |
62e09ce9 CR |
979 | ' |
980 | ||
a4df22ce | 981 | test_expect_success GPG 'verifying a forged tag should fail' ' |
ef5a6fb5 CR |
982 | forged=$(git cat-file tag signed-tag | |
983 | sed -e "s/signed-tag/forged-tag/" | | |
984 | git mktag) && | |
985 | git tag forged-tag $forged && | |
d592b315 | 986 | test_must_fail git tag -v forged-tag |
ef5a6fb5 CR |
987 | ' |
988 | ||
b42ca35e ST |
989 | test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' ' |
990 | cat >expect <<-\EOF && | |
4fea72f4 | 991 | tagname : signed-tag |
b42ca35e | 992 | EOF |
4fea72f4 ST |
993 | git tag -v --format="tagname : %(tag)" "signed-tag" >actual && |
994 | test_cmp expect actual | |
995 | ' | |
996 | ||
b42ca35e | 997 | test_expect_success GPG 'verifying a forged tag with --format should fail silently' ' |
4fea72f4 | 998 | test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual && |
d3c6751b | 999 | test_must_be_empty actual |
4fea72f4 ST |
1000 | ' |
1001 | ||
ef5a6fb5 CR |
1002 | # blank and empty messages for signed tags: |
1003 | ||
1004 | get_tag_header empty-signed-tag $commit commit $time >expect | |
1005 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1006 | test_expect_success GPG \ |
ef5a6fb5 | 1007 | 'creating a signed tag with an empty -m message should succeed' ' |
d592b315 | 1008 | git tag -s -m "" empty-signed-tag && |
ef5a6fb5 | 1009 | get_tag_msg empty-signed-tag >actual && |
3af82863 | 1010 | test_cmp expect actual && |
d592b315 | 1011 | git tag -v empty-signed-tag |
ef5a6fb5 CR |
1012 | ' |
1013 | ||
1014 | >sigemptyfile | |
1015 | get_tag_header emptyfile-signed-tag $commit commit $time >expect | |
1016 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1017 | test_expect_success GPG \ |
ef5a6fb5 | 1018 | 'creating a signed tag with an empty -F messagefile should succeed' ' |
d592b315 | 1019 | git tag -s -F sigemptyfile emptyfile-signed-tag && |
ef5a6fb5 | 1020 | get_tag_msg emptyfile-signed-tag >actual && |
3af82863 | 1021 | test_cmp expect actual && |
d592b315 | 1022 | git tag -v emptyfile-signed-tag |
ef5a6fb5 CR |
1023 | ' |
1024 | ||
1025 | printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile | |
1026 | printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile | |
1027 | printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile | |
1028 | printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile | |
1029 | get_tag_header blanks-signed-tag $commit commit $time >expect | |
1030 | cat >>expect <<EOF | |
1031 | Leading blank lines | |
1032 | ||
1033 | Repeated blank lines | |
1034 | ||
1035 | Trailing spaces | |
1036 | ||
1037 | Trailing blank lines | |
1038 | EOF | |
1039 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1040 | test_expect_success GPG \ |
ef5a6fb5 | 1041 | 'extra blanks in the message for a signed tag should be removed' ' |
d592b315 | 1042 | git tag -s -F sigblanksfile blanks-signed-tag && |
ef5a6fb5 | 1043 | get_tag_msg blanks-signed-tag >actual && |
3af82863 | 1044 | test_cmp expect actual && |
d592b315 | 1045 | git tag -v blanks-signed-tag |
ef5a6fb5 CR |
1046 | ' |
1047 | ||
1048 | get_tag_header blank-signed-tag $commit commit $time >expect | |
1049 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1050 | test_expect_success GPG \ |
ef5a6fb5 | 1051 | 'creating a signed tag with a blank -m message should succeed' ' |
d592b315 | 1052 | git tag -s -m " " blank-signed-tag && |
ef5a6fb5 | 1053 | get_tag_msg blank-signed-tag >actual && |
3af82863 | 1054 | test_cmp expect actual && |
d592b315 | 1055 | git tag -v blank-signed-tag |
ef5a6fb5 CR |
1056 | ' |
1057 | ||
1058 | echo ' ' >sigblankfile | |
1059 | echo '' >>sigblankfile | |
1060 | echo ' ' >>sigblankfile | |
1061 | get_tag_header blankfile-signed-tag $commit commit $time >expect | |
1062 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1063 | test_expect_success GPG \ |
ef5a6fb5 | 1064 | 'creating a signed tag with blank -F file with spaces should succeed' ' |
d592b315 | 1065 | git tag -s -F sigblankfile blankfile-signed-tag && |
ef5a6fb5 | 1066 | get_tag_msg blankfile-signed-tag >actual && |
3af82863 | 1067 | test_cmp expect actual && |
d592b315 | 1068 | git tag -v blankfile-signed-tag |
ef5a6fb5 CR |
1069 | ' |
1070 | ||
1071 | printf ' ' >sigblanknonlfile | |
1072 | get_tag_header blanknonlfile-signed-tag $commit commit $time >expect | |
1073 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1074 | test_expect_success GPG \ |
ef5a6fb5 | 1075 | 'creating a signed tag with spaces and no newline should succeed' ' |
d592b315 | 1076 | git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && |
ef5a6fb5 | 1077 | get_tag_msg blanknonlfile-signed-tag >actual && |
3af82863 | 1078 | test_cmp expect actual && |
cf98a52b | 1079 | git tag -v blanknonlfile-signed-tag |
ef5a6fb5 CR |
1080 | ' |
1081 | ||
8b44b2be JK |
1082 | test_expect_success GPG 'signed tag with embedded PGP message' ' |
1083 | cat >msg <<-\EOF && | |
1084 | -----BEGIN PGP MESSAGE----- | |
1085 | ||
1086 | this is not a real PGP message | |
1087 | -----END PGP MESSAGE----- | |
1088 | EOF | |
1089 | git tag -s -F msg confusing-pgp-message && | |
1090 | git tag -v confusing-pgp-message | |
1091 | ' | |
1092 | ||
ef5a6fb5 CR |
1093 | # messages with commented lines for signed tags: |
1094 | ||
1095 | cat >sigcommentsfile <<EOF | |
1096 | # A comment | |
1097 | ||
1098 | ############ | |
1099 | The message. | |
1100 | ############ | |
1101 | One line. | |
1102 | ||
1103 | ||
1104 | # commented lines | |
1105 | # commented lines | |
1106 | ||
1107 | Another line. | |
1108 | # comments | |
1109 | ||
1110 | Last line. | |
1111 | EOF | |
1112 | get_tag_header comments-signed-tag $commit commit $time >expect | |
1113 | cat >>expect <<EOF | |
1114 | The message. | |
1115 | One line. | |
1116 | ||
1117 | Another line. | |
1118 | ||
1119 | Last line. | |
1120 | EOF | |
1121 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1122 | test_expect_success GPG \ |
ef5a6fb5 | 1123 | 'creating a signed tag with a -F file with #comments should succeed' ' |
d592b315 | 1124 | git tag -s -F sigcommentsfile comments-signed-tag && |
ef5a6fb5 | 1125 | get_tag_msg comments-signed-tag >actual && |
3af82863 | 1126 | test_cmp expect actual && |
d592b315 | 1127 | git tag -v comments-signed-tag |
ef5a6fb5 CR |
1128 | ' |
1129 | ||
1130 | get_tag_header comment-signed-tag $commit commit $time >expect | |
1131 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1132 | test_expect_success GPG \ |
ef5a6fb5 | 1133 | 'creating a signed tag with #commented -m message should succeed' ' |
d592b315 | 1134 | git tag -s -m "#comment" comment-signed-tag && |
ef5a6fb5 | 1135 | get_tag_msg comment-signed-tag >actual && |
3af82863 | 1136 | test_cmp expect actual && |
d592b315 | 1137 | git tag -v comment-signed-tag |
ef5a6fb5 CR |
1138 | ' |
1139 | ||
1140 | echo '#comment' >sigcommentfile | |
1141 | echo '' >>sigcommentfile | |
1142 | echo '####' >>sigcommentfile | |
1143 | get_tag_header commentfile-signed-tag $commit commit $time >expect | |
1144 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1145 | test_expect_success GPG \ |
ef5a6fb5 | 1146 | 'creating a signed tag with #commented -F messagefile should succeed' ' |
d592b315 | 1147 | git tag -s -F sigcommentfile commentfile-signed-tag && |
ef5a6fb5 | 1148 | get_tag_msg commentfile-signed-tag >actual && |
3af82863 | 1149 | test_cmp expect actual && |
d592b315 | 1150 | git tag -v commentfile-signed-tag |
ef5a6fb5 CR |
1151 | ' |
1152 | ||
1153 | printf '#comment' >sigcommentnonlfile | |
1154 | get_tag_header commentnonlfile-signed-tag $commit commit $time >expect | |
1155 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1156 | test_expect_success GPG \ |
ef5a6fb5 | 1157 | 'creating a signed tag with a #comment and no newline should succeed' ' |
d592b315 | 1158 | git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && |
ef5a6fb5 | 1159 | get_tag_msg commentnonlfile-signed-tag >actual && |
3af82863 | 1160 | test_cmp expect actual && |
d592b315 | 1161 | git tag -v commentnonlfile-signed-tag |
ef5a6fb5 CR |
1162 | ' |
1163 | ||
5206d130 CR |
1164 | # listing messages for signed tags: |
1165 | ||
a4df22ce | 1166 | test_expect_success GPG \ |
5206d130 | 1167 | 'listing the one-line message of a signed tag should succeed' ' |
d592b315 | 1168 | git tag -s -m "A message line signed" stag-one-line && |
5206d130 CR |
1169 | |
1170 | echo "stag-one-line" >expect && | |
d592b315 | 1171 | git tag -l | grep "^stag-one-line" >actual && |
3af82863 | 1172 | test_cmp expect actual && |
d592b315 | 1173 | git tag -n0 -l | grep "^stag-one-line" >actual && |
3af82863 | 1174 | test_cmp expect actual && |
d592b315 | 1175 | git tag -n0 -l stag-one-line >actual && |
3af82863 | 1176 | test_cmp expect actual && |
5206d130 CR |
1177 | |
1178 | echo "stag-one-line A message line signed" >expect && | |
d592b315 | 1179 | git tag -n1 -l | grep "^stag-one-line" >actual && |
3af82863 | 1180 | test_cmp expect actual && |
d592b315 | 1181 | git tag -n -l | grep "^stag-one-line" >actual && |
3af82863 | 1182 | test_cmp expect actual && |
d592b315 | 1183 | git tag -n1 -l stag-one-line >actual && |
3af82863 | 1184 | test_cmp expect actual && |
d592b315 | 1185 | git tag -n2 -l stag-one-line >actual && |
3af82863 | 1186 | test_cmp expect actual && |
d592b315 | 1187 | git tag -n999 -l stag-one-line >actual && |
3af82863 | 1188 | test_cmp expect actual |
5206d130 CR |
1189 | ' |
1190 | ||
a4df22ce | 1191 | test_expect_success GPG \ |
5206d130 | 1192 | 'listing the zero-lines message of a signed tag should succeed' ' |
d592b315 | 1193 | git tag -s -m "" stag-zero-lines && |
5206d130 CR |
1194 | |
1195 | echo "stag-zero-lines" >expect && | |
d592b315 | 1196 | git tag -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1197 | test_cmp expect actual && |
d592b315 | 1198 | git tag -n0 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1199 | test_cmp expect actual && |
d592b315 | 1200 | git tag -n0 -l stag-zero-lines >actual && |
3af82863 | 1201 | test_cmp expect actual && |
5206d130 CR |
1202 | |
1203 | echo "stag-zero-lines " >expect && | |
d592b315 | 1204 | git tag -n1 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1205 | test_cmp expect actual && |
d592b315 | 1206 | git tag -n -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1207 | test_cmp expect actual && |
d592b315 | 1208 | git tag -n1 -l stag-zero-lines >actual && |
3af82863 | 1209 | test_cmp expect actual && |
d592b315 | 1210 | git tag -n2 -l stag-zero-lines >actual && |
3af82863 | 1211 | test_cmp expect actual && |
d592b315 | 1212 | git tag -n999 -l stag-zero-lines >actual && |
3af82863 | 1213 | test_cmp expect actual |
5206d130 CR |
1214 | ' |
1215 | ||
1216 | echo 'stag line one' >sigtagmsg | |
1217 | echo 'stag line two' >>sigtagmsg | |
1218 | echo 'stag line three' >>sigtagmsg | |
a4df22ce | 1219 | test_expect_success GPG \ |
5206d130 | 1220 | 'listing many message lines of a signed tag should succeed' ' |
d592b315 | 1221 | git tag -s -F sigtagmsg stag-lines && |
5206d130 CR |
1222 | |
1223 | echo "stag-lines" >expect && | |
d592b315 | 1224 | git tag -l | grep "^stag-lines" >actual && |
3af82863 | 1225 | test_cmp expect actual && |
d592b315 | 1226 | git tag -n0 -l | grep "^stag-lines" >actual && |
3af82863 | 1227 | test_cmp expect actual && |
d592b315 | 1228 | git tag -n0 -l stag-lines >actual && |
3af82863 | 1229 | test_cmp expect actual && |
5206d130 CR |
1230 | |
1231 | echo "stag-lines stag line one" >expect && | |
d592b315 | 1232 | git tag -n1 -l | grep "^stag-lines" >actual && |
3af82863 | 1233 | test_cmp expect actual && |
d592b315 | 1234 | git tag -n -l | grep "^stag-lines" >actual && |
3af82863 | 1235 | test_cmp expect actual && |
d592b315 | 1236 | git tag -n1 -l stag-lines >actual && |
3af82863 | 1237 | test_cmp expect actual && |
5206d130 CR |
1238 | |
1239 | echo " stag line two" >>expect && | |
d592b315 | 1240 | git tag -n2 -l | grep "^ *stag.line" >actual && |
3af82863 | 1241 | test_cmp expect actual && |
d592b315 | 1242 | git tag -n2 -l stag-lines >actual && |
3af82863 | 1243 | test_cmp expect actual && |
5206d130 CR |
1244 | |
1245 | echo " stag line three" >>expect && | |
d592b315 | 1246 | git tag -n3 -l | grep "^ *stag.line" >actual && |
3af82863 | 1247 | test_cmp expect actual && |
d592b315 | 1248 | git tag -n3 -l stag-lines >actual && |
3af82863 | 1249 | test_cmp expect actual && |
d592b315 | 1250 | git tag -n4 -l | grep "^ *stag.line" >actual && |
3af82863 | 1251 | test_cmp expect actual && |
d592b315 | 1252 | git tag -n4 -l stag-lines >actual && |
3af82863 | 1253 | test_cmp expect actual && |
d592b315 | 1254 | git tag -n99 -l | grep "^ *stag.line" >actual && |
3af82863 | 1255 | test_cmp expect actual && |
d592b315 | 1256 | git tag -n99 -l stag-lines >actual && |
3af82863 | 1257 | test_cmp expect actual |
5206d130 CR |
1258 | ' |
1259 | ||
ef5a6fb5 CR |
1260 | # tags pointing to objects different from commits: |
1261 | ||
1262 | tree=$(git rev-parse HEAD^{tree}) | |
1263 | blob=$(git rev-parse HEAD:foo) | |
a4df22ce | 1264 | tag=$(git rev-parse signed-tag 2>/dev/null) |
ef5a6fb5 CR |
1265 | |
1266 | get_tag_header tree-signed-tag $tree tree $time >expect | |
1267 | echo "A message for a tree" >>expect | |
1268 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1269 | test_expect_success GPG \ |
ef5a6fb5 | 1270 | 'creating a signed tag pointing to a tree should succeed' ' |
d592b315 | 1271 | git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && |
ef5a6fb5 | 1272 | get_tag_msg tree-signed-tag >actual && |
3af82863 | 1273 | test_cmp expect actual |
ef5a6fb5 CR |
1274 | ' |
1275 | ||
1276 | get_tag_header blob-signed-tag $blob blob $time >expect | |
1277 | echo "A message for a blob" >>expect | |
1278 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1279 | test_expect_success GPG \ |
ef5a6fb5 | 1280 | 'creating a signed tag pointing to a blob should succeed' ' |
d592b315 | 1281 | git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && |
ef5a6fb5 | 1282 | get_tag_msg blob-signed-tag >actual && |
3af82863 | 1283 | test_cmp expect actual |
ef5a6fb5 CR |
1284 | ' |
1285 | ||
1286 | get_tag_header tag-signed-tag $tag tag $time >expect | |
1287 | echo "A message for another tag" >>expect | |
1288 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1289 | test_expect_success GPG \ |
ef5a6fb5 | 1290 | 'creating a signed tag pointing to another tag should succeed' ' |
d592b315 | 1291 | git tag -s -m "A message for another tag" tag-signed-tag signed-tag && |
ef5a6fb5 | 1292 | get_tag_msg tag-signed-tag >actual && |
3af82863 | 1293 | test_cmp expect actual |
ef5a6fb5 CR |
1294 | ' |
1295 | ||
c8525c30 | 1296 | # usage with rfc1991 signatures |
c8525c30 MG |
1297 | get_tag_header rfc1991-signed-tag $commit commit $time >expect |
1298 | echo "RFC1991 signed tag" >>expect | |
1299 | echo '-----BEGIN PGP MESSAGE-----' >>expect | |
c0e0ed6e | 1300 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1301 | 'creating a signed tag with rfc1991' ' |
086cb911 | 1302 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1303 | git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && |
1304 | get_tag_msg rfc1991-signed-tag >actual && | |
1305 | test_cmp expect actual | |
1306 | ' | |
1307 | ||
1308 | cat >fakeeditor <<'EOF' | |
1309 | #!/bin/sh | |
1310 | cp "$1" actual | |
1311 | EOF | |
1312 | chmod +x fakeeditor | |
1313 | ||
c0e0ed6e | 1314 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1315 | 'reediting a signed tag body omits signature' ' |
086cb911 | 1316 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1317 | echo "RFC1991 signed tag" >expect && |
1318 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1319 | test_cmp expect actual | |
1320 | ' | |
1321 | ||
c0e0ed6e | 1322 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1323 | 'verifying rfc1991 signature' ' |
086cb911 | 1324 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1325 | git tag -v rfc1991-signed-tag |
1326 | ' | |
1327 | ||
c0e0ed6e | 1328 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1329 | 'list tag with rfc1991 signature' ' |
086cb911 | 1330 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1331 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && |
1332 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1333 | test_cmp expect actual && | |
1334 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1335 | test_cmp expect actual && | |
1336 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1337 | test_cmp expect actual | |
1338 | ' | |
1339 | ||
1340 | rm -f gpghome/gpg.conf | |
1341 | ||
c0e0ed6e | 1342 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1343 | 'verifying rfc1991 signature without --rfc1991' ' |
1344 | git tag -v rfc1991-signed-tag | |
1345 | ' | |
1346 | ||
c0e0ed6e | 1347 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1348 | 'list tag with rfc1991 signature without --rfc1991' ' |
1349 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1350 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1351 | test_cmp expect actual && | |
1352 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1353 | test_cmp expect actual && | |
1354 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1355 | test_cmp expect actual | |
1356 | ' | |
1357 | ||
c0e0ed6e | 1358 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1359 | 'reediting a signed tag body omits signature' ' |
1360 | echo "RFC1991 signed tag" >expect && | |
1361 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1362 | test_cmp expect actual | |
1363 | ' | |
1364 | ||
aba91192 | 1365 | # try to sign with bad user.signingkey |
a4df22ce | 1366 | test_expect_success GPG \ |
efee9553 | 1367 | 'git tag -s fails if gpg is misconfigured (bad key)' \ |
9ffda48f SG |
1368 | 'test_config user.signingkey BobTheMouse && |
1369 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
aba91192 | 1370 | |
efee9553 MG |
1371 | # try to produce invalid signature |
1372 | test_expect_success GPG \ | |
1373 | 'git tag -s fails if gpg is misconfigured (bad signature format)' \ | |
1374 | 'test_config gpg.program echo && | |
1375 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
1376 | ||
53fc9993 HS |
1377 | # try to sign with bad user.signingkey |
1378 | test_expect_success GPGSM \ | |
1379 | 'git tag -s fails if gpgsm is misconfigured (bad key)' \ | |
1380 | 'test_config user.signingkey BobTheMouse && | |
1381 | test_config gpg.format x509 && | |
1382 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
1383 | ||
1384 | # try to produce invalid signature | |
1385 | test_expect_success GPGSM \ | |
1386 | 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \ | |
1387 | 'test_config gpg.x509.program echo && | |
1388 | test_config gpg.format x509 && | |
1389 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
efee9553 | 1390 | |
ef5a6fb5 CR |
1391 | # try to verify without gpg: |
1392 | ||
1393 | rm -rf gpghome | |
a4df22ce | 1394 | test_expect_success GPG \ |
ef5a6fb5 | 1395 | 'verify signed tag fails when public key is not present' \ |
d592b315 | 1396 | 'test_must_fail git tag -v signed-tag' |
ef5a6fb5 | 1397 | |
41ac414e | 1398 | test_expect_success \ |
d592b315 | 1399 | 'git tag -a fails if tag annotation is empty' ' |
41ac414e | 1400 | ! (GIT_EDITOR=cat git tag -a initial-comment) |
eb9d2b91 MH |
1401 | ' |
1402 | ||
4d8b1dc8 MH |
1403 | test_expect_success \ |
1404 | 'message in editor has initial comment' ' | |
5649bd9a ÆAB |
1405 | ! (GIT_EDITOR=cat git tag -a initial-comment > actual) |
1406 | ' | |
1407 | ||
b3e1900a | 1408 | test_expect_success 'message in editor has initial comment: first line' ' |
eb9d2b91 | 1409 | # check the first line --- should be empty |
5649bd9a ÆAB |
1410 | echo >first.expect && |
1411 | sed -e 1q <actual >first.actual && | |
b3e1900a | 1412 | test_i18ncmp first.expect first.actual |
5649bd9a ÆAB |
1413 | ' |
1414 | ||
1415 | test_expect_success \ | |
1416 | 'message in editor has initial comment: remainder' ' | |
eb9d2b91 | 1417 | # remove commented lines from the remainder -- should be empty |
11f228b0 | 1418 | sed -e 1d -e "/^#/d" <actual >rest.actual && |
d3c6751b | 1419 | test_must_be_empty rest.actual |
4d8b1dc8 MH |
1420 | ' |
1421 | ||
1422 | get_tag_header reuse $commit commit $time >expect | |
1423 | echo "An annotation to be reused" >> expect | |
1424 | test_expect_success \ | |
4dc8b1c1 | 1425 | 'overwriting an annotated tag should use its previous body' ' |
4d8b1dc8 MH |
1426 | git tag -a -m "An annotation to be reused" reuse && |
1427 | GIT_EDITOR=true git tag -f -a reuse && | |
1428 | get_tag_msg reuse >actual && | |
3af82863 | 1429 | test_cmp expect actual |
4d8b1dc8 MH |
1430 | ' |
1431 | ||
dbd0f5c7 JH |
1432 | test_expect_success 'filename for the message is relative to cwd' ' |
1433 | mkdir subdir && | |
1434 | echo "Tag message in top directory" >msgfile-5 && | |
1435 | echo "Tag message in sub directory" >subdir/msgfile-5 && | |
1436 | ( | |
1437 | cd subdir && | |
1438 | git tag -a -F msgfile-5 tag-from-subdir | |
1439 | ) && | |
1440 | git cat-file tag tag-from-subdir | grep "in sub directory" | |
1441 | ' | |
1442 | ||
1443 | test_expect_success 'filename for the message is relative to cwd' ' | |
1444 | echo "Tag message in sub directory" >subdir/msgfile-6 && | |
1445 | ( | |
1446 | cd subdir && | |
1447 | git tag -a -F msgfile-6 tag-from-subdir-2 | |
1448 | ) && | |
1449 | git cat-file tag tag-from-subdir-2 | grep "in sub directory" | |
1450 | ' | |
1451 | ||
32c35cfb JG |
1452 | # create a few more commits to test --contains |
1453 | ||
1454 | hash1=$(git rev-parse HEAD) | |
1455 | ||
1456 | test_expect_success 'creating second commit and tag' ' | |
1457 | echo foo-2.0 >foo && | |
1458 | git add foo && | |
2dec68cf | 1459 | git commit -m second && |
32c35cfb JG |
1460 | git tag v2.0 |
1461 | ' | |
1462 | ||
1463 | hash2=$(git rev-parse HEAD) | |
1464 | ||
1465 | test_expect_success 'creating third commit without tag' ' | |
1466 | echo foo-dev >foo && | |
1467 | git add foo && | |
1468 | git commit -m third | |
1469 | ' | |
1470 | ||
1471 | hash3=$(git rev-parse HEAD) | |
1472 | ||
1473 | # simple linear checks of --continue | |
1474 | ||
1475 | cat > expected <<EOF | |
1476 | v0.2.1 | |
1477 | v1.0 | |
1478 | v1.0.1 | |
1479 | v1.1.3 | |
1480 | v2.0 | |
1481 | EOF | |
1482 | ||
1483 | test_expect_success 'checking that first commit is in all tags (hash)' " | |
2dec68cf | 1484 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1485 | test_cmp expected actual |
1486 | " | |
1487 | ||
1488 | # other ways of specifying the commit | |
1489 | test_expect_success 'checking that first commit is in all tags (tag)' " | |
2dec68cf | 1490 | git tag -l --contains v1.0 v* >actual && |
32c35cfb JG |
1491 | test_cmp expected actual |
1492 | " | |
1493 | ||
1494 | test_expect_success 'checking that first commit is in all tags (relative)' " | |
2dec68cf | 1495 | git tag -l --contains HEAD~2 v* >actual && |
32c35cfb JG |
1496 | test_cmp expected actual |
1497 | " | |
1498 | ||
ac3f5a34 ÆAB |
1499 | # All the --contains tests above, but with --no-contains |
1500 | test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' " | |
ac3f5a34 | 1501 | git tag -l --no-contains $hash1 v* >actual && |
d3c6751b | 1502 | test_must_be_empty actual |
ac3f5a34 ÆAB |
1503 | " |
1504 | ||
1505 | test_expect_success 'checking that first commit is in all tags (tag)' " | |
1506 | git tag -l --no-contains v1.0 v* >actual && | |
d3c6751b | 1507 | test_must_be_empty actual |
ac3f5a34 ÆAB |
1508 | " |
1509 | ||
1510 | test_expect_success 'checking that first commit is in all tags (relative)' " | |
1511 | git tag -l --no-contains HEAD~2 v* >actual && | |
d3c6751b | 1512 | test_must_be_empty actual |
ac3f5a34 ÆAB |
1513 | " |
1514 | ||
32c35cfb JG |
1515 | cat > expected <<EOF |
1516 | v2.0 | |
1517 | EOF | |
1518 | ||
1519 | test_expect_success 'checking that second commit only has one tag' " | |
2dec68cf | 1520 | git tag -l --contains $hash2 v* >actual && |
32c35cfb JG |
1521 | test_cmp expected actual |
1522 | " | |
1523 | ||
ac3f5a34 ÆAB |
1524 | cat > expected <<EOF |
1525 | v0.2.1 | |
1526 | v1.0 | |
1527 | v1.0.1 | |
1528 | v1.1.3 | |
1529 | EOF | |
1530 | ||
1531 | test_expect_success 'inverse of the last test, with --no-contains' " | |
1532 | git tag -l --no-contains $hash2 v* >actual && | |
1533 | test_cmp expected actual | |
1534 | " | |
32c35cfb | 1535 | |
32c35cfb | 1536 | test_expect_success 'checking that third commit has no tags' " |
2dec68cf | 1537 | git tag -l --contains $hash3 v* >actual && |
1c5e94f4 | 1538 | test_must_be_empty actual |
32c35cfb JG |
1539 | " |
1540 | ||
ac3f5a34 ÆAB |
1541 | cat > expected <<EOF |
1542 | v0.2.1 | |
1543 | v1.0 | |
1544 | v1.0.1 | |
1545 | v1.1.3 | |
1546 | v2.0 | |
1547 | EOF | |
1548 | ||
1549 | test_expect_success 'conversely --no-contains on the third commit lists all tags' " | |
1550 | git tag -l --no-contains $hash3 v* >actual && | |
1551 | test_cmp expected actual | |
1552 | " | |
1553 | ||
32c35cfb JG |
1554 | # how about a simple merge? |
1555 | ||
1556 | test_expect_success 'creating simple branch' ' | |
1557 | git branch stable v2.0 && | |
1558 | git checkout stable && | |
1559 | echo foo-3.0 > foo && | |
2dec68cf | 1560 | git commit foo -m fourth && |
32c35cfb JG |
1561 | git tag v3.0 |
1562 | ' | |
1563 | ||
1564 | hash4=$(git rev-parse HEAD) | |
1565 | ||
1566 | cat > expected <<EOF | |
1567 | v3.0 | |
1568 | EOF | |
1569 | ||
1570 | test_expect_success 'checking that branch head only has one tag' " | |
2dec68cf | 1571 | git tag -l --contains $hash4 v* >actual && |
32c35cfb JG |
1572 | test_cmp expected actual |
1573 | " | |
1574 | ||
ac3f5a34 ÆAB |
1575 | cat > expected <<EOF |
1576 | v0.2.1 | |
1577 | v1.0 | |
1578 | v1.0.1 | |
1579 | v1.1.3 | |
1580 | v2.0 | |
1581 | EOF | |
1582 | ||
1583 | test_expect_success 'checking that branch head with --no-contains lists all but one tag' " | |
1584 | git tag -l --no-contains $hash4 v* >actual && | |
1585 | test_cmp expected actual | |
1586 | " | |
1587 | ||
32c35cfb | 1588 | test_expect_success 'merging original branch into this branch' ' |
01dc8133 | 1589 | git merge --strategy=ours main && |
32c35cfb JG |
1590 | git tag v4.0 |
1591 | ' | |
1592 | ||
1593 | cat > expected <<EOF | |
1594 | v4.0 | |
1595 | EOF | |
1596 | ||
1597 | test_expect_success 'checking that original branch head has one tag now' " | |
2dec68cf | 1598 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1599 | test_cmp expected actual |
1600 | " | |
1601 | ||
ac3f5a34 ÆAB |
1602 | cat > expected <<EOF |
1603 | v0.2.1 | |
1604 | v1.0 | |
1605 | v1.0.1 | |
1606 | v1.1.3 | |
1607 | v2.0 | |
1608 | v3.0 | |
1609 | EOF | |
1610 | ||
1611 | test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' " | |
1612 | git tag -l --no-contains $hash3 v* >actual && | |
1613 | test_cmp expected actual | |
1614 | " | |
1615 | ||
32c35cfb JG |
1616 | cat > expected <<EOF |
1617 | v0.2.1 | |
1618 | v1.0 | |
1619 | v1.0.1 | |
1620 | v1.1.3 | |
1621 | v2.0 | |
1622 | v3.0 | |
1623 | v4.0 | |
1624 | EOF | |
1625 | ||
1626 | test_expect_success 'checking that initial commit is in all tags' " | |
2dec68cf | 1627 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1628 | test_cmp expected actual |
1629 | " | |
1630 | ||
6a338149 ÆAB |
1631 | test_expect_success 'checking that --contains can be used in non-list mode' ' |
1632 | git tag --contains $hash1 v* >actual && | |
1633 | test_cmp expected actual | |
1634 | ' | |
1635 | ||
ac3f5a34 | 1636 | test_expect_success 'checking that initial commit is in all tags with --no-contains' " |
ac3f5a34 | 1637 | git tag -l --no-contains $hash1 v* >actual && |
d3c6751b | 1638 | test_must_be_empty actual |
ac3f5a34 ÆAB |
1639 | " |
1640 | ||
e0e03a73 ST |
1641 | # mixing modes and options: |
1642 | ||
1643 | test_expect_success 'mixing incompatibles modes and options is forbidden' ' | |
2dec68cf | 1644 | test_must_fail git tag -a && |
bf748049 ÆAB |
1645 | test_must_fail git tag -a -l && |
1646 | test_must_fail git tag -s && | |
1647 | test_must_fail git tag -s -l && | |
1648 | test_must_fail git tag -m && | |
1649 | test_must_fail git tag -m -l && | |
1650 | test_must_fail git tag -m "hlagh" && | |
1651 | test_must_fail git tag -m "hlagh" -l && | |
1652 | test_must_fail git tag -F && | |
1653 | test_must_fail git tag -F -l && | |
1654 | test_must_fail git tag -f && | |
1655 | test_must_fail git tag -f -l && | |
1656 | test_must_fail git tag -a -s -m -F && | |
1657 | test_must_fail git tag -a -s -m -F -l && | |
2dec68cf | 1658 | test_must_fail git tag -l -v && |
bf748049 ÆAB |
1659 | test_must_fail git tag -l -d && |
1660 | test_must_fail git tag -l -v -d && | |
bf748049 | 1661 | test_must_fail git tag -n 100 -v && |
2dec68cf JN |
1662 | test_must_fail git tag -l -m msg && |
1663 | test_must_fail git tag -l -F some file && | |
b643827b ÆAB |
1664 | test_must_fail git tag -v -s && |
1665 | test_must_fail git tag --contains tag-tree && | |
ac3f5a34 ÆAB |
1666 | test_must_fail git tag --contains tag-blob && |
1667 | test_must_fail git tag --no-contains tag-tree && | |
1668 | test_must_fail git tag --no-contains tag-blob && | |
75057691 ÆAB |
1669 | test_must_fail git tag --contains --no-contains && |
1670 | test_must_fail git tag --no-with HEAD && | |
1671 | test_must_fail git tag --no-without HEAD | |
e0e03a73 ST |
1672 | ' |
1673 | ||
75057691 | 1674 | for option in --contains --with --no-contains --without --merged --no-merged --points-at |
6a338149 ÆAB |
1675 | do |
1676 | test_expect_success "mixing incompatible modes with $option is forbidden" " | |
1677 | test_must_fail git tag -d $option HEAD && | |
1678 | test_must_fail git tag -d $option HEAD some-tag && | |
1679 | test_must_fail git tag -v $option HEAD | |
1680 | " | |
1681 | test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" " | |
1682 | git tag -n $option HEAD HEAD && | |
1e0c3b68 ÆAB |
1683 | git tag $option HEAD HEAD && |
1684 | git tag $option | |
6a338149 ÆAB |
1685 | " |
1686 | done | |
e0e03a73 | 1687 | |
ae7706b9 TG |
1688 | # check points-at |
1689 | ||
6a338149 ÆAB |
1690 | test_expect_success '--points-at can be used in non-list mode' ' |
1691 | echo v4.0 >expect && | |
1692 | git tag --points-at=v4.0 "v*" >actual && | |
1693 | test_cmp expect actual | |
ae7706b9 TG |
1694 | ' |
1695 | ||
1e0c3b68 ÆAB |
1696 | test_expect_success '--points-at is a synonym for --points-at HEAD' ' |
1697 | echo v4.0 >expect && | |
1698 | git tag --points-at >actual && | |
1699 | test_cmp expect actual | |
ae7706b9 TG |
1700 | ' |
1701 | ||
1702 | test_expect_success '--points-at finds lightweight tags' ' | |
1703 | echo v4.0 >expect && | |
1704 | git tag --points-at v4.0 >actual && | |
1705 | test_cmp expect actual | |
1706 | ' | |
1707 | ||
1708 | test_expect_success '--points-at finds annotated tags of commits' ' | |
1709 | git tag -m "v4.0, annotated" annotated-v4.0 v4.0 && | |
1710 | echo annotated-v4.0 >expect && | |
1711 | git tag -l --points-at v4.0 "annotated*" >actual && | |
1712 | test_cmp expect actual | |
1713 | ' | |
1714 | ||
1715 | test_expect_success '--points-at finds annotated tags of tags' ' | |
1716 | git tag -m "describing the v4.0 tag object" \ | |
1717 | annotated-again-v4.0 annotated-v4.0 && | |
1718 | cat >expect <<-\EOF && | |
1719 | annotated-again-v4.0 | |
1720 | annotated-v4.0 | |
1721 | EOF | |
1722 | git tag --points-at=annotated-v4.0 >actual && | |
1723 | test_cmp expect actual | |
1724 | ' | |
1725 | ||
eea9c1e7 DL |
1726 | test_expect_success 'recursive tagging should give advice' ' |
1727 | sed -e "s/|$//" <<-EOF >expect && | |
a54b2ab3 | 1728 | hint: You have created a nested tag. The object referred to by your new tag is |
eea9c1e7 DL |
1729 | hint: already a tag. If you meant to tag the object that it points to, use: |
1730 | hint: | | |
1731 | hint: git tag -f nested annotated-v4.0^{} | |
f665d63a | 1732 | hint: Disable this message with "git config advice.nestedTag false" |
eea9c1e7 DL |
1733 | EOF |
1734 | git tag -m nested nested annotated-v4.0 2>actual && | |
1735 | test_i18ncmp expect actual | |
1736 | ' | |
1737 | ||
ae7706b9 TG |
1738 | test_expect_success 'multiple --points-at are OR-ed together' ' |
1739 | cat >expect <<-\EOF && | |
1740 | v2.0 | |
1741 | v3.0 | |
1742 | EOF | |
1743 | git tag --points-at=v2.0 --points-at=v3.0 >actual && | |
1744 | test_cmp expect actual | |
1745 | ' | |
1746 | ||
9ef176b5 NTND |
1747 | test_expect_success 'lexical sort' ' |
1748 | git tag foo1.3 && | |
1749 | git tag foo1.6 && | |
1750 | git tag foo1.10 && | |
1751 | git tag -l --sort=refname "foo*" >actual && | |
dc662d44 JK |
1752 | cat >expect <<-\EOF && |
1753 | foo1.10 | |
1754 | foo1.3 | |
1755 | foo1.6 | |
1756 | EOF | |
9ef176b5 NTND |
1757 | test_cmp expect actual |
1758 | ' | |
1759 | ||
1760 | test_expect_success 'version sort' ' | |
1761 | git tag -l --sort=version:refname "foo*" >actual && | |
dc662d44 JK |
1762 | cat >expect <<-\EOF && |
1763 | foo1.3 | |
1764 | foo1.6 | |
1765 | foo1.10 | |
1766 | EOF | |
9ef176b5 NTND |
1767 | test_cmp expect actual |
1768 | ' | |
1769 | ||
1770 | test_expect_success 'reverse version sort' ' | |
1771 | git tag -l --sort=-version:refname "foo*" >actual && | |
dc662d44 JK |
1772 | cat >expect <<-\EOF && |
1773 | foo1.10 | |
1774 | foo1.6 | |
1775 | foo1.3 | |
1776 | EOF | |
9ef176b5 NTND |
1777 | test_cmp expect actual |
1778 | ' | |
1779 | ||
1780 | test_expect_success 'reverse lexical sort' ' | |
1781 | git tag -l --sort=-refname "foo*" >actual && | |
dc662d44 JK |
1782 | cat >expect <<-\EOF && |
1783 | foo1.6 | |
1784 | foo1.3 | |
1785 | foo1.10 | |
1786 | EOF | |
9ef176b5 NTND |
1787 | test_cmp expect actual |
1788 | ' | |
1789 | ||
b150794d | 1790 | test_expect_success 'configured lexical sort' ' |
9ffda48f | 1791 | test_config tag.sort "v:refname" && |
b150794d JK |
1792 | git tag -l "foo*" >actual && |
1793 | cat >expect <<-\EOF && | |
1794 | foo1.3 | |
1795 | foo1.6 | |
1796 | foo1.10 | |
1797 | EOF | |
1798 | test_cmp expect actual | |
1799 | ' | |
1800 | ||
1801 | test_expect_success 'option override configured sort' ' | |
9ffda48f | 1802 | test_config tag.sort "v:refname" && |
b150794d JK |
1803 | git tag -l --sort=-refname "foo*" >actual && |
1804 | cat >expect <<-\EOF && | |
1805 | foo1.6 | |
1806 | foo1.3 | |
1807 | foo1.10 | |
1808 | EOF | |
1809 | test_cmp expect actual | |
1810 | ' | |
1811 | ||
1812 | test_expect_success 'invalid sort parameter on command line' ' | |
1813 | test_must_fail git tag -l --sort=notvalid "foo*" >actual | |
1814 | ' | |
1815 | ||
1816 | test_expect_success 'invalid sort parameter in configuratoin' ' | |
9ffda48f | 1817 | test_config tag.sort "v:notvalid" && |
b7cc53e9 | 1818 | test_must_fail git tag -l "foo*" |
b150794d JK |
1819 | ' |
1820 | ||
d811c8e1 | 1821 | test_expect_success 'version sort with prerelease reordering' ' |
9ffda48f | 1822 | test_config versionsort.prereleaseSuffix -rc && |
d811c8e1 NTND |
1823 | git tag foo1.6-rc1 && |
1824 | git tag foo1.6-rc2 && | |
1825 | git tag -l --sort=version:refname "foo*" >actual && | |
1826 | cat >expect <<-\EOF && | |
1827 | foo1.3 | |
1828 | foo1.6-rc1 | |
1829 | foo1.6-rc2 | |
1830 | foo1.6 | |
1831 | foo1.10 | |
1832 | EOF | |
1833 | test_cmp expect actual | |
1834 | ' | |
1835 | ||
1836 | test_expect_success 'reverse version sort with prerelease reordering' ' | |
9ffda48f | 1837 | test_config versionsort.prereleaseSuffix -rc && |
d811c8e1 NTND |
1838 | git tag -l --sort=-version:refname "foo*" >actual && |
1839 | cat >expect <<-\EOF && | |
1840 | foo1.10 | |
1841 | foo1.6 | |
1842 | foo1.6-rc2 | |
1843 | foo1.6-rc1 | |
1844 | foo1.3 | |
1845 | EOF | |
1846 | test_cmp expect actual | |
1847 | ' | |
1848 | ||
b8231660 | 1849 | test_expect_success 'version sort with prerelease reordering and common leading character' ' |
0c1b4878 SG |
1850 | test_config versionsort.prereleaseSuffix -before && |
1851 | git tag foo1.7-before1 && | |
1852 | git tag foo1.7 && | |
1853 | git tag foo1.7-after1 && | |
1854 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1855 | cat >expect <<-\EOF && | |
1856 | foo1.7-before1 | |
1857 | foo1.7 | |
1858 | foo1.7-after1 | |
1859 | EOF | |
1860 | test_cmp expect actual | |
1861 | ' | |
1862 | ||
b8231660 | 1863 | test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' ' |
0c1b4878 SG |
1864 | test_config versionsort.prereleaseSuffix -before && |
1865 | git config --add versionsort.prereleaseSuffix -after && | |
1866 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1867 | cat >expect <<-\EOF && | |
1868 | foo1.7-before1 | |
1869 | foo1.7-after1 | |
1870 | foo1.7 | |
1871 | EOF | |
1872 | test_cmp expect actual | |
1873 | ' | |
1874 | ||
51acfa9d SG |
1875 | test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' ' |
1876 | test_config versionsort.prereleaseSuffix -bar && | |
1877 | git config --add versionsort.prereleaseSuffix -foo-baz && | |
1878 | git config --add versionsort.prereleaseSuffix -foo-bar && | |
1879 | git tag foo1.8-foo-bar && | |
1880 | git tag foo1.8-foo-baz && | |
1881 | git tag foo1.8 && | |
1882 | git tag -l --sort=version:refname "foo1.8*" >actual && | |
1883 | cat >expect <<-\EOF && | |
1884 | foo1.8-foo-baz | |
1885 | foo1.8-foo-bar | |
1886 | foo1.8 | |
1887 | EOF | |
1888 | test_cmp expect actual | |
1889 | ' | |
1890 | ||
1891 | test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' ' | |
1892 | test_config versionsort.prereleaseSuffix -pre && | |
1893 | git config --add versionsort.prereleaseSuffix -prerelease && | |
1894 | git tag foo1.9-pre1 && | |
1895 | git tag foo1.9-pre2 && | |
1896 | git tag foo1.9-prerelease1 && | |
1897 | git tag -l --sort=version:refname "foo1.9*" >actual && | |
1898 | cat >expect <<-\EOF && | |
1899 | foo1.9-pre1 | |
1900 | foo1.9-pre2 | |
1901 | foo1.9-prerelease1 | |
1902 | EOF | |
1903 | test_cmp expect actual | |
1904 | ' | |
1905 | ||
c026557a SG |
1906 | test_expect_success 'version sort with general suffix reordering' ' |
1907 | test_config versionsort.suffix -alpha && | |
1908 | git config --add versionsort.suffix -beta && | |
1909 | git config --add versionsort.suffix "" && | |
1910 | git config --add versionsort.suffix -gamma && | |
1911 | git config --add versionsort.suffix -delta && | |
1912 | git tag foo1.10-alpha && | |
1913 | git tag foo1.10-beta && | |
1914 | git tag foo1.10-gamma && | |
1915 | git tag foo1.10-delta && | |
1916 | git tag foo1.10-unlisted-suffix && | |
1917 | git tag -l --sort=version:refname "foo1.10*" >actual && | |
1918 | cat >expect <<-\EOF && | |
1919 | foo1.10-alpha | |
1920 | foo1.10-beta | |
1921 | foo1.10 | |
1922 | foo1.10-unlisted-suffix | |
1923 | foo1.10-gamma | |
1924 | foo1.10-delta | |
1925 | EOF | |
1926 | test_cmp expect actual | |
1927 | ' | |
1928 | ||
1929 | test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' ' | |
1930 | test_config versionsort.suffix -before && | |
1931 | test_config versionsort.prereleaseSuffix -after && | |
1932 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1933 | cat >expect <<-\EOF && | |
1934 | foo1.7-before1 | |
1935 | foo1.7 | |
1936 | foo1.7-after1 | |
1937 | EOF | |
1938 | test_cmp expect actual | |
1939 | ' | |
1940 | ||
b8231660 SG |
1941 | test_expect_success 'version sort with very long prerelease suffix' ' |
1942 | test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix && | |
1943 | git tag -l --sort=version:refname | |
1944 | ' | |
1945 | ||
ac3f5a34 | 1946 | test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' ' |
cbc60b67 | 1947 | i=1 && |
b9a19078 | 1948 | while test $i -lt 8000 |
cbc60b67 | 1949 | do |
01dc8133 | 1950 | echo "commit refs/heads/main |
cbc60b67 JJL |
1951 | committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 |
1952 | data <<EOF | |
1953 | commit #$i | |
1954 | EOF" | |
01dc8133 | 1955 | test $i = 1 && echo "from refs/heads/main^0" |
cbc60b67 JJL |
1956 | i=$(($i + 1)) |
1957 | done | git fast-import && | |
01dc8133 | 1958 | git checkout main && |
cbc60b67 JJL |
1959 | git tag far-far-away HEAD^ && |
1960 | run_with_limited_stack git tag --contains HEAD >actual && | |
d3c6751b | 1961 | test_must_be_empty actual && |
ac3f5a34 | 1962 | run_with_limited_stack git tag --no-contains HEAD >actual && |
dff28133 | 1963 | test_line_count "-gt" 10 actual |
cbc60b67 JJL |
1964 | ' |
1965 | ||
df094741 KN |
1966 | test_expect_success '--format should list tags as per format given' ' |
1967 | cat >expect <<-\EOF && | |
0c1b4878 SG |
1968 | refname : refs/tags/v1.0 |
1969 | refname : refs/tags/v1.0.1 | |
1970 | refname : refs/tags/v1.1.3 | |
df094741 | 1971 | EOF |
0c1b4878 | 1972 | git tag -l --format="refname : %(refname)" "v1*" >actual && |
df094741 KN |
1973 | test_cmp expect actual |
1974 | ' | |
1975 | ||
11b087ad JK |
1976 | test_expect_success "set up color tests" ' |
1977 | echo "<RED>v1.0<RESET>" >expect.color && | |
1978 | echo "v1.0" >expect.bare && | |
1979 | color_args="--format=%(color:red)%(refname:short) --list v1.0" | |
1980 | ' | |
1981 | ||
1982 | test_expect_success '%(color) omitted without tty' ' | |
1983 | TERM=vt100 git tag $color_args >actual.raw && | |
1984 | test_decode_color <actual.raw >actual && | |
1985 | test_cmp expect.bare actual | |
1986 | ' | |
1987 | ||
1988 | test_expect_success TTY '%(color) present with tty' ' | |
e433749d | 1989 | test_terminal git tag $color_args >actual.raw && |
11b087ad JK |
1990 | test_decode_color <actual.raw >actual && |
1991 | test_cmp expect.color actual | |
1992 | ' | |
1993 | ||
0c88bf50 JK |
1994 | test_expect_success '--color overrides auto-color' ' |
1995 | git tag --color $color_args >actual.raw && | |
11b087ad JK |
1996 | test_decode_color <actual.raw >actual && |
1997 | test_cmp expect.color actual | |
1998 | ' | |
1999 | ||
b521fd12 JK |
2000 | test_expect_success 'color.ui=always overrides auto-color' ' |
2001 | git -c color.ui=always tag $color_args >actual.raw && | |
2002 | test_decode_color <actual.raw >actual && | |
2003 | test_cmp expect.color actual | |
2004 | ' | |
2005 | ||
5242860f KN |
2006 | test_expect_success 'setup --merged test tags' ' |
2007 | git tag mergetest-1 HEAD~2 && | |
2008 | git tag mergetest-2 HEAD~1 && | |
2009 | git tag mergetest-3 HEAD | |
2010 | ' | |
2011 | ||
6a338149 ÆAB |
2012 | test_expect_success '--merged can be used in non-list mode' ' |
2013 | cat >expect <<-\EOF && | |
2014 | mergetest-1 | |
2015 | mergetest-2 | |
2016 | EOF | |
2017 | git tag --merged=mergetest-2 "mergetest*" >actual && | |
2018 | test_cmp expect actual | |
5242860f KN |
2019 | ' |
2020 | ||
21bf9339 AL |
2021 | test_expect_success '--merged is compatible with --no-merged' ' |
2022 | git tag --merged HEAD --no-merged HEAD | |
5242860f KN |
2023 | ' |
2024 | ||
2025 | test_expect_success '--merged shows merged tags' ' | |
2026 | cat >expect <<-\EOF && | |
2027 | mergetest-1 | |
2028 | mergetest-2 | |
2029 | EOF | |
2030 | git tag -l --merged=mergetest-2 mergetest-* >actual && | |
2031 | test_cmp expect actual | |
2032 | ' | |
2033 | ||
2034 | test_expect_success '--no-merged show unmerged tags' ' | |
2035 | cat >expect <<-\EOF && | |
2036 | mergetest-3 | |
2037 | EOF | |
2038 | git tag -l --no-merged=mergetest-2 mergetest-* >actual && | |
2039 | test_cmp expect actual | |
2040 | ' | |
2041 | ||
6a338149 ÆAB |
2042 | test_expect_success '--no-merged can be used in non-list mode' ' |
2043 | git tag --no-merged=mergetest-2 mergetest-* >actual && | |
2044 | test_cmp expect actual | |
2045 | ' | |
2046 | ||
0571979b JK |
2047 | test_expect_success 'ambiguous branch/tags not marked' ' |
2048 | git tag ambiguous && | |
2049 | git branch ambiguous && | |
2050 | echo ambiguous >expect && | |
2051 | git tag -l ambiguous >actual && | |
2052 | test_cmp expect actual | |
2053 | ' | |
2054 | ||
ac3f5a34 ÆAB |
2055 | test_expect_success '--contains combined with --no-contains' ' |
2056 | ( | |
2057 | git init no-contains && | |
2058 | cd no-contains && | |
2059 | test_commit v0.1 && | |
2060 | test_commit v0.2 && | |
2061 | test_commit v0.3 && | |
2062 | test_commit v0.4 && | |
2063 | test_commit v0.5 && | |
2064 | cat >expected <<-\EOF && | |
2065 | v0.2 | |
2066 | v0.3 | |
2067 | v0.4 | |
2068 | EOF | |
2069 | git tag --contains v0.2 --no-contains v0.5 >actual && | |
2070 | test_cmp expected actual | |
2071 | ) | |
2072 | ' | |
2073 | ||
2074 | # As the docs say, list tags which contain a specified *commit*. We | |
2075 | # don't recurse down to tags for trees or blobs pointed to by *those* | |
2076 | # commits. | |
2077 | test_expect_success 'Does --[no-]contains stop at commits? Yes!' ' | |
2078 | cd no-contains && | |
2079 | blob=$(git rev-parse v0.3:v0.3.t) && | |
2080 | tree=$(git rev-parse v0.3^{tree}) && | |
2081 | git tag tag-blob $blob && | |
2082 | git tag tag-tree $tree && | |
2083 | git tag --contains v0.3 >actual && | |
2084 | cat >expected <<-\EOF && | |
2085 | v0.3 | |
2086 | v0.4 | |
2087 | v0.5 | |
2088 | EOF | |
2089 | test_cmp expected actual && | |
2090 | git tag --no-contains v0.3 >actual && | |
2091 | cat >expected <<-\EOF && | |
2092 | v0.1 | |
2093 | v0.2 | |
2094 | EOF | |
2095 | test_cmp expected actual | |
2096 | ' | |
2097 | ||
ef5a6fb5 | 2098 | test_done |