3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
11 . "$TEST_DIRECTORY"/lib-gpg.sh
13 # creating and listing lightweight tags:
16 git show-ref --quiet --verify refs/tags/"$1"
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' '
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
30 test_expect_success 'looking for a tag in an empty tree should fail' \
31 '! (tag_exists mytag)'
33 test_expect_success 'creating a tag in an empty tree should fail' '
34 test_must_fail git tag mynotag &&
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
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
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' '
57 test_expect_success 'listing all tags if one exists should succeed' '
62 test_expect_success 'listing all tags if one exists should output that tag' '
63 test `git tag -l` = mytag &&
64 test `git tag` = mytag
69 test_expect_success 'listing a tag using a matching pattern should succeed' \
73 'listing a tag using a matching pattern should output that tag' \
74 'test `git tag -l mytag` = mytag'
76 # todo: git tag -l now returns always zero, when fixed, change this test
78 'listing tags using a non-matching pattern should suceed' \
82 'listing tags using a non-matching pattern should output nothing' \
83 'test `git tag -l xxx | wc -l` -eq 0'
85 # special cases for creating tags:
88 'trying to create a tag with the name of one existing should fail' \
89 'test_must_fail git tag mytag'
92 'trying to create a tag with a non-valid name should fail' '
93 test `git tag -l | wc -l` -eq 1 &&
94 test_must_fail git tag "" &&
95 test_must_fail git tag .othertag &&
96 test_must_fail git tag "other tag" &&
97 test_must_fail git tag "othertag^" &&
98 test_must_fail git tag "other~tag" &&
99 test `git tag -l | wc -l` -eq 1
102 test_expect_success 'creating a tag using HEAD directly should succeed' '
103 git tag myhead HEAD &&
109 test_expect_success 'trying to delete an unknown tag should fail' '
110 ! tag_exists unknown-tag &&
111 test_must_fail git tag -d unknown-tag
118 test_expect_success \
119 'trying to delete tags without params should succeed and do nothing' '
120 git tag -l > actual && test_cmp expect actual &&
122 git tag -l > actual && test_cmp expect actual
125 test_expect_success \
126 'deleting two existing tags in one command should succeed' '
129 git tag -d mytag myhead &&
130 ! tag_exists mytag &&
134 test_expect_success \
135 'creating a tag with the name of another deleted one should succeed' '
136 ! tag_exists mytag &&
141 test_expect_success \
142 'trying to delete two tags, existing and not, should fail in the 2nd' '
144 ! tag_exists myhead &&
145 test_must_fail git tag -d mytag anothertag &&
146 ! tag_exists mytag &&
150 test_expect_success 'trying to delete an already deleted tag should fail' \
151 'test_must_fail git tag -d mytag'
153 # listing various tags with pattern matching:
166 test_expect_success 'listing all tags should print them ordered' '
176 git tag -l > actual &&
177 test_cmp expect actual &&
179 test_cmp expect actual
187 test_expect_success \
188 'listing tags with substring as pattern must print those matching' '
190 git tag -l "*a*" > current &&
191 test_cmp expect current
198 test_expect_success \
199 'listing tags with a suffix as pattern must print those matching' '
200 git tag -l "*.1" > actual &&
201 test_cmp expect actual
208 test_expect_success \
209 'listing tags with a prefix as pattern must print those matching' '
210 git tag -l "t21*" > actual &&
211 test_cmp expect actual
217 test_expect_success \
218 'listing tags using a name as pattern must print that one matching' '
219 git tag -l a1 > actual &&
220 test_cmp expect actual
226 test_expect_success \
227 'listing tags using a name as pattern must print that one matching' '
228 git tag -l v1.0 > actual &&
229 test_cmp expect actual
236 test_expect_success \
237 'listing tags with ? in the pattern should print those matching' '
238 git tag -l "v1.?.?" > actual &&
239 test_cmp expect actual
243 test_expect_success \
244 'listing tags using v.* should print nothing because none have v.' '
245 git tag -l "v.*" > actual &&
246 test_cmp expect actual
255 test_expect_success \
256 'listing tags using v* should print only those having v' '
257 git tag -l "v*" > actual &&
258 test_cmp expect actual
261 test_expect_success 'tag -l can accept multiple patterns' '
262 git tag -l "v1*" "v0*" >actual &&
263 test_cmp expect actual
266 # creating and verifying lightweight tags:
268 test_expect_success \
269 'a non-annotated tag created without parameters should point to HEAD' '
270 git tag non-annotated-tag &&
271 test $(git cat-file -t non-annotated-tag) = commit &&
272 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
275 test_expect_success 'trying to verify an unknown tag should fail' \
276 'test_must_fail git tag -v unknown-tag'
278 test_expect_success \
279 'trying to verify a non-annotated and non-signed tag should fail' \
280 'test_must_fail git tag -v non-annotated-tag'
282 test_expect_success \
283 'trying to verify many non-annotated or unknown tags, should fail' \
284 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
286 # creating annotated tags:
289 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
292 # run test_tick before committing always gives the time in that timezone
298 tagger C O Mitter <committer@example.com> $4 -0700
303 commit=$(git rev-parse HEAD)
306 get_tag_header annotated-tag $commit commit $time >expect
307 echo "A message" >>expect
308 test_expect_success \
309 'creating an annotated tag with -m message should succeed' '
310 git tag -m "A message" annotated-tag &&
311 get_tag_msg annotated-tag >actual &&
312 test_cmp expect actual
319 get_tag_header file-annotated-tag $commit commit $time >expect
321 test_expect_success \
322 'creating an annotated tag with -F messagefile should succeed' '
323 git tag -F msgfile file-annotated-tag &&
324 get_tag_msg file-annotated-tag >actual &&
325 test_cmp expect actual
332 get_tag_header stdin-annotated-tag $commit commit $time >expect
333 cat inputmsg >>expect
334 test_expect_success 'creating an annotated tag with -F - should succeed' '
335 git tag -F - stdin-annotated-tag <inputmsg &&
336 get_tag_msg stdin-annotated-tag >actual &&
337 test_cmp expect actual
340 test_expect_success \
341 'trying to create a tag with a non-existing -F file should fail' '
342 ! test -f nonexistingfile &&
343 ! tag_exists notag &&
344 test_must_fail git tag -F nonexistingfile notag &&
348 test_expect_success \
349 'trying to create tags giving both -m or -F options should fail' '
350 echo "message file 1" >msgfile1 &&
351 echo "message file 2" >msgfile2 &&
352 ! tag_exists msgtag &&
353 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
354 ! tag_exists msgtag &&
355 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
356 ! tag_exists msgtag &&
357 test_must_fail git tag -m "message 1" -F msgfile1 \
358 -m "message 2" msgtag &&
362 # blank and empty messages:
364 get_tag_header empty-annotated-tag $commit commit $time >expect
365 test_expect_success \
366 'creating a tag with an empty -m message should succeed' '
367 git tag -m "" empty-annotated-tag &&
368 get_tag_msg empty-annotated-tag >actual &&
369 test_cmp expect actual
373 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
374 test_expect_success \
375 'creating a tag with an empty -F messagefile should succeed' '
376 git tag -F emptyfile emptyfile-annotated-tag &&
377 get_tag_msg emptyfile-annotated-tag >actual &&
378 test_cmp expect actual
381 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
382 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
383 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
384 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
385 get_tag_header blanks-annotated-tag $commit commit $time >expect
395 test_expect_success \
396 'extra blanks in the message for an annotated tag should be removed' '
397 git tag -F blanksfile blanks-annotated-tag &&
398 get_tag_msg blanks-annotated-tag >actual &&
399 test_cmp expect actual
402 get_tag_header blank-annotated-tag $commit commit $time >expect
403 test_expect_success \
404 'creating a tag with blank -m message with spaces should succeed' '
405 git tag -m " " blank-annotated-tag &&
406 get_tag_msg blank-annotated-tag >actual &&
407 test_cmp expect actual
413 get_tag_header blankfile-annotated-tag $commit commit $time >expect
414 test_expect_success \
415 'creating a tag with blank -F messagefile with spaces should succeed' '
416 git tag -F blankfile blankfile-annotated-tag &&
417 get_tag_msg blankfile-annotated-tag >actual &&
418 test_cmp expect actual
421 printf ' ' >blanknonlfile
422 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
423 test_expect_success \
424 'creating a tag with -F file of spaces and no newline should succeed' '
425 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
426 get_tag_msg blanknonlfile-annotated-tag >actual &&
427 test_cmp expect actual
430 # messages with commented lines:
432 cat >commentsfile <<EOF
449 get_tag_header comments-annotated-tag $commit commit $time >expect
458 test_expect_success \
459 'creating a tag using a -F messagefile with #comments should succeed' '
460 git tag -F commentsfile comments-annotated-tag &&
461 get_tag_msg comments-annotated-tag >actual &&
462 test_cmp expect actual
465 get_tag_header comment-annotated-tag $commit commit $time >expect
466 test_expect_success \
467 'creating a tag with a #comment in the -m message should succeed' '
468 git tag -m "#comment" comment-annotated-tag &&
469 get_tag_msg comment-annotated-tag >actual &&
470 test_cmp expect actual
473 echo '#comment' >commentfile
474 echo '' >>commentfile
475 echo '####' >>commentfile
476 get_tag_header commentfile-annotated-tag $commit commit $time >expect
477 test_expect_success \
478 'creating a tag with #comments in the -F messagefile should succeed' '
479 git tag -F commentfile commentfile-annotated-tag &&
480 get_tag_msg commentfile-annotated-tag >actual &&
481 test_cmp expect actual
484 printf '#comment' >commentnonlfile
485 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
486 test_expect_success \
487 'creating a tag with a file of #comment and no newline should succeed' '
488 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
489 get_tag_msg commentnonlfile-annotated-tag >actual &&
490 test_cmp expect actual
493 # listing messages for annotated non-signed tags:
495 test_expect_success \
496 'listing the one-line message of a non-signed tag should succeed' '
497 git tag -m "A msg" tag-one-line &&
499 echo "tag-one-line" >expect &&
500 git tag -l | grep "^tag-one-line" >actual &&
501 test_cmp expect actual &&
502 git tag -n0 -l | grep "^tag-one-line" >actual &&
503 test_cmp expect actual &&
504 git tag -n0 -l tag-one-line >actual &&
505 test_cmp expect actual &&
507 echo "tag-one-line A msg" >expect &&
508 git tag -n1 -l | grep "^tag-one-line" >actual &&
509 test_cmp expect actual &&
510 git tag -n -l | grep "^tag-one-line" >actual &&
511 test_cmp expect actual &&
512 git tag -n1 -l tag-one-line >actual &&
513 test_cmp expect actual &&
514 git tag -n2 -l tag-one-line >actual &&
515 test_cmp expect actual &&
516 git tag -n999 -l tag-one-line >actual &&
517 test_cmp expect actual
520 test_expect_success \
521 'listing the zero-lines message of a non-signed tag should succeed' '
522 git tag -m "" tag-zero-lines &&
524 echo "tag-zero-lines" >expect &&
525 git tag -l | grep "^tag-zero-lines" >actual &&
526 test_cmp expect actual &&
527 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
528 test_cmp expect actual &&
529 git tag -n0 -l tag-zero-lines >actual &&
530 test_cmp expect actual &&
532 echo "tag-zero-lines " >expect &&
533 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
534 test_cmp expect actual &&
535 git tag -n -l | grep "^tag-zero-lines" >actual &&
536 test_cmp expect actual &&
537 git tag -n1 -l tag-zero-lines >actual &&
538 test_cmp expect actual &&
539 git tag -n2 -l tag-zero-lines >actual &&
540 test_cmp expect actual &&
541 git tag -n999 -l tag-zero-lines >actual &&
542 test_cmp expect actual
545 echo 'tag line one' >annotagmsg
546 echo 'tag line two' >>annotagmsg
547 echo 'tag line three' >>annotagmsg
548 test_expect_success \
549 'listing many message lines of a non-signed tag should succeed' '
550 git tag -F annotagmsg tag-lines &&
552 echo "tag-lines" >expect &&
553 git tag -l | grep "^tag-lines" >actual &&
554 test_cmp expect actual &&
555 git tag -n0 -l | grep "^tag-lines" >actual &&
556 test_cmp expect actual &&
557 git tag -n0 -l tag-lines >actual &&
558 test_cmp expect actual &&
560 echo "tag-lines tag line one" >expect &&
561 git tag -n1 -l | grep "^tag-lines" >actual &&
562 test_cmp expect actual &&
563 git tag -n -l | grep "^tag-lines" >actual &&
564 test_cmp expect actual &&
565 git tag -n1 -l tag-lines >actual &&
566 test_cmp expect actual &&
568 echo " tag line two" >>expect &&
569 git tag -n2 -l | grep "^ *tag.line" >actual &&
570 test_cmp expect actual &&
571 git tag -n2 -l tag-lines >actual &&
572 test_cmp expect actual &&
574 echo " tag line three" >>expect &&
575 git tag -n3 -l | grep "^ *tag.line" >actual &&
576 test_cmp expect actual &&
577 git tag -n3 -l tag-lines >actual &&
578 test_cmp expect actual &&
579 git tag -n4 -l | grep "^ *tag.line" >actual &&
580 test_cmp expect actual &&
581 git tag -n4 -l tag-lines >actual &&
582 test_cmp expect actual &&
583 git tag -n99 -l | grep "^ *tag.line" >actual &&
584 test_cmp expect actual &&
585 git tag -n99 -l tag-lines >actual &&
586 test_cmp expect actual
589 test_expect_success 'annotations for blobs are empty' '
590 blob=$(git hash-object -w --stdin <<-\EOF
596 git tag tag-blob $blob &&
597 echo "tag-blob " >expect &&
598 git tag -n1 -l tag-blob >actual &&
599 test_cmp expect actual
602 # trying to verify annotated non-signed tags:
604 test_expect_success GPG \
605 'trying to verify an annotated non-signed tag should fail' '
606 tag_exists annotated-tag &&
607 test_must_fail git tag -v annotated-tag
610 test_expect_success GPG \
611 'trying to verify a file-annotated non-signed tag should fail' '
612 tag_exists file-annotated-tag &&
613 test_must_fail git tag -v file-annotated-tag
616 test_expect_success GPG \
617 'trying to verify two annotated non-signed tags should fail' '
618 tag_exists annotated-tag file-annotated-tag &&
619 test_must_fail git tag -v annotated-tag file-annotated-tag
622 # creating and verifying signed tags:
624 get_tag_header signed-tag $commit commit $time >expect
625 echo 'A signed tag message' >>expect
626 echo '-----BEGIN PGP SIGNATURE-----' >>expect
627 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
628 git tag -s -m "A signed tag message" signed-tag &&
629 get_tag_msg signed-tag >actual &&
630 test_cmp expect actual
633 get_tag_header u-signed-tag $commit commit $time >expect
634 echo 'Another message' >>expect
635 echo '-----BEGIN PGP SIGNATURE-----' >>expect
636 test_expect_success GPG 'sign with a given key id' '
638 git tag -u committer@example.com -m "Another message" u-signed-tag &&
639 get_tag_msg u-signed-tag >actual &&
640 test_cmp expect actual
644 test_expect_success GPG 'sign with an unknown id (1)' '
646 test_must_fail git tag -u author@example.com \
647 -m "Another message" o-signed-tag
651 test_expect_success GPG 'sign with an unknown id (2)' '
653 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
657 cat >fakeeditor <<'EOF'
659 test -n "$1" && exec >"$1"
660 echo A signed tag message
661 echo from a fake editor.
665 get_tag_header implied-sign $commit commit $time >expect
666 ./fakeeditor >>expect
667 echo '-----BEGIN PGP SIGNATURE-----' >>expect
668 test_expect_success GPG '-u implies signed tag' '
669 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
670 get_tag_msg implied-sign >actual &&
671 test_cmp expect actual
674 cat >sigmsgfile <<EOF
678 get_tag_header file-signed-tag $commit commit $time >expect
679 cat sigmsgfile >>expect
680 echo '-----BEGIN PGP SIGNATURE-----' >>expect
681 test_expect_success GPG \
682 'creating a signed tag with -F messagefile should succeed' '
683 git tag -s -F sigmsgfile file-signed-tag &&
684 get_tag_msg file-signed-tag >actual &&
685 test_cmp expect actual
688 cat >siginputmsg <<EOF
689 A signed tag message from
692 get_tag_header stdin-signed-tag $commit commit $time >expect
693 cat siginputmsg >>expect
694 echo '-----BEGIN PGP SIGNATURE-----' >>expect
695 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
696 git tag -s -F - stdin-signed-tag <siginputmsg &&
697 get_tag_msg stdin-signed-tag >actual &&
698 test_cmp expect actual
701 get_tag_header implied-annotate $commit commit $time >expect
702 ./fakeeditor >>expect
703 echo '-----BEGIN PGP SIGNATURE-----' >>expect
704 test_expect_success GPG '-s implies annotated tag' '
705 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
706 get_tag_msg implied-annotate >actual &&
707 test_cmp expect actual
710 test_expect_success GPG \
711 'trying to create a signed tag with non-existing -F file should fail' '
712 ! test -f nonexistingfile &&
713 ! tag_exists nosigtag &&
714 test_must_fail git tag -s -F nonexistingfile nosigtag &&
715 ! tag_exists nosigtag
718 test_expect_success GPG 'verifying a signed tag should succeed' \
719 'git tag -v signed-tag'
721 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
722 'git tag -v signed-tag file-signed-tag'
724 test_expect_success GPG \
725 'verifying many signed and non-signed tags should fail' '
726 test_must_fail git tag -v signed-tag annotated-tag &&
727 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
728 test_must_fail git tag -v annotated-tag \
729 file-signed-tag file-annotated-tag &&
730 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
733 test_expect_success GPG 'verifying a forged tag should fail' '
734 forged=$(git cat-file tag signed-tag |
735 sed -e "s/signed-tag/forged-tag/" |
737 git tag forged-tag $forged &&
738 test_must_fail git tag -v forged-tag
741 # blank and empty messages for signed tags:
743 get_tag_header empty-signed-tag $commit commit $time >expect
744 echo '-----BEGIN PGP SIGNATURE-----' >>expect
745 test_expect_success GPG \
746 'creating a signed tag with an empty -m message should succeed' '
747 git tag -s -m "" empty-signed-tag &&
748 get_tag_msg empty-signed-tag >actual &&
749 test_cmp expect actual &&
750 git tag -v empty-signed-tag
754 get_tag_header emptyfile-signed-tag $commit commit $time >expect
755 echo '-----BEGIN PGP SIGNATURE-----' >>expect
756 test_expect_success GPG \
757 'creating a signed tag with an empty -F messagefile should succeed' '
758 git tag -s -F sigemptyfile emptyfile-signed-tag &&
759 get_tag_msg emptyfile-signed-tag >actual &&
760 test_cmp expect actual &&
761 git tag -v emptyfile-signed-tag
764 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
765 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
766 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
767 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
768 get_tag_header blanks-signed-tag $commit commit $time >expect
778 echo '-----BEGIN PGP SIGNATURE-----' >>expect
779 test_expect_success GPG \
780 'extra blanks in the message for a signed tag should be removed' '
781 git tag -s -F sigblanksfile blanks-signed-tag &&
782 get_tag_msg blanks-signed-tag >actual &&
783 test_cmp expect actual &&
784 git tag -v blanks-signed-tag
787 get_tag_header blank-signed-tag $commit commit $time >expect
788 echo '-----BEGIN PGP SIGNATURE-----' >>expect
789 test_expect_success GPG \
790 'creating a signed tag with a blank -m message should succeed' '
791 git tag -s -m " " blank-signed-tag &&
792 get_tag_msg blank-signed-tag >actual &&
793 test_cmp expect actual &&
794 git tag -v blank-signed-tag
797 echo ' ' >sigblankfile
798 echo '' >>sigblankfile
799 echo ' ' >>sigblankfile
800 get_tag_header blankfile-signed-tag $commit commit $time >expect
801 echo '-----BEGIN PGP SIGNATURE-----' >>expect
802 test_expect_success GPG \
803 'creating a signed tag with blank -F file with spaces should succeed' '
804 git tag -s -F sigblankfile blankfile-signed-tag &&
805 get_tag_msg blankfile-signed-tag >actual &&
806 test_cmp expect actual &&
807 git tag -v blankfile-signed-tag
810 printf ' ' >sigblanknonlfile
811 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
812 echo '-----BEGIN PGP SIGNATURE-----' >>expect
813 test_expect_success GPG \
814 'creating a signed tag with spaces and no newline should succeed' '
815 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
816 get_tag_msg blanknonlfile-signed-tag >actual &&
817 test_cmp expect actual &&
818 git tag -v signed-tag
821 # messages with commented lines for signed tags:
823 cat >sigcommentsfile <<EOF
840 get_tag_header comments-signed-tag $commit commit $time >expect
849 echo '-----BEGIN PGP SIGNATURE-----' >>expect
850 test_expect_success GPG \
851 'creating a signed tag with a -F file with #comments should succeed' '
852 git tag -s -F sigcommentsfile comments-signed-tag &&
853 get_tag_msg comments-signed-tag >actual &&
854 test_cmp expect actual &&
855 git tag -v comments-signed-tag
858 get_tag_header comment-signed-tag $commit commit $time >expect
859 echo '-----BEGIN PGP SIGNATURE-----' >>expect
860 test_expect_success GPG \
861 'creating a signed tag with #commented -m message should succeed' '
862 git tag -s -m "#comment" comment-signed-tag &&
863 get_tag_msg comment-signed-tag >actual &&
864 test_cmp expect actual &&
865 git tag -v comment-signed-tag
868 echo '#comment' >sigcommentfile
869 echo '' >>sigcommentfile
870 echo '####' >>sigcommentfile
871 get_tag_header commentfile-signed-tag $commit commit $time >expect
872 echo '-----BEGIN PGP SIGNATURE-----' >>expect
873 test_expect_success GPG \
874 'creating a signed tag with #commented -F messagefile should succeed' '
875 git tag -s -F sigcommentfile commentfile-signed-tag &&
876 get_tag_msg commentfile-signed-tag >actual &&
877 test_cmp expect actual &&
878 git tag -v commentfile-signed-tag
881 printf '#comment' >sigcommentnonlfile
882 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
883 echo '-----BEGIN PGP SIGNATURE-----' >>expect
884 test_expect_success GPG \
885 'creating a signed tag with a #comment and no newline should succeed' '
886 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
887 get_tag_msg commentnonlfile-signed-tag >actual &&
888 test_cmp expect actual &&
889 git tag -v commentnonlfile-signed-tag
892 # listing messages for signed tags:
894 test_expect_success GPG \
895 'listing the one-line message of a signed tag should succeed' '
896 git tag -s -m "A message line signed" stag-one-line &&
898 echo "stag-one-line" >expect &&
899 git tag -l | grep "^stag-one-line" >actual &&
900 test_cmp expect actual &&
901 git tag -n0 -l | grep "^stag-one-line" >actual &&
902 test_cmp expect actual &&
903 git tag -n0 -l stag-one-line >actual &&
904 test_cmp expect actual &&
906 echo "stag-one-line A message line signed" >expect &&
907 git tag -n1 -l | grep "^stag-one-line" >actual &&
908 test_cmp expect actual &&
909 git tag -n -l | grep "^stag-one-line" >actual &&
910 test_cmp expect actual &&
911 git tag -n1 -l stag-one-line >actual &&
912 test_cmp expect actual &&
913 git tag -n2 -l stag-one-line >actual &&
914 test_cmp expect actual &&
915 git tag -n999 -l stag-one-line >actual &&
916 test_cmp expect actual
919 test_expect_success GPG \
920 'listing the zero-lines message of a signed tag should succeed' '
921 git tag -s -m "" stag-zero-lines &&
923 echo "stag-zero-lines" >expect &&
924 git tag -l | grep "^stag-zero-lines" >actual &&
925 test_cmp expect actual &&
926 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
927 test_cmp expect actual &&
928 git tag -n0 -l stag-zero-lines >actual &&
929 test_cmp expect actual &&
931 echo "stag-zero-lines " >expect &&
932 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
933 test_cmp expect actual &&
934 git tag -n -l | grep "^stag-zero-lines" >actual &&
935 test_cmp expect actual &&
936 git tag -n1 -l stag-zero-lines >actual &&
937 test_cmp expect actual &&
938 git tag -n2 -l stag-zero-lines >actual &&
939 test_cmp expect actual &&
940 git tag -n999 -l stag-zero-lines >actual &&
941 test_cmp expect actual
944 echo 'stag line one' >sigtagmsg
945 echo 'stag line two' >>sigtagmsg
946 echo 'stag line three' >>sigtagmsg
947 test_expect_success GPG \
948 'listing many message lines of a signed tag should succeed' '
949 git tag -s -F sigtagmsg stag-lines &&
951 echo "stag-lines" >expect &&
952 git tag -l | grep "^stag-lines" >actual &&
953 test_cmp expect actual &&
954 git tag -n0 -l | grep "^stag-lines" >actual &&
955 test_cmp expect actual &&
956 git tag -n0 -l stag-lines >actual &&
957 test_cmp expect actual &&
959 echo "stag-lines stag line one" >expect &&
960 git tag -n1 -l | grep "^stag-lines" >actual &&
961 test_cmp expect actual &&
962 git tag -n -l | grep "^stag-lines" >actual &&
963 test_cmp expect actual &&
964 git tag -n1 -l stag-lines >actual &&
965 test_cmp expect actual &&
967 echo " stag line two" >>expect &&
968 git tag -n2 -l | grep "^ *stag.line" >actual &&
969 test_cmp expect actual &&
970 git tag -n2 -l stag-lines >actual &&
971 test_cmp expect actual &&
973 echo " stag line three" >>expect &&
974 git tag -n3 -l | grep "^ *stag.line" >actual &&
975 test_cmp expect actual &&
976 git tag -n3 -l stag-lines >actual &&
977 test_cmp expect actual &&
978 git tag -n4 -l | grep "^ *stag.line" >actual &&
979 test_cmp expect actual &&
980 git tag -n4 -l stag-lines >actual &&
981 test_cmp expect actual &&
982 git tag -n99 -l | grep "^ *stag.line" >actual &&
983 test_cmp expect actual &&
984 git tag -n99 -l stag-lines >actual &&
985 test_cmp expect actual
988 # tags pointing to objects different from commits:
990 tree=$(git rev-parse HEAD^{tree})
991 blob=$(git rev-parse HEAD:foo)
992 tag=$(git rev-parse signed-tag 2>/dev/null)
994 get_tag_header tree-signed-tag $tree tree $time >expect
995 echo "A message for a tree" >>expect
996 echo '-----BEGIN PGP SIGNATURE-----' >>expect
997 test_expect_success GPG \
998 'creating a signed tag pointing to a tree should succeed' '
999 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1000 get_tag_msg tree-signed-tag >actual &&
1001 test_cmp expect actual
1004 get_tag_header blob-signed-tag $blob blob $time >expect
1005 echo "A message for a blob" >>expect
1006 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1007 test_expect_success GPG \
1008 'creating a signed tag pointing to a blob should succeed' '
1009 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1010 get_tag_msg blob-signed-tag >actual &&
1011 test_cmp expect actual
1014 get_tag_header tag-signed-tag $tag tag $time >expect
1015 echo "A message for another tag" >>expect
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success GPG \
1018 'creating a signed tag pointing to another tag should succeed' '
1019 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1020 get_tag_msg tag-signed-tag >actual &&
1021 test_cmp expect actual
1024 # usage with rfc1991 signatures
1025 echo "rfc1991" > gpghome/gpg.conf
1026 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1027 echo "RFC1991 signed tag" >>expect
1028 echo '-----BEGIN PGP MESSAGE-----' >>expect
1029 test_expect_success GPG \
1030 'creating a signed tag with rfc1991' '
1031 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1032 get_tag_msg rfc1991-signed-tag >actual &&
1033 test_cmp expect actual
1036 cat >fakeeditor <<'EOF'
1042 test_expect_success GPG \
1043 'reediting a signed tag body omits signature' '
1044 echo "RFC1991 signed tag" >expect &&
1045 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1046 test_cmp expect actual
1049 test_expect_success GPG \
1050 'verifying rfc1991 signature' '
1051 git tag -v rfc1991-signed-tag
1054 test_expect_success GPG \
1055 'list tag with rfc1991 signature' '
1056 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1057 git tag -l -n1 rfc1991-signed-tag >actual &&
1058 test_cmp expect actual &&
1059 git tag -l -n2 rfc1991-signed-tag >actual &&
1060 test_cmp expect actual &&
1061 git tag -l -n999 rfc1991-signed-tag >actual &&
1062 test_cmp expect actual
1065 rm -f gpghome/gpg.conf
1067 test_expect_success GPG \
1068 'verifying rfc1991 signature without --rfc1991' '
1069 git tag -v rfc1991-signed-tag
1072 test_expect_success GPG \
1073 'list tag with rfc1991 signature without --rfc1991' '
1074 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1075 git tag -l -n1 rfc1991-signed-tag >actual &&
1076 test_cmp expect actual &&
1077 git tag -l -n2 rfc1991-signed-tag >actual &&
1078 test_cmp expect actual &&
1079 git tag -l -n999 rfc1991-signed-tag >actual &&
1080 test_cmp expect actual
1083 test_expect_success GPG \
1084 'reediting a signed tag body omits signature' '
1085 echo "RFC1991 signed tag" >expect &&
1086 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1087 test_cmp expect actual
1090 # try to sign with bad user.signingkey
1091 git config user.signingkey BobTheMouse
1092 test_expect_success GPG \
1093 'git tag -s fails if gpg is misconfigured' \
1094 'test_must_fail git tag -s -m tail tag-gpg-failure'
1095 git config --unset user.signingkey
1097 # try to verify without gpg:
1100 test_expect_success GPG \
1101 'verify signed tag fails when public key is not present' \
1102 'test_must_fail git tag -v signed-tag'
1104 test_expect_success \
1105 'git tag -a fails if tag annotation is empty' '
1106 ! (GIT_EDITOR=cat git tag -a initial-comment)
1109 test_expect_success \
1110 'message in editor has initial comment' '
1111 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1114 test_expect_success 'message in editor has initial comment: first line' '
1115 # check the first line --- should be empty
1116 echo >first.expect &&
1117 sed -e 1q <actual >first.actual &&
1118 test_i18ncmp first.expect first.actual
1121 test_expect_success \
1122 'message in editor has initial comment: remainder' '
1123 # remove commented lines from the remainder -- should be empty
1125 sed -e 1d -e '/^#/d' <actual >rest.actual &&
1126 test_cmp rest.expect rest.actual
1129 get_tag_header reuse $commit commit $time >expect
1130 echo "An annotation to be reused" >> expect
1131 test_expect_success \
1132 'overwriting an annoted tag should use its previous body' '
1133 git tag -a -m "An annotation to be reused" reuse &&
1134 GIT_EDITOR=true git tag -f -a reuse &&
1135 get_tag_msg reuse >actual &&
1136 test_cmp expect actual
1139 test_expect_success 'filename for the message is relative to cwd' '
1141 echo "Tag message in top directory" >msgfile-5 &&
1142 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1145 git tag -a -F msgfile-5 tag-from-subdir
1147 git cat-file tag tag-from-subdir | grep "in sub directory"
1150 test_expect_success 'filename for the message is relative to cwd' '
1151 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1154 git tag -a -F msgfile-6 tag-from-subdir-2
1156 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1159 # create a few more commits to test --contains
1161 hash1=$(git rev-parse HEAD)
1163 test_expect_success 'creating second commit and tag' '
1164 echo foo-2.0 >foo &&
1166 git commit -m second &&
1170 hash2=$(git rev-parse HEAD)
1172 test_expect_success 'creating third commit without tag' '
1173 echo foo-dev >foo &&
1178 hash3=$(git rev-parse HEAD)
1180 # simple linear checks of --continue
1182 cat > expected <<EOF
1190 test_expect_success 'checking that first commit is in all tags (hash)' "
1191 git tag -l --contains $hash1 v* >actual &&
1192 test_cmp expected actual
1195 # other ways of specifying the commit
1196 test_expect_success 'checking that first commit is in all tags (tag)' "
1197 git tag -l --contains v1.0 v* >actual &&
1198 test_cmp expected actual
1201 test_expect_success 'checking that first commit is in all tags (relative)' "
1202 git tag -l --contains HEAD~2 v* >actual &&
1203 test_cmp expected actual
1206 cat > expected <<EOF
1210 test_expect_success 'checking that second commit only has one tag' "
1211 git tag -l --contains $hash2 v* >actual &&
1212 test_cmp expected actual
1216 cat > expected <<EOF
1219 test_expect_success 'checking that third commit has no tags' "
1220 git tag -l --contains $hash3 v* >actual &&
1221 test_cmp expected actual
1224 # how about a simple merge?
1226 test_expect_success 'creating simple branch' '
1227 git branch stable v2.0 &&
1228 git checkout stable &&
1229 echo foo-3.0 > foo &&
1230 git commit foo -m fourth &&
1234 hash4=$(git rev-parse HEAD)
1236 cat > expected <<EOF
1240 test_expect_success 'checking that branch head only has one tag' "
1241 git tag -l --contains $hash4 v* >actual &&
1242 test_cmp expected actual
1245 test_expect_success 'merging original branch into this branch' '
1246 git merge --strategy=ours master &&
1250 cat > expected <<EOF
1254 test_expect_success 'checking that original branch head has one tag now' "
1255 git tag -l --contains $hash3 v* >actual &&
1256 test_cmp expected actual
1259 cat > expected <<EOF
1269 test_expect_success 'checking that initial commit is in all tags' "
1270 git tag -l --contains $hash1 v* >actual &&
1271 test_cmp expected actual
1274 # mixing modes and options:
1276 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1277 test_must_fail git tag -a &&
1278 test_must_fail git tag -l -v &&
1279 test_must_fail git tag -n 100 &&
1280 test_must_fail git tag -l -m msg &&
1281 test_must_fail git tag -l -F some file &&
1282 test_must_fail git tag -v -s