]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7004-tag.sh
bdd28dad14d6f6dd7730e2fff6a82dc9308f3a80
[thirdparty/git.git] / t / t7004-tag.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Carlos Rica
4 #
5
6 test_description='git tag
7
8 Tests for operations with tags.'
9
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-gpg.sh
12
13 # creating and listing lightweight tags:
14
15 tag_exists () {
16 git show-ref --quiet --verify refs/tags/"$1"
17 }
18
19 # todo: git tag -l now returns always zero, when fixed, change this test
20 test_expect_success 'listing all tags in an empty tree should succeed' '
21 git tag -l &&
22 git tag
23 '
24
25 test_expect_success 'listing all tags in an empty tree should output nothing' '
26 test $(git tag -l | wc -l) -eq 0 &&
27 test $(git tag | wc -l) -eq 0
28 '
29
30 test_expect_success 'looking for a tag in an empty tree should fail' \
31 '! (tag_exists mytag)'
32
33 test_expect_success 'creating a tag in an empty tree should fail' '
34 test_must_fail git tag mynotag &&
35 ! tag_exists mynotag
36 '
37
38 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
39 test_must_fail git tag mytaghead HEAD &&
40 ! tag_exists mytaghead
41 '
42
43 test_expect_success 'creating a tag for an unknown revision should fail' '
44 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
45 ! tag_exists mytagnorev
46 '
47
48 # commit used in the tests, test_tick is also called here to freeze the date:
49 test_expect_success 'creating a tag using default HEAD should succeed' '
50 test_tick &&
51 echo foo >foo &&
52 git add foo &&
53 git commit -m Foo &&
54 git tag mytag &&
55 test_must_fail git reflog exists refs/tags/mytag
56 '
57
58 test_expect_success 'creating a tag with --create-reflog should create reflog' '
59 test_when_finished "git tag -d tag_with_reflog" &&
60 git tag --create-reflog tag_with_reflog &&
61 git reflog exists refs/tags/tag_with_reflog
62 '
63
64 test_expect_success '--create-reflog does not create reflog on failure' '
65 test_must_fail git tag --create-reflog mytag &&
66 test_must_fail git reflog exists refs/tags/mytag
67 '
68
69 test_expect_success 'listing all tags if one exists should succeed' '
70 git tag -l &&
71 git tag
72 '
73
74 test_expect_success 'listing all tags if one exists should output that tag' '
75 test $(git tag -l) = mytag &&
76 test $(git tag) = mytag
77 '
78
79 # pattern matching:
80
81 test_expect_success 'listing a tag using a matching pattern should succeed' \
82 'git tag -l mytag'
83
84 test_expect_success \
85 'listing a tag using a matching pattern should output that tag' \
86 'test $(git tag -l mytag) = mytag'
87
88 # todo: git tag -l now returns always zero, when fixed, change this test
89 test_expect_success \
90 'listing tags using a non-matching pattern should suceed' \
91 'git tag -l xxx'
92
93 test_expect_success \
94 'listing tags using a non-matching pattern should output nothing' \
95 'test $(git tag -l xxx | wc -l) -eq 0'
96
97 # special cases for creating tags:
98
99 test_expect_success \
100 'trying to create a tag with the name of one existing should fail' \
101 'test_must_fail git tag mytag'
102
103 test_expect_success \
104 'trying to create a tag with a non-valid name should fail' '
105 test $(git tag -l | wc -l) -eq 1 &&
106 test_must_fail git tag "" &&
107 test_must_fail git tag .othertag &&
108 test_must_fail git tag "other tag" &&
109 test_must_fail git tag "othertag^" &&
110 test_must_fail git tag "other~tag" &&
111 test $(git tag -l | wc -l) -eq 1
112 '
113
114 test_expect_success 'creating a tag using HEAD directly should succeed' '
115 git tag myhead HEAD &&
116 tag_exists myhead
117 '
118
119 test_expect_success '--force can create a tag with the name of one existing' '
120 tag_exists mytag &&
121 git tag --force mytag &&
122 tag_exists mytag'
123
124 test_expect_success '--force is moot with a non-existing tag name' '
125 test_when_finished git tag -d newtag forcetag &&
126 git tag newtag >expect &&
127 git tag --force forcetag >actual &&
128 test_cmp expect actual
129 '
130
131 # deleting tags:
132
133 test_expect_success 'trying to delete an unknown tag should fail' '
134 ! tag_exists unknown-tag &&
135 test_must_fail git tag -d unknown-tag
136 '
137
138 cat >expect <<EOF
139 myhead
140 mytag
141 EOF
142 test_expect_success \
143 'trying to delete tags without params should succeed and do nothing' '
144 git tag -l > actual && test_cmp expect actual &&
145 git tag -d &&
146 git tag -l > actual && test_cmp expect actual
147 '
148
149 test_expect_success \
150 'deleting two existing tags in one command should succeed' '
151 tag_exists mytag &&
152 tag_exists myhead &&
153 git tag -d mytag myhead &&
154 ! tag_exists mytag &&
155 ! tag_exists myhead
156 '
157
158 test_expect_success \
159 'creating a tag with the name of another deleted one should succeed' '
160 ! tag_exists mytag &&
161 git tag mytag &&
162 tag_exists mytag
163 '
164
165 test_expect_success \
166 'trying to delete two tags, existing and not, should fail in the 2nd' '
167 tag_exists mytag &&
168 ! tag_exists myhead &&
169 test_must_fail git tag -d mytag anothertag &&
170 ! tag_exists mytag &&
171 ! tag_exists myhead
172 '
173
174 test_expect_success 'trying to delete an already deleted tag should fail' \
175 'test_must_fail git tag -d mytag'
176
177 # listing various tags with pattern matching:
178
179 cat >expect <<EOF
180 a1
181 aa1
182 cba
183 t210
184 t211
185 v0.2.1
186 v1.0
187 v1.0.1
188 v1.1.3
189 EOF
190 test_expect_success 'listing all tags should print them ordered' '
191 git tag v1.0.1 &&
192 git tag t211 &&
193 git tag aa1 &&
194 git tag v0.2.1 &&
195 git tag v1.1.3 &&
196 git tag cba &&
197 git tag a1 &&
198 git tag v1.0 &&
199 git tag t210 &&
200 git tag -l > actual &&
201 test_cmp expect actual &&
202 git tag > actual &&
203 test_cmp expect actual
204 '
205
206 cat >expect <<EOF
207 a1
208 aa1
209 cba
210 EOF
211 test_expect_success \
212 'listing tags with substring as pattern must print those matching' '
213 rm *a* &&
214 git tag -l "*a*" > current &&
215 test_cmp expect current
216 '
217
218 cat >expect <<EOF
219 v0.2.1
220 v1.0.1
221 EOF
222 test_expect_success \
223 'listing tags with a suffix as pattern must print those matching' '
224 git tag -l "*.1" > actual &&
225 test_cmp expect actual
226 '
227
228 cat >expect <<EOF
229 t210
230 t211
231 EOF
232 test_expect_success \
233 'listing tags with a prefix as pattern must print those matching' '
234 git tag -l "t21*" > actual &&
235 test_cmp expect actual
236 '
237
238 cat >expect <<EOF
239 a1
240 EOF
241 test_expect_success \
242 'listing tags using a name as pattern must print that one matching' '
243 git tag -l a1 > actual &&
244 test_cmp expect actual
245 '
246
247 cat >expect <<EOF
248 v1.0
249 EOF
250 test_expect_success \
251 'listing tags using a name as pattern must print that one matching' '
252 git tag -l v1.0 > actual &&
253 test_cmp expect actual
254 '
255
256 cat >expect <<EOF
257 v1.0.1
258 v1.1.3
259 EOF
260 test_expect_success \
261 'listing tags with ? in the pattern should print those matching' '
262 git tag -l "v1.?.?" > actual &&
263 test_cmp expect actual
264 '
265
266 >expect
267 test_expect_success \
268 'listing tags using v.* should print nothing because none have v.' '
269 git tag -l "v.*" > actual &&
270 test_cmp expect actual
271 '
272
273 cat >expect <<EOF
274 v0.2.1
275 v1.0
276 v1.0.1
277 v1.1.3
278 EOF
279 test_expect_success \
280 'listing tags using v* should print only those having v' '
281 git tag -l "v*" > actual &&
282 test_cmp expect actual
283 '
284
285 test_expect_success 'tag -l can accept multiple patterns' '
286 git tag -l "v1*" "v0*" >actual &&
287 test_cmp expect actual
288 '
289
290 test_expect_success 'listing tags in column' '
291 COLUMNS=40 git tag -l --column=row >actual &&
292 cat >expected <<\EOF &&
293 a1 aa1 cba t210 t211
294 v0.2.1 v1.0 v1.0.1 v1.1.3
295 EOF
296 test_cmp expected actual
297 '
298
299 test_expect_success 'listing tags in column with column.*' '
300 test_config column.tag row &&
301 test_config column.ui dense &&
302 COLUMNS=40 git tag -l >actual &&
303 cat >expected <<\EOF &&
304 a1 aa1 cba t210 t211
305 v0.2.1 v1.0 v1.0.1 v1.1.3
306 EOF
307 test_cmp expected actual
308 '
309
310 test_expect_success 'listing tag with -n --column should fail' '
311 test_must_fail git tag --column -n
312 '
313
314 test_expect_success 'listing tags -n in column with column.ui ignored' '
315 test_config column.ui "row dense" &&
316 COLUMNS=40 git tag -l -n >actual &&
317 cat >expected <<\EOF &&
318 a1 Foo
319 aa1 Foo
320 cba Foo
321 t210 Foo
322 t211 Foo
323 v0.2.1 Foo
324 v1.0 Foo
325 v1.0.1 Foo
326 v1.1.3 Foo
327 EOF
328 test_cmp expected actual
329 '
330
331 # creating and verifying lightweight tags:
332
333 test_expect_success \
334 'a non-annotated tag created without parameters should point to HEAD' '
335 git tag non-annotated-tag &&
336 test $(git cat-file -t non-annotated-tag) = commit &&
337 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
338 '
339
340 test_expect_success 'trying to verify an unknown tag should fail' \
341 'test_must_fail git tag -v unknown-tag'
342
343 test_expect_success \
344 'trying to verify a non-annotated and non-signed tag should fail' \
345 'test_must_fail git tag -v non-annotated-tag'
346
347 test_expect_success \
348 'trying to verify many non-annotated or unknown tags, should fail' \
349 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
350
351 # creating annotated tags:
352
353 get_tag_msg () {
354 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
355 }
356
357 # run test_tick before committing always gives the time in that timezone
358 get_tag_header () {
359 cat <<EOF
360 object $2
361 type $3
362 tag $1
363 tagger C O Mitter <committer@example.com> $4 -0700
364
365 EOF
366 }
367
368 commit=$(git rev-parse HEAD)
369 time=$test_tick
370
371 get_tag_header annotated-tag $commit commit $time >expect
372 echo "A message" >>expect
373 test_expect_success \
374 'creating an annotated tag with -m message should succeed' '
375 git tag -m "A message" annotated-tag &&
376 get_tag_msg annotated-tag >actual &&
377 test_cmp expect actual
378 '
379
380 cat >msgfile <<EOF
381 Another message
382 in a file.
383 EOF
384 get_tag_header file-annotated-tag $commit commit $time >expect
385 cat msgfile >>expect
386 test_expect_success \
387 'creating an annotated tag with -F messagefile should succeed' '
388 git tag -F msgfile file-annotated-tag &&
389 get_tag_msg file-annotated-tag >actual &&
390 test_cmp expect actual
391 '
392
393 cat >inputmsg <<EOF
394 A message from the
395 standard input
396 EOF
397 get_tag_header stdin-annotated-tag $commit commit $time >expect
398 cat inputmsg >>expect
399 test_expect_success 'creating an annotated tag with -F - should succeed' '
400 git tag -F - stdin-annotated-tag <inputmsg &&
401 get_tag_msg stdin-annotated-tag >actual &&
402 test_cmp expect actual
403 '
404
405 test_expect_success \
406 'trying to create a tag with a non-existing -F file should fail' '
407 ! test -f nonexistingfile &&
408 ! tag_exists notag &&
409 test_must_fail git tag -F nonexistingfile notag &&
410 ! tag_exists notag
411 '
412
413 test_expect_success \
414 'trying to create tags giving both -m or -F options should fail' '
415 echo "message file 1" >msgfile1 &&
416 echo "message file 2" >msgfile2 &&
417 ! tag_exists msgtag &&
418 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
419 ! tag_exists msgtag &&
420 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
421 ! tag_exists msgtag &&
422 test_must_fail git tag -m "message 1" -F msgfile1 \
423 -m "message 2" msgtag &&
424 ! tag_exists msgtag
425 '
426
427 # blank and empty messages:
428
429 get_tag_header empty-annotated-tag $commit commit $time >expect
430 test_expect_success \
431 'creating a tag with an empty -m message should succeed' '
432 git tag -m "" empty-annotated-tag &&
433 get_tag_msg empty-annotated-tag >actual &&
434 test_cmp expect actual
435 '
436
437 >emptyfile
438 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
439 test_expect_success \
440 'creating a tag with an empty -F messagefile should succeed' '
441 git tag -F emptyfile emptyfile-annotated-tag &&
442 get_tag_msg emptyfile-annotated-tag >actual &&
443 test_cmp expect actual
444 '
445
446 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
447 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
448 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
449 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
450 get_tag_header blanks-annotated-tag $commit commit $time >expect
451 cat >>expect <<EOF
452 Leading blank lines
453
454 Repeated blank lines
455
456 Trailing spaces
457
458 Trailing blank lines
459 EOF
460 test_expect_success \
461 'extra blanks in the message for an annotated tag should be removed' '
462 git tag -F blanksfile blanks-annotated-tag &&
463 get_tag_msg blanks-annotated-tag >actual &&
464 test_cmp expect actual
465 '
466
467 get_tag_header blank-annotated-tag $commit commit $time >expect
468 test_expect_success \
469 'creating a tag with blank -m message with spaces should succeed' '
470 git tag -m " " blank-annotated-tag &&
471 get_tag_msg blank-annotated-tag >actual &&
472 test_cmp expect actual
473 '
474
475 echo ' ' >blankfile
476 echo '' >>blankfile
477 echo ' ' >>blankfile
478 get_tag_header blankfile-annotated-tag $commit commit $time >expect
479 test_expect_success \
480 'creating a tag with blank -F messagefile with spaces should succeed' '
481 git tag -F blankfile blankfile-annotated-tag &&
482 get_tag_msg blankfile-annotated-tag >actual &&
483 test_cmp expect actual
484 '
485
486 printf ' ' >blanknonlfile
487 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
488 test_expect_success \
489 'creating a tag with -F file of spaces and no newline should succeed' '
490 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
491 get_tag_msg blanknonlfile-annotated-tag >actual &&
492 test_cmp expect actual
493 '
494
495 # messages with commented lines:
496
497 cat >commentsfile <<EOF
498 # A comment
499
500 ############
501 The message.
502 ############
503 One line.
504
505
506 # commented lines
507 # commented lines
508
509 Another line.
510 # comments
511
512 Last line.
513 EOF
514 get_tag_header comments-annotated-tag $commit commit $time >expect
515 cat >>expect <<EOF
516 The message.
517 One line.
518
519 Another line.
520
521 Last line.
522 EOF
523 test_expect_success \
524 'creating a tag using a -F messagefile with #comments should succeed' '
525 git tag -F commentsfile comments-annotated-tag &&
526 get_tag_msg comments-annotated-tag >actual &&
527 test_cmp expect actual
528 '
529
530 get_tag_header comment-annotated-tag $commit commit $time >expect
531 test_expect_success \
532 'creating a tag with a #comment in the -m message should succeed' '
533 git tag -m "#comment" comment-annotated-tag &&
534 get_tag_msg comment-annotated-tag >actual &&
535 test_cmp expect actual
536 '
537
538 echo '#comment' >commentfile
539 echo '' >>commentfile
540 echo '####' >>commentfile
541 get_tag_header commentfile-annotated-tag $commit commit $time >expect
542 test_expect_success \
543 'creating a tag with #comments in the -F messagefile should succeed' '
544 git tag -F commentfile commentfile-annotated-tag &&
545 get_tag_msg commentfile-annotated-tag >actual &&
546 test_cmp expect actual
547 '
548
549 printf '#comment' >commentnonlfile
550 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
551 test_expect_success \
552 'creating a tag with a file of #comment and no newline should succeed' '
553 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
554 get_tag_msg commentnonlfile-annotated-tag >actual &&
555 test_cmp expect actual
556 '
557
558 # listing messages for annotated non-signed tags:
559
560 test_expect_success \
561 'listing the one-line message of a non-signed tag should succeed' '
562 git tag -m "A msg" tag-one-line &&
563
564 echo "tag-one-line" >expect &&
565 git tag -l | grep "^tag-one-line" >actual &&
566 test_cmp expect actual &&
567 git tag -n0 -l | grep "^tag-one-line" >actual &&
568 test_cmp expect actual &&
569 git tag -n0 -l tag-one-line >actual &&
570 test_cmp expect actual &&
571
572 echo "tag-one-line A msg" >expect &&
573 git tag -n1 -l | grep "^tag-one-line" >actual &&
574 test_cmp expect actual &&
575 git tag -n -l | grep "^tag-one-line" >actual &&
576 test_cmp expect actual &&
577 git tag -n1 -l tag-one-line >actual &&
578 test_cmp expect actual &&
579 git tag -n2 -l tag-one-line >actual &&
580 test_cmp expect actual &&
581 git tag -n999 -l tag-one-line >actual &&
582 test_cmp expect actual
583 '
584
585 test_expect_success \
586 'listing the zero-lines message of a non-signed tag should succeed' '
587 git tag -m "" tag-zero-lines &&
588
589 echo "tag-zero-lines" >expect &&
590 git tag -l | grep "^tag-zero-lines" >actual &&
591 test_cmp expect actual &&
592 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
593 test_cmp expect actual &&
594 git tag -n0 -l tag-zero-lines >actual &&
595 test_cmp expect actual &&
596
597 echo "tag-zero-lines " >expect &&
598 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
599 test_cmp expect actual &&
600 git tag -n -l | grep "^tag-zero-lines" >actual &&
601 test_cmp expect actual &&
602 git tag -n1 -l tag-zero-lines >actual &&
603 test_cmp expect actual &&
604 git tag -n2 -l tag-zero-lines >actual &&
605 test_cmp expect actual &&
606 git tag -n999 -l tag-zero-lines >actual &&
607 test_cmp expect actual
608 '
609
610 echo 'tag line one' >annotagmsg
611 echo 'tag line two' >>annotagmsg
612 echo 'tag line three' >>annotagmsg
613 test_expect_success \
614 'listing many message lines of a non-signed tag should succeed' '
615 git tag -F annotagmsg tag-lines &&
616
617 echo "tag-lines" >expect &&
618 git tag -l | grep "^tag-lines" >actual &&
619 test_cmp expect actual &&
620 git tag -n0 -l | grep "^tag-lines" >actual &&
621 test_cmp expect actual &&
622 git tag -n0 -l tag-lines >actual &&
623 test_cmp expect actual &&
624
625 echo "tag-lines tag line one" >expect &&
626 git tag -n1 -l | grep "^tag-lines" >actual &&
627 test_cmp expect actual &&
628 git tag -n -l | grep "^tag-lines" >actual &&
629 test_cmp expect actual &&
630 git tag -n1 -l tag-lines >actual &&
631 test_cmp expect actual &&
632
633 echo " tag line two" >>expect &&
634 git tag -n2 -l | grep "^ *tag.line" >actual &&
635 test_cmp expect actual &&
636 git tag -n2 -l tag-lines >actual &&
637 test_cmp expect actual &&
638
639 echo " tag line three" >>expect &&
640 git tag -n3 -l | grep "^ *tag.line" >actual &&
641 test_cmp expect actual &&
642 git tag -n3 -l tag-lines >actual &&
643 test_cmp expect actual &&
644 git tag -n4 -l | grep "^ *tag.line" >actual &&
645 test_cmp expect actual &&
646 git tag -n4 -l tag-lines >actual &&
647 test_cmp expect actual &&
648 git tag -n99 -l | grep "^ *tag.line" >actual &&
649 test_cmp expect actual &&
650 git tag -n99 -l tag-lines >actual &&
651 test_cmp expect actual
652 '
653
654 test_expect_success 'annotations for blobs are empty' '
655 blob=$(git hash-object -w --stdin <<-\EOF
656 Blob paragraph 1.
657
658 Blob paragraph 2.
659 EOF
660 ) &&
661 git tag tag-blob $blob &&
662 echo "tag-blob " >expect &&
663 git tag -n1 -l tag-blob >actual &&
664 test_cmp expect actual
665 '
666
667 # trying to verify annotated non-signed tags:
668
669 test_expect_success GPG \
670 'trying to verify an annotated non-signed tag should fail' '
671 tag_exists annotated-tag &&
672 test_must_fail git tag -v annotated-tag
673 '
674
675 test_expect_success GPG \
676 'trying to verify a file-annotated non-signed tag should fail' '
677 tag_exists file-annotated-tag &&
678 test_must_fail git tag -v file-annotated-tag
679 '
680
681 test_expect_success GPG \
682 'trying to verify two annotated non-signed tags should fail' '
683 tag_exists annotated-tag file-annotated-tag &&
684 test_must_fail git tag -v annotated-tag file-annotated-tag
685 '
686
687 # creating and verifying signed tags:
688
689 get_tag_header signed-tag $commit commit $time >expect
690 echo 'A signed tag message' >>expect
691 echo '-----BEGIN PGP SIGNATURE-----' >>expect
692 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
693 git tag -s -m "A signed tag message" signed-tag &&
694 get_tag_msg signed-tag >actual &&
695 test_cmp expect actual
696 '
697
698 get_tag_header u-signed-tag $commit commit $time >expect
699 echo 'Another message' >>expect
700 echo '-----BEGIN PGP SIGNATURE-----' >>expect
701 test_expect_success GPG 'sign with a given key id' '
702
703 git tag -u committer@example.com -m "Another message" u-signed-tag &&
704 get_tag_msg u-signed-tag >actual &&
705 test_cmp expect actual
706
707 '
708
709 test_expect_success GPG 'sign with an unknown id (1)' '
710
711 test_must_fail git tag -u author@example.com \
712 -m "Another message" o-signed-tag
713
714 '
715
716 test_expect_success GPG 'sign with an unknown id (2)' '
717
718 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
719
720 '
721
722 cat >fakeeditor <<'EOF'
723 #!/bin/sh
724 test -n "$1" && exec >"$1"
725 echo A signed tag message
726 echo from a fake editor.
727 EOF
728 chmod +x fakeeditor
729
730 get_tag_header implied-sign $commit commit $time >expect
731 ./fakeeditor >>expect
732 echo '-----BEGIN PGP SIGNATURE-----' >>expect
733 test_expect_success GPG '-u implies signed tag' '
734 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
735 get_tag_msg implied-sign >actual &&
736 test_cmp expect actual
737 '
738
739 cat >sigmsgfile <<EOF
740 Another signed tag
741 message in a file.
742 EOF
743 get_tag_header file-signed-tag $commit commit $time >expect
744 cat sigmsgfile >>expect
745 echo '-----BEGIN PGP SIGNATURE-----' >>expect
746 test_expect_success GPG \
747 'creating a signed tag with -F messagefile should succeed' '
748 git tag -s -F sigmsgfile file-signed-tag &&
749 get_tag_msg file-signed-tag >actual &&
750 test_cmp expect actual
751 '
752
753 cat >siginputmsg <<EOF
754 A signed tag message from
755 the standard input
756 EOF
757 get_tag_header stdin-signed-tag $commit commit $time >expect
758 cat siginputmsg >>expect
759 echo '-----BEGIN PGP SIGNATURE-----' >>expect
760 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
761 git tag -s -F - stdin-signed-tag <siginputmsg &&
762 get_tag_msg stdin-signed-tag >actual &&
763 test_cmp expect actual
764 '
765
766 get_tag_header implied-annotate $commit commit $time >expect
767 ./fakeeditor >>expect
768 echo '-----BEGIN PGP SIGNATURE-----' >>expect
769 test_expect_success GPG '-s implies annotated tag' '
770 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
771 get_tag_msg implied-annotate >actual &&
772 test_cmp expect actual
773 '
774
775 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
776 echo "A message" >>expect
777 echo '-----BEGIN PGP SIGNATURE-----' >>expect
778 test_expect_success GPG \
779 'git tag -s implied if configured with tag.forcesignannotated' \
780 'test_config tag.forcesignannotated true &&
781 git tag -m "A message" forcesignannotated-implied-sign &&
782 get_tag_msg forcesignannotated-implied-sign >actual &&
783 test_cmp expect actual
784 '
785
786 test_expect_success GPG \
787 'lightweight with no message when configured with tag.forcesignannotated' \
788 'test_config tag.forcesignannotated true &&
789 git tag forcesignannotated-lightweight &&
790 tag_exists forcesignannotated-lightweight &&
791 test_must_fail git tag -v forcesignannotated-no-message
792 '
793
794 get_tag_header forcesignannotated-annotate $commit commit $time >expect
795 echo "A message" >>expect
796 test_expect_success GPG \
797 'git tag -a disable configured tag.forcesignannotated' \
798 'test_config tag.forcesignannotated true &&
799 git tag -a -m "A message" forcesignannotated-annotate &&
800 get_tag_msg forcesignannotated-annotate >actual &&
801 test_cmp expect actual &&
802 test_must_fail git tag -v forcesignannotated-annotate
803 '
804
805 get_tag_header forcesignannotated-disabled $commit commit $time >expect
806 echo "A message" >>expect
807 echo '-----BEGIN PGP SIGNATURE-----' >>expect
808 test_expect_success GPG \
809 'git tag --sign enable GPG sign' \
810 'test_config tag.forcesignannotated false &&
811 git tag --sign -m "A message" forcesignannotated-disabled &&
812 get_tag_msg forcesignannotated-disabled >actual &&
813 test_cmp expect actual
814 '
815
816 test_expect_success GPG \
817 'trying to create a signed tag with non-existing -F file should fail' '
818 ! test -f nonexistingfile &&
819 ! tag_exists nosigtag &&
820 test_must_fail git tag -s -F nonexistingfile nosigtag &&
821 ! tag_exists nosigtag
822 '
823
824 test_expect_success GPG 'verifying a signed tag should succeed' \
825 'git tag -v signed-tag'
826
827 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
828 'git tag -v signed-tag file-signed-tag'
829
830 test_expect_success GPG \
831 'verifying many signed and non-signed tags should fail' '
832 test_must_fail git tag -v signed-tag annotated-tag &&
833 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
834 test_must_fail git tag -v annotated-tag \
835 file-signed-tag file-annotated-tag &&
836 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
837 '
838
839 test_expect_success GPG 'verifying a forged tag should fail' '
840 forged=$(git cat-file tag signed-tag |
841 sed -e "s/signed-tag/forged-tag/" |
842 git mktag) &&
843 git tag forged-tag $forged &&
844 test_must_fail git tag -v forged-tag
845 '
846
847 # blank and empty messages for signed tags:
848
849 get_tag_header empty-signed-tag $commit commit $time >expect
850 echo '-----BEGIN PGP SIGNATURE-----' >>expect
851 test_expect_success GPG \
852 'creating a signed tag with an empty -m message should succeed' '
853 git tag -s -m "" empty-signed-tag &&
854 get_tag_msg empty-signed-tag >actual &&
855 test_cmp expect actual &&
856 git tag -v empty-signed-tag
857 '
858
859 >sigemptyfile
860 get_tag_header emptyfile-signed-tag $commit commit $time >expect
861 echo '-----BEGIN PGP SIGNATURE-----' >>expect
862 test_expect_success GPG \
863 'creating a signed tag with an empty -F messagefile should succeed' '
864 git tag -s -F sigemptyfile emptyfile-signed-tag &&
865 get_tag_msg emptyfile-signed-tag >actual &&
866 test_cmp expect actual &&
867 git tag -v emptyfile-signed-tag
868 '
869
870 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
871 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
872 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
873 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
874 get_tag_header blanks-signed-tag $commit commit $time >expect
875 cat >>expect <<EOF
876 Leading blank lines
877
878 Repeated blank lines
879
880 Trailing spaces
881
882 Trailing blank lines
883 EOF
884 echo '-----BEGIN PGP SIGNATURE-----' >>expect
885 test_expect_success GPG \
886 'extra blanks in the message for a signed tag should be removed' '
887 git tag -s -F sigblanksfile blanks-signed-tag &&
888 get_tag_msg blanks-signed-tag >actual &&
889 test_cmp expect actual &&
890 git tag -v blanks-signed-tag
891 '
892
893 get_tag_header blank-signed-tag $commit commit $time >expect
894 echo '-----BEGIN PGP SIGNATURE-----' >>expect
895 test_expect_success GPG \
896 'creating a signed tag with a blank -m message should succeed' '
897 git tag -s -m " " blank-signed-tag &&
898 get_tag_msg blank-signed-tag >actual &&
899 test_cmp expect actual &&
900 git tag -v blank-signed-tag
901 '
902
903 echo ' ' >sigblankfile
904 echo '' >>sigblankfile
905 echo ' ' >>sigblankfile
906 get_tag_header blankfile-signed-tag $commit commit $time >expect
907 echo '-----BEGIN PGP SIGNATURE-----' >>expect
908 test_expect_success GPG \
909 'creating a signed tag with blank -F file with spaces should succeed' '
910 git tag -s -F sigblankfile blankfile-signed-tag &&
911 get_tag_msg blankfile-signed-tag >actual &&
912 test_cmp expect actual &&
913 git tag -v blankfile-signed-tag
914 '
915
916 printf ' ' >sigblanknonlfile
917 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
918 echo '-----BEGIN PGP SIGNATURE-----' >>expect
919 test_expect_success GPG \
920 'creating a signed tag with spaces and no newline should succeed' '
921 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
922 get_tag_msg blanknonlfile-signed-tag >actual &&
923 test_cmp expect actual &&
924 git tag -v signed-tag
925 '
926
927 # messages with commented lines for signed tags:
928
929 cat >sigcommentsfile <<EOF
930 # A comment
931
932 ############
933 The message.
934 ############
935 One line.
936
937
938 # commented lines
939 # commented lines
940
941 Another line.
942 # comments
943
944 Last line.
945 EOF
946 get_tag_header comments-signed-tag $commit commit $time >expect
947 cat >>expect <<EOF
948 The message.
949 One line.
950
951 Another line.
952
953 Last line.
954 EOF
955 echo '-----BEGIN PGP SIGNATURE-----' >>expect
956 test_expect_success GPG \
957 'creating a signed tag with a -F file with #comments should succeed' '
958 git tag -s -F sigcommentsfile comments-signed-tag &&
959 get_tag_msg comments-signed-tag >actual &&
960 test_cmp expect actual &&
961 git tag -v comments-signed-tag
962 '
963
964 get_tag_header comment-signed-tag $commit commit $time >expect
965 echo '-----BEGIN PGP SIGNATURE-----' >>expect
966 test_expect_success GPG \
967 'creating a signed tag with #commented -m message should succeed' '
968 git tag -s -m "#comment" comment-signed-tag &&
969 get_tag_msg comment-signed-tag >actual &&
970 test_cmp expect actual &&
971 git tag -v comment-signed-tag
972 '
973
974 echo '#comment' >sigcommentfile
975 echo '' >>sigcommentfile
976 echo '####' >>sigcommentfile
977 get_tag_header commentfile-signed-tag $commit commit $time >expect
978 echo '-----BEGIN PGP SIGNATURE-----' >>expect
979 test_expect_success GPG \
980 'creating a signed tag with #commented -F messagefile should succeed' '
981 git tag -s -F sigcommentfile commentfile-signed-tag &&
982 get_tag_msg commentfile-signed-tag >actual &&
983 test_cmp expect actual &&
984 git tag -v commentfile-signed-tag
985 '
986
987 printf '#comment' >sigcommentnonlfile
988 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
989 echo '-----BEGIN PGP SIGNATURE-----' >>expect
990 test_expect_success GPG \
991 'creating a signed tag with a #comment and no newline should succeed' '
992 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
993 get_tag_msg commentnonlfile-signed-tag >actual &&
994 test_cmp expect actual &&
995 git tag -v commentnonlfile-signed-tag
996 '
997
998 # listing messages for signed tags:
999
1000 test_expect_success GPG \
1001 'listing the one-line message of a signed tag should succeed' '
1002 git tag -s -m "A message line signed" stag-one-line &&
1003
1004 echo "stag-one-line" >expect &&
1005 git tag -l | grep "^stag-one-line" >actual &&
1006 test_cmp expect actual &&
1007 git tag -n0 -l | grep "^stag-one-line" >actual &&
1008 test_cmp expect actual &&
1009 git tag -n0 -l stag-one-line >actual &&
1010 test_cmp expect actual &&
1011
1012 echo "stag-one-line A message line signed" >expect &&
1013 git tag -n1 -l | grep "^stag-one-line" >actual &&
1014 test_cmp expect actual &&
1015 git tag -n -l | grep "^stag-one-line" >actual &&
1016 test_cmp expect actual &&
1017 git tag -n1 -l stag-one-line >actual &&
1018 test_cmp expect actual &&
1019 git tag -n2 -l stag-one-line >actual &&
1020 test_cmp expect actual &&
1021 git tag -n999 -l stag-one-line >actual &&
1022 test_cmp expect actual
1023 '
1024
1025 test_expect_success GPG \
1026 'listing the zero-lines message of a signed tag should succeed' '
1027 git tag -s -m "" stag-zero-lines &&
1028
1029 echo "stag-zero-lines" >expect &&
1030 git tag -l | grep "^stag-zero-lines" >actual &&
1031 test_cmp expect actual &&
1032 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1033 test_cmp expect actual &&
1034 git tag -n0 -l stag-zero-lines >actual &&
1035 test_cmp expect actual &&
1036
1037 echo "stag-zero-lines " >expect &&
1038 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1039 test_cmp expect actual &&
1040 git tag -n -l | grep "^stag-zero-lines" >actual &&
1041 test_cmp expect actual &&
1042 git tag -n1 -l stag-zero-lines >actual &&
1043 test_cmp expect actual &&
1044 git tag -n2 -l stag-zero-lines >actual &&
1045 test_cmp expect actual &&
1046 git tag -n999 -l stag-zero-lines >actual &&
1047 test_cmp expect actual
1048 '
1049
1050 echo 'stag line one' >sigtagmsg
1051 echo 'stag line two' >>sigtagmsg
1052 echo 'stag line three' >>sigtagmsg
1053 test_expect_success GPG \
1054 'listing many message lines of a signed tag should succeed' '
1055 git tag -s -F sigtagmsg stag-lines &&
1056
1057 echo "stag-lines" >expect &&
1058 git tag -l | grep "^stag-lines" >actual &&
1059 test_cmp expect actual &&
1060 git tag -n0 -l | grep "^stag-lines" >actual &&
1061 test_cmp expect actual &&
1062 git tag -n0 -l stag-lines >actual &&
1063 test_cmp expect actual &&
1064
1065 echo "stag-lines stag line one" >expect &&
1066 git tag -n1 -l | grep "^stag-lines" >actual &&
1067 test_cmp expect actual &&
1068 git tag -n -l | grep "^stag-lines" >actual &&
1069 test_cmp expect actual &&
1070 git tag -n1 -l stag-lines >actual &&
1071 test_cmp expect actual &&
1072
1073 echo " stag line two" >>expect &&
1074 git tag -n2 -l | grep "^ *stag.line" >actual &&
1075 test_cmp expect actual &&
1076 git tag -n2 -l stag-lines >actual &&
1077 test_cmp expect actual &&
1078
1079 echo " stag line three" >>expect &&
1080 git tag -n3 -l | grep "^ *stag.line" >actual &&
1081 test_cmp expect actual &&
1082 git tag -n3 -l stag-lines >actual &&
1083 test_cmp expect actual &&
1084 git tag -n4 -l | grep "^ *stag.line" >actual &&
1085 test_cmp expect actual &&
1086 git tag -n4 -l stag-lines >actual &&
1087 test_cmp expect actual &&
1088 git tag -n99 -l | grep "^ *stag.line" >actual &&
1089 test_cmp expect actual &&
1090 git tag -n99 -l stag-lines >actual &&
1091 test_cmp expect actual
1092 '
1093
1094 # tags pointing to objects different from commits:
1095
1096 tree=$(git rev-parse HEAD^{tree})
1097 blob=$(git rev-parse HEAD:foo)
1098 tag=$(git rev-parse signed-tag 2>/dev/null)
1099
1100 get_tag_header tree-signed-tag $tree tree $time >expect
1101 echo "A message for a tree" >>expect
1102 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1103 test_expect_success GPG \
1104 'creating a signed tag pointing to a tree should succeed' '
1105 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1106 get_tag_msg tree-signed-tag >actual &&
1107 test_cmp expect actual
1108 '
1109
1110 get_tag_header blob-signed-tag $blob blob $time >expect
1111 echo "A message for a blob" >>expect
1112 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1113 test_expect_success GPG \
1114 'creating a signed tag pointing to a blob should succeed' '
1115 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1116 get_tag_msg blob-signed-tag >actual &&
1117 test_cmp expect actual
1118 '
1119
1120 get_tag_header tag-signed-tag $tag tag $time >expect
1121 echo "A message for another tag" >>expect
1122 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1123 test_expect_success GPG \
1124 'creating a signed tag pointing to another tag should succeed' '
1125 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1126 get_tag_msg tag-signed-tag >actual &&
1127 test_cmp expect actual
1128 '
1129
1130 # usage with rfc1991 signatures
1131 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1132 echo "RFC1991 signed tag" >>expect
1133 echo '-----BEGIN PGP MESSAGE-----' >>expect
1134 test_expect_success GPG,RFC1991 \
1135 'creating a signed tag with rfc1991' '
1136 echo "rfc1991" >gpghome/gpg.conf &&
1137 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1138 get_tag_msg rfc1991-signed-tag >actual &&
1139 test_cmp expect actual
1140 '
1141
1142 cat >fakeeditor <<'EOF'
1143 #!/bin/sh
1144 cp "$1" actual
1145 EOF
1146 chmod +x fakeeditor
1147
1148 test_expect_success GPG,RFC1991 \
1149 'reediting a signed tag body omits signature' '
1150 echo "rfc1991" >gpghome/gpg.conf &&
1151 echo "RFC1991 signed tag" >expect &&
1152 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1153 test_cmp expect actual
1154 '
1155
1156 test_expect_success GPG,RFC1991 \
1157 'verifying rfc1991 signature' '
1158 echo "rfc1991" >gpghome/gpg.conf &&
1159 git tag -v rfc1991-signed-tag
1160 '
1161
1162 test_expect_success GPG,RFC1991 \
1163 'list tag with rfc1991 signature' '
1164 echo "rfc1991" >gpghome/gpg.conf &&
1165 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1166 git tag -l -n1 rfc1991-signed-tag >actual &&
1167 test_cmp expect actual &&
1168 git tag -l -n2 rfc1991-signed-tag >actual &&
1169 test_cmp expect actual &&
1170 git tag -l -n999 rfc1991-signed-tag >actual &&
1171 test_cmp expect actual
1172 '
1173
1174 rm -f gpghome/gpg.conf
1175
1176 test_expect_success GPG,RFC1991 \
1177 'verifying rfc1991 signature without --rfc1991' '
1178 git tag -v rfc1991-signed-tag
1179 '
1180
1181 test_expect_success GPG,RFC1991 \
1182 'list tag with rfc1991 signature without --rfc1991' '
1183 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1184 git tag -l -n1 rfc1991-signed-tag >actual &&
1185 test_cmp expect actual &&
1186 git tag -l -n2 rfc1991-signed-tag >actual &&
1187 test_cmp expect actual &&
1188 git tag -l -n999 rfc1991-signed-tag >actual &&
1189 test_cmp expect actual
1190 '
1191
1192 test_expect_success GPG,RFC1991 \
1193 'reediting a signed tag body omits signature' '
1194 echo "RFC1991 signed tag" >expect &&
1195 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1196 test_cmp expect actual
1197 '
1198
1199 # try to sign with bad user.signingkey
1200 test_expect_success GPG \
1201 'git tag -s fails if gpg is misconfigured (bad key)' \
1202 'test_config user.signingkey BobTheMouse &&
1203 test_must_fail git tag -s -m tail tag-gpg-failure'
1204
1205 # try to produce invalid signature
1206 test_expect_success GPG \
1207 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1208 'test_config gpg.program echo &&
1209 test_must_fail git tag -s -m tail tag-gpg-failure'
1210
1211
1212 # try to verify without gpg:
1213
1214 rm -rf gpghome
1215 test_expect_success GPG \
1216 'verify signed tag fails when public key is not present' \
1217 'test_must_fail git tag -v signed-tag'
1218
1219 test_expect_success \
1220 'git tag -a fails if tag annotation is empty' '
1221 ! (GIT_EDITOR=cat git tag -a initial-comment)
1222 '
1223
1224 test_expect_success \
1225 'message in editor has initial comment' '
1226 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1227 '
1228
1229 test_expect_success 'message in editor has initial comment: first line' '
1230 # check the first line --- should be empty
1231 echo >first.expect &&
1232 sed -e 1q <actual >first.actual &&
1233 test_i18ncmp first.expect first.actual
1234 '
1235
1236 test_expect_success \
1237 'message in editor has initial comment: remainder' '
1238 # remove commented lines from the remainder -- should be empty
1239 >rest.expect &&
1240 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1241 test_cmp rest.expect rest.actual
1242 '
1243
1244 get_tag_header reuse $commit commit $time >expect
1245 echo "An annotation to be reused" >> expect
1246 test_expect_success \
1247 'overwriting an annoted tag should use its previous body' '
1248 git tag -a -m "An annotation to be reused" reuse &&
1249 GIT_EDITOR=true git tag -f -a reuse &&
1250 get_tag_msg reuse >actual &&
1251 test_cmp expect actual
1252 '
1253
1254 test_expect_success 'filename for the message is relative to cwd' '
1255 mkdir subdir &&
1256 echo "Tag message in top directory" >msgfile-5 &&
1257 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1258 (
1259 cd subdir &&
1260 git tag -a -F msgfile-5 tag-from-subdir
1261 ) &&
1262 git cat-file tag tag-from-subdir | grep "in sub directory"
1263 '
1264
1265 test_expect_success 'filename for the message is relative to cwd' '
1266 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1267 (
1268 cd subdir &&
1269 git tag -a -F msgfile-6 tag-from-subdir-2
1270 ) &&
1271 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1272 '
1273
1274 # create a few more commits to test --contains
1275
1276 hash1=$(git rev-parse HEAD)
1277
1278 test_expect_success 'creating second commit and tag' '
1279 echo foo-2.0 >foo &&
1280 git add foo &&
1281 git commit -m second &&
1282 git tag v2.0
1283 '
1284
1285 hash2=$(git rev-parse HEAD)
1286
1287 test_expect_success 'creating third commit without tag' '
1288 echo foo-dev >foo &&
1289 git add foo &&
1290 git commit -m third
1291 '
1292
1293 hash3=$(git rev-parse HEAD)
1294
1295 # simple linear checks of --continue
1296
1297 cat > expected <<EOF
1298 v0.2.1
1299 v1.0
1300 v1.0.1
1301 v1.1.3
1302 v2.0
1303 EOF
1304
1305 test_expect_success 'checking that first commit is in all tags (hash)' "
1306 git tag -l --contains $hash1 v* >actual &&
1307 test_cmp expected actual
1308 "
1309
1310 # other ways of specifying the commit
1311 test_expect_success 'checking that first commit is in all tags (tag)' "
1312 git tag -l --contains v1.0 v* >actual &&
1313 test_cmp expected actual
1314 "
1315
1316 test_expect_success 'checking that first commit is in all tags (relative)' "
1317 git tag -l --contains HEAD~2 v* >actual &&
1318 test_cmp expected actual
1319 "
1320
1321 cat > expected <<EOF
1322 v2.0
1323 EOF
1324
1325 test_expect_success 'checking that second commit only has one tag' "
1326 git tag -l --contains $hash2 v* >actual &&
1327 test_cmp expected actual
1328 "
1329
1330
1331 cat > expected <<EOF
1332 EOF
1333
1334 test_expect_success 'checking that third commit has no tags' "
1335 git tag -l --contains $hash3 v* >actual &&
1336 test_cmp expected actual
1337 "
1338
1339 # how about a simple merge?
1340
1341 test_expect_success 'creating simple branch' '
1342 git branch stable v2.0 &&
1343 git checkout stable &&
1344 echo foo-3.0 > foo &&
1345 git commit foo -m fourth &&
1346 git tag v3.0
1347 '
1348
1349 hash4=$(git rev-parse HEAD)
1350
1351 cat > expected <<EOF
1352 v3.0
1353 EOF
1354
1355 test_expect_success 'checking that branch head only has one tag' "
1356 git tag -l --contains $hash4 v* >actual &&
1357 test_cmp expected actual
1358 "
1359
1360 test_expect_success 'merging original branch into this branch' '
1361 git merge --strategy=ours master &&
1362 git tag v4.0
1363 '
1364
1365 cat > expected <<EOF
1366 v4.0
1367 EOF
1368
1369 test_expect_success 'checking that original branch head has one tag now' "
1370 git tag -l --contains $hash3 v* >actual &&
1371 test_cmp expected actual
1372 "
1373
1374 cat > expected <<EOF
1375 v0.2.1
1376 v1.0
1377 v1.0.1
1378 v1.1.3
1379 v2.0
1380 v3.0
1381 v4.0
1382 EOF
1383
1384 test_expect_success 'checking that initial commit is in all tags' "
1385 git tag -l --contains $hash1 v* >actual &&
1386 test_cmp expected actual
1387 "
1388
1389 # mixing modes and options:
1390
1391 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1392 test_must_fail git tag -a &&
1393 test_must_fail git tag -l -v &&
1394 test_must_fail git tag -n 100 &&
1395 test_must_fail git tag -l -m msg &&
1396 test_must_fail git tag -l -F some file &&
1397 test_must_fail git tag -v -s
1398 '
1399
1400 # check points-at
1401
1402 test_expect_success '--points-at cannot be used in non-list mode' '
1403 test_must_fail git tag --points-at=v4.0 foo
1404 '
1405
1406 test_expect_success '--points-at finds lightweight tags' '
1407 echo v4.0 >expect &&
1408 git tag --points-at v4.0 >actual &&
1409 test_cmp expect actual
1410 '
1411
1412 test_expect_success '--points-at finds annotated tags of commits' '
1413 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1414 echo annotated-v4.0 >expect &&
1415 git tag -l --points-at v4.0 "annotated*" >actual &&
1416 test_cmp expect actual
1417 '
1418
1419 test_expect_success '--points-at finds annotated tags of tags' '
1420 git tag -m "describing the v4.0 tag object" \
1421 annotated-again-v4.0 annotated-v4.0 &&
1422 cat >expect <<-\EOF &&
1423 annotated-again-v4.0
1424 annotated-v4.0
1425 EOF
1426 git tag --points-at=annotated-v4.0 >actual &&
1427 test_cmp expect actual
1428 '
1429
1430 test_expect_success 'multiple --points-at are OR-ed together' '
1431 cat >expect <<-\EOF &&
1432 v2.0
1433 v3.0
1434 EOF
1435 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1436 test_cmp expect actual
1437 '
1438
1439 test_expect_success 'lexical sort' '
1440 git tag foo1.3 &&
1441 git tag foo1.6 &&
1442 git tag foo1.10 &&
1443 git tag -l --sort=refname "foo*" >actual &&
1444 cat >expect <<-\EOF &&
1445 foo1.10
1446 foo1.3
1447 foo1.6
1448 EOF
1449 test_cmp expect actual
1450 '
1451
1452 test_expect_success 'version sort' '
1453 git tag -l --sort=version:refname "foo*" >actual &&
1454 cat >expect <<-\EOF &&
1455 foo1.3
1456 foo1.6
1457 foo1.10
1458 EOF
1459 test_cmp expect actual
1460 '
1461
1462 test_expect_success 'reverse version sort' '
1463 git tag -l --sort=-version:refname "foo*" >actual &&
1464 cat >expect <<-\EOF &&
1465 foo1.10
1466 foo1.6
1467 foo1.3
1468 EOF
1469 test_cmp expect actual
1470 '
1471
1472 test_expect_success 'reverse lexical sort' '
1473 git tag -l --sort=-refname "foo*" >actual &&
1474 cat >expect <<-\EOF &&
1475 foo1.6
1476 foo1.3
1477 foo1.10
1478 EOF
1479 test_cmp expect actual
1480 '
1481
1482 test_expect_success 'configured lexical sort' '
1483 test_config tag.sort "v:refname" &&
1484 git tag -l "foo*" >actual &&
1485 cat >expect <<-\EOF &&
1486 foo1.3
1487 foo1.6
1488 foo1.10
1489 EOF
1490 test_cmp expect actual
1491 '
1492
1493 test_expect_success 'option override configured sort' '
1494 test_config tag.sort "v:refname" &&
1495 git tag -l --sort=-refname "foo*" >actual &&
1496 cat >expect <<-\EOF &&
1497 foo1.6
1498 foo1.3
1499 foo1.10
1500 EOF
1501 test_cmp expect actual
1502 '
1503
1504 test_expect_success 'invalid sort parameter on command line' '
1505 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1506 '
1507
1508 test_expect_success 'invalid sort parameter in configuratoin' '
1509 test_config tag.sort "v:notvalid" &&
1510 test_must_fail git tag -l "foo*"
1511 '
1512
1513 test_expect_success 'version sort with prerelease reordering' '
1514 test_config versionsort.prereleaseSuffix -rc &&
1515 git tag foo1.6-rc1 &&
1516 git tag foo1.6-rc2 &&
1517 git tag -l --sort=version:refname "foo*" >actual &&
1518 cat >expect <<-\EOF &&
1519 foo1.3
1520 foo1.6-rc1
1521 foo1.6-rc2
1522 foo1.6
1523 foo1.10
1524 EOF
1525 test_cmp expect actual
1526 '
1527
1528 test_expect_success 'reverse version sort with prerelease reordering' '
1529 test_config versionsort.prereleaseSuffix -rc &&
1530 git tag -l --sort=-version:refname "foo*" >actual &&
1531 cat >expect <<-\EOF &&
1532 foo1.10
1533 foo1.6
1534 foo1.6-rc2
1535 foo1.6-rc1
1536 foo1.3
1537 EOF
1538 test_cmp expect actual
1539 '
1540
1541 test_expect_success 'version sort with prerelease reordering and common leading character' '
1542 test_config versionsort.prereleaseSuffix -before &&
1543 git tag foo1.7-before1 &&
1544 git tag foo1.7 &&
1545 git tag foo1.7-after1 &&
1546 git tag -l --sort=version:refname "foo1.7*" >actual &&
1547 cat >expect <<-\EOF &&
1548 foo1.7-before1
1549 foo1.7
1550 foo1.7-after1
1551 EOF
1552 test_cmp expect actual
1553 '
1554
1555 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1556 test_config versionsort.prereleaseSuffix -before &&
1557 git config --add versionsort.prereleaseSuffix -after &&
1558 git tag -l --sort=version:refname "foo1.7*" >actual &&
1559 cat >expect <<-\EOF &&
1560 foo1.7-before1
1561 foo1.7-after1
1562 foo1.7
1563 EOF
1564 test_cmp expect actual
1565 '
1566
1567 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1568 test_config versionsort.prereleaseSuffix -bar &&
1569 git config --add versionsort.prereleaseSuffix -foo-baz &&
1570 git config --add versionsort.prereleaseSuffix -foo-bar &&
1571 git tag foo1.8-foo-bar &&
1572 git tag foo1.8-foo-baz &&
1573 git tag foo1.8 &&
1574 git tag -l --sort=version:refname "foo1.8*" >actual &&
1575 cat >expect <<-\EOF &&
1576 foo1.8-foo-baz
1577 foo1.8-foo-bar
1578 foo1.8
1579 EOF
1580 test_cmp expect actual
1581 '
1582
1583 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1584 test_config versionsort.prereleaseSuffix -pre &&
1585 git config --add versionsort.prereleaseSuffix -prerelease &&
1586 git tag foo1.9-pre1 &&
1587 git tag foo1.9-pre2 &&
1588 git tag foo1.9-prerelease1 &&
1589 git tag -l --sort=version:refname "foo1.9*" >actual &&
1590 cat >expect <<-\EOF &&
1591 foo1.9-pre1
1592 foo1.9-pre2
1593 foo1.9-prerelease1
1594 EOF
1595 test_cmp expect actual
1596 '
1597
1598 test_expect_success 'version sort with general suffix reordering' '
1599 test_config versionsort.suffix -alpha &&
1600 git config --add versionsort.suffix -beta &&
1601 git config --add versionsort.suffix "" &&
1602 git config --add versionsort.suffix -gamma &&
1603 git config --add versionsort.suffix -delta &&
1604 git tag foo1.10-alpha &&
1605 git tag foo1.10-beta &&
1606 git tag foo1.10-gamma &&
1607 git tag foo1.10-delta &&
1608 git tag foo1.10-unlisted-suffix &&
1609 git tag -l --sort=version:refname "foo1.10*" >actual &&
1610 cat >expect <<-\EOF &&
1611 foo1.10-alpha
1612 foo1.10-beta
1613 foo1.10
1614 foo1.10-unlisted-suffix
1615 foo1.10-gamma
1616 foo1.10-delta
1617 EOF
1618 test_cmp expect actual
1619 '
1620
1621 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1622 test_config versionsort.suffix -before &&
1623 test_config versionsort.prereleaseSuffix -after &&
1624 git tag -l --sort=version:refname "foo1.7*" >actual &&
1625 cat >expect <<-\EOF &&
1626 foo1.7-before1
1627 foo1.7
1628 foo1.7-after1
1629 EOF
1630 test_cmp expect actual
1631 '
1632
1633 test_expect_success 'version sort with very long prerelease suffix' '
1634 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1635 git tag -l --sort=version:refname
1636 '
1637
1638 run_with_limited_stack () {
1639 (ulimit -s 128 && "$@")
1640 }
1641
1642 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1643
1644 # we require ulimit, this excludes Windows
1645 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1646 >expect &&
1647 i=1 &&
1648 while test $i -lt 8000
1649 do
1650 echo "commit refs/heads/master
1651 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1652 data <<EOF
1653 commit #$i
1654 EOF"
1655 test $i = 1 && echo "from refs/heads/master^0"
1656 i=$(($i + 1))
1657 done | git fast-import &&
1658 git checkout master &&
1659 git tag far-far-away HEAD^ &&
1660 run_with_limited_stack git tag --contains HEAD >actual &&
1661 test_cmp expect actual
1662 '
1663
1664 test_expect_success '--format should list tags as per format given' '
1665 cat >expect <<-\EOF &&
1666 refname : refs/tags/v1.0
1667 refname : refs/tags/v1.0.1
1668 refname : refs/tags/v1.1.3
1669 EOF
1670 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1671 test_cmp expect actual
1672 '
1673
1674 test_expect_success 'setup --merged test tags' '
1675 git tag mergetest-1 HEAD~2 &&
1676 git tag mergetest-2 HEAD~1 &&
1677 git tag mergetest-3 HEAD
1678 '
1679
1680 test_expect_success '--merged cannot be used in non-list mode' '
1681 test_must_fail git tag --merged=mergetest-2 foo
1682 '
1683
1684 test_expect_success '--merged shows merged tags' '
1685 cat >expect <<-\EOF &&
1686 mergetest-1
1687 mergetest-2
1688 EOF
1689 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1690 test_cmp expect actual
1691 '
1692
1693 test_expect_success '--no-merged show unmerged tags' '
1694 cat >expect <<-\EOF &&
1695 mergetest-3
1696 EOF
1697 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1698 test_cmp expect actual
1699 '
1700
1701 test_expect_success 'ambiguous branch/tags not marked' '
1702 git tag ambiguous &&
1703 git branch ambiguous &&
1704 echo ambiguous >expect &&
1705 git tag -l ambiguous >actual &&
1706 test_cmp expect actual
1707 '
1708
1709 test_done