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 'sort tags, ignore case' '
34 test_commit initial &&
38 cat >expected <<-\EOF &&
43 test_cmp expected actual &&
44 git tag -l -i >actual &&
45 cat >expected <<-\EOF &&
50 test_cmp expected actual
54 test_expect_success 'looking for a tag in an empty tree should fail' \
55 '! (tag_exists mytag)'
57 test_expect_success 'creating a tag in an empty tree should fail' '
58 test_must_fail git tag mynotag &&
62 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
63 test_must_fail git tag mytaghead HEAD &&
64 ! tag_exists mytaghead
67 test_expect_success 'creating a tag for an unknown revision should fail' '
68 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
69 ! tag_exists mytagnorev
72 # commit used in the tests, test_tick is also called here to freeze the date:
73 test_expect_success 'creating a tag using default HEAD should succeed' '
79 test_must_fail git reflog exists refs/tags/mytag
82 test_expect_success 'creating a tag with --create-reflog should create reflog' '
83 test_when_finished "git tag -d tag_with_reflog" &&
84 git tag --create-reflog tag_with_reflog &&
85 git reflog exists refs/tags/tag_with_reflog
88 test_expect_success '--create-reflog does not create reflog on failure' '
89 test_must_fail git tag --create-reflog mytag &&
90 test_must_fail git reflog exists refs/tags/mytag
93 test_expect_success 'listing all tags if one exists should succeed' '
98 test_expect_success 'listing all tags if one exists should output that tag' '
99 test $(git tag -l) = mytag &&
100 test $(git tag) = mytag
105 test_expect_success 'listing a tag using a matching pattern should succeed' \
108 test_expect_success 'listing a tag with --ignore-case' \
109 'test $(git tag -l --ignore-case MYTAG) = mytag'
111 test_expect_success \
112 'listing a tag using a matching pattern should output that tag' \
113 'test $(git tag -l mytag) = mytag'
115 # todo: git tag -l now returns always zero, when fixed, change this test
116 test_expect_success \
117 'listing tags using a non-matching pattern should suceed' \
120 test_expect_success \
121 'listing tags using a non-matching pattern should output nothing' \
122 'test $(git tag -l xxx | wc -l) -eq 0'
124 # special cases for creating tags:
126 test_expect_success \
127 'trying to create a tag with the name of one existing should fail' \
128 'test_must_fail git tag mytag'
130 test_expect_success \
131 'trying to create a tag with a non-valid name should fail' '
132 test $(git tag -l | wc -l) -eq 1 &&
133 test_must_fail git tag "" &&
134 test_must_fail git tag .othertag &&
135 test_must_fail git tag "other tag" &&
136 test_must_fail git tag "othertag^" &&
137 test_must_fail git tag "other~tag" &&
138 test $(git tag -l | wc -l) -eq 1
141 test_expect_success 'creating a tag using HEAD directly should succeed' '
142 git tag myhead HEAD &&
146 test_expect_success '--force can create a tag with the name of one existing' '
148 git tag --force mytag &&
151 test_expect_success '--force is moot with a non-existing tag name' '
152 git tag newtag >expect &&
153 git tag --force forcetag >actual &&
154 test_cmp expect actual
156 git tag -d newtag forcetag
160 test_expect_success 'trying to delete an unknown tag should fail' '
161 ! tag_exists unknown-tag &&
162 test_must_fail git tag -d unknown-tag
169 test_expect_success \
170 'trying to delete tags without params should succeed and do nothing' '
171 git tag -l > actual && test_cmp expect actual &&
173 git tag -l > actual && test_cmp expect actual
176 test_expect_success \
177 'deleting two existing tags in one command should succeed' '
180 git tag -d mytag myhead &&
181 ! tag_exists mytag &&
185 test_expect_success \
186 'creating a tag with the name of another deleted one should succeed' '
187 ! tag_exists mytag &&
192 test_expect_success \
193 'trying to delete two tags, existing and not, should fail in the 2nd' '
195 ! tag_exists myhead &&
196 test_must_fail git tag -d mytag anothertag &&
197 ! tag_exists mytag &&
201 test_expect_success 'trying to delete an already deleted tag should fail' \
202 'test_must_fail git tag -d mytag'
204 # listing various tags with pattern matching:
217 test_expect_success 'listing all tags should print them ordered' '
227 git tag -l > actual &&
228 test_cmp expect actual &&
230 test_cmp expect actual
238 test_expect_success \
239 'listing tags with substring as pattern must print those matching' '
241 git tag -l "*a*" > current &&
242 test_cmp expect current
249 test_expect_success \
250 'listing tags with a suffix as pattern must print those matching' '
251 git tag -l "*.1" > actual &&
252 test_cmp expect actual
259 test_expect_success \
260 'listing tags with a prefix as pattern must print those matching' '
261 git tag -l "t21*" > actual &&
262 test_cmp expect actual
268 test_expect_success \
269 'listing tags using a name as pattern must print that one matching' '
270 git tag -l a1 > actual &&
271 test_cmp expect actual
277 test_expect_success \
278 'listing tags using a name as pattern must print that one matching' '
279 git tag -l v1.0 > actual &&
280 test_cmp expect actual
287 test_expect_success \
288 'listing tags with ? in the pattern should print those matching' '
289 git tag -l "v1.?.?" > actual &&
290 test_cmp expect actual
294 test_expect_success \
295 'listing tags using v.* should print nothing because none have v.' '
296 git tag -l "v.*" > actual &&
297 test_cmp expect actual
306 test_expect_success \
307 'listing tags using v* should print only those having v' '
308 git tag -l "v*" > actual &&
309 test_cmp expect actual
312 test_expect_success 'tag -l can accept multiple patterns' '
313 git tag -l "v1*" "v0*" >actual &&
314 test_cmp expect actual
317 test_expect_success 'listing tags in column' '
318 COLUMNS=40 git tag -l --column=row >actual &&
319 cat >expected <<\EOF &&
321 v0.2.1 v1.0 v1.0.1 v1.1.3
323 test_cmp expected actual
326 test_expect_success 'listing tags in column with column.*' '
327 git config column.tag row &&
328 git config column.ui dense &&
329 COLUMNS=40 git tag -l >actual &&
330 git config --unset column.ui &&
331 git config --unset column.tag &&
332 cat >expected <<\EOF &&
334 v0.2.1 v1.0 v1.0.1 v1.1.3
336 test_cmp expected actual
339 test_expect_success 'listing tag with -n --column should fail' '
340 test_must_fail git tag --column -n
343 test_expect_success 'listing tags -n in column with column.ui ignored' '
344 git config column.ui "row dense" &&
345 COLUMNS=40 git tag -l -n >actual &&
346 git config --unset column.ui &&
347 cat >expected <<\EOF &&
358 test_cmp expected actual
361 # creating and verifying lightweight tags:
363 test_expect_success \
364 'a non-annotated tag created without parameters should point to HEAD' '
365 git tag non-annotated-tag &&
366 test $(git cat-file -t non-annotated-tag) = commit &&
367 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
370 test_expect_success 'trying to verify an unknown tag should fail' \
371 'test_must_fail git tag -v unknown-tag'
373 test_expect_success \
374 'trying to verify a non-annotated and non-signed tag should fail' \
375 'test_must_fail git tag -v non-annotated-tag'
377 test_expect_success \
378 'trying to verify many non-annotated or unknown tags, should fail' \
379 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
381 # creating annotated tags:
384 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
387 # run test_tick before committing always gives the time in that timezone
393 tagger C O Mitter <committer@example.com> $4 -0700
398 commit=$(git rev-parse HEAD)
401 get_tag_header annotated-tag $commit commit $time >expect
402 echo "A message" >>expect
403 test_expect_success \
404 'creating an annotated tag with -m message should succeed' '
405 git tag -m "A message" annotated-tag &&
406 get_tag_msg annotated-tag >actual &&
407 test_cmp expect actual
414 get_tag_header file-annotated-tag $commit commit $time >expect
416 test_expect_success \
417 'creating an annotated tag with -F messagefile should succeed' '
418 git tag -F msgfile file-annotated-tag &&
419 get_tag_msg file-annotated-tag >actual &&
420 test_cmp expect actual
427 get_tag_header stdin-annotated-tag $commit commit $time >expect
428 cat inputmsg >>expect
429 test_expect_success 'creating an annotated tag with -F - should succeed' '
430 git tag -F - stdin-annotated-tag <inputmsg &&
431 get_tag_msg stdin-annotated-tag >actual &&
432 test_cmp expect actual
435 test_expect_success \
436 'trying to create a tag with a non-existing -F file should fail' '
437 ! test -f nonexistingfile &&
438 ! tag_exists notag &&
439 test_must_fail git tag -F nonexistingfile notag &&
443 test_expect_success \
444 'trying to create tags giving both -m or -F options should fail' '
445 echo "message file 1" >msgfile1 &&
446 echo "message file 2" >msgfile2 &&
447 ! tag_exists msgtag &&
448 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
449 ! tag_exists msgtag &&
450 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
451 ! tag_exists msgtag &&
452 test_must_fail git tag -m "message 1" -F msgfile1 \
453 -m "message 2" msgtag &&
457 # blank and empty messages:
459 get_tag_header empty-annotated-tag $commit commit $time >expect
460 test_expect_success \
461 'creating a tag with an empty -m message should succeed' '
462 git tag -m "" empty-annotated-tag &&
463 get_tag_msg empty-annotated-tag >actual &&
464 test_cmp expect actual
468 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
469 test_expect_success \
470 'creating a tag with an empty -F messagefile should succeed' '
471 git tag -F emptyfile emptyfile-annotated-tag &&
472 get_tag_msg emptyfile-annotated-tag >actual &&
473 test_cmp expect actual
476 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
477 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
478 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
479 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
480 get_tag_header blanks-annotated-tag $commit commit $time >expect
490 test_expect_success \
491 'extra blanks in the message for an annotated tag should be removed' '
492 git tag -F blanksfile blanks-annotated-tag &&
493 get_tag_msg blanks-annotated-tag >actual &&
494 test_cmp expect actual
497 get_tag_header blank-annotated-tag $commit commit $time >expect
498 test_expect_success \
499 'creating a tag with blank -m message with spaces should succeed' '
500 git tag -m " " blank-annotated-tag &&
501 get_tag_msg blank-annotated-tag >actual &&
502 test_cmp expect actual
508 get_tag_header blankfile-annotated-tag $commit commit $time >expect
509 test_expect_success \
510 'creating a tag with blank -F messagefile with spaces should succeed' '
511 git tag -F blankfile blankfile-annotated-tag &&
512 get_tag_msg blankfile-annotated-tag >actual &&
513 test_cmp expect actual
516 printf ' ' >blanknonlfile
517 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
518 test_expect_success \
519 'creating a tag with -F file of spaces and no newline should succeed' '
520 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
521 get_tag_msg blanknonlfile-annotated-tag >actual &&
522 test_cmp expect actual
525 # messages with commented lines:
527 cat >commentsfile <<EOF
544 get_tag_header comments-annotated-tag $commit commit $time >expect
553 test_expect_success \
554 'creating a tag using a -F messagefile with #comments should succeed' '
555 git tag -F commentsfile comments-annotated-tag &&
556 get_tag_msg comments-annotated-tag >actual &&
557 test_cmp expect actual
560 get_tag_header comment-annotated-tag $commit commit $time >expect
561 test_expect_success \
562 'creating a tag with a #comment in the -m message should succeed' '
563 git tag -m "#comment" comment-annotated-tag &&
564 get_tag_msg comment-annotated-tag >actual &&
565 test_cmp expect actual
568 echo '#comment' >commentfile
569 echo '' >>commentfile
570 echo '####' >>commentfile
571 get_tag_header commentfile-annotated-tag $commit commit $time >expect
572 test_expect_success \
573 'creating a tag with #comments in the -F messagefile should succeed' '
574 git tag -F commentfile commentfile-annotated-tag &&
575 get_tag_msg commentfile-annotated-tag >actual &&
576 test_cmp expect actual
579 printf '#comment' >commentnonlfile
580 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
581 test_expect_success \
582 'creating a tag with a file of #comment and no newline should succeed' '
583 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
584 get_tag_msg commentnonlfile-annotated-tag >actual &&
585 test_cmp expect actual
588 # listing messages for annotated non-signed tags:
590 test_expect_success \
591 'listing the one-line message of a non-signed tag should succeed' '
592 git tag -m "A msg" tag-one-line &&
594 echo "tag-one-line" >expect &&
595 git tag -l | grep "^tag-one-line" >actual &&
596 test_cmp expect actual &&
597 git tag -n0 -l | grep "^tag-one-line" >actual &&
598 test_cmp expect actual &&
599 git tag -n0 -l tag-one-line >actual &&
600 test_cmp expect actual &&
602 echo "tag-one-line A msg" >expect &&
603 git tag -n1 -l | grep "^tag-one-line" >actual &&
604 test_cmp expect actual &&
605 git tag -n -l | grep "^tag-one-line" >actual &&
606 test_cmp expect actual &&
607 git tag -n1 -l tag-one-line >actual &&
608 test_cmp expect actual &&
609 git tag -n2 -l tag-one-line >actual &&
610 test_cmp expect actual &&
611 git tag -n999 -l tag-one-line >actual &&
612 test_cmp expect actual
615 test_expect_success \
616 'listing the zero-lines message of a non-signed tag should succeed' '
617 git tag -m "" tag-zero-lines &&
619 echo "tag-zero-lines" >expect &&
620 git tag -l | grep "^tag-zero-lines" >actual &&
621 test_cmp expect actual &&
622 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
623 test_cmp expect actual &&
624 git tag -n0 -l tag-zero-lines >actual &&
625 test_cmp expect actual &&
627 echo "tag-zero-lines " >expect &&
628 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
629 test_cmp expect actual &&
630 git tag -n -l | grep "^tag-zero-lines" >actual &&
631 test_cmp expect actual &&
632 git tag -n1 -l tag-zero-lines >actual &&
633 test_cmp expect actual &&
634 git tag -n2 -l tag-zero-lines >actual &&
635 test_cmp expect actual &&
636 git tag -n999 -l tag-zero-lines >actual &&
637 test_cmp expect actual
640 echo 'tag line one' >annotagmsg
641 echo 'tag line two' >>annotagmsg
642 echo 'tag line three' >>annotagmsg
643 test_expect_success \
644 'listing many message lines of a non-signed tag should succeed' '
645 git tag -F annotagmsg tag-lines &&
647 echo "tag-lines" >expect &&
648 git tag -l | grep "^tag-lines" >actual &&
649 test_cmp expect actual &&
650 git tag -n0 -l | grep "^tag-lines" >actual &&
651 test_cmp expect actual &&
652 git tag -n0 -l tag-lines >actual &&
653 test_cmp expect actual &&
655 echo "tag-lines tag line one" >expect &&
656 git tag -n1 -l | grep "^tag-lines" >actual &&
657 test_cmp expect actual &&
658 git tag -n -l | grep "^tag-lines" >actual &&
659 test_cmp expect actual &&
660 git tag -n1 -l tag-lines >actual &&
661 test_cmp expect actual &&
663 echo " tag line two" >>expect &&
664 git tag -n2 -l | grep "^ *tag.line" >actual &&
665 test_cmp expect actual &&
666 git tag -n2 -l tag-lines >actual &&
667 test_cmp expect actual &&
669 echo " tag line three" >>expect &&
670 git tag -n3 -l | grep "^ *tag.line" >actual &&
671 test_cmp expect actual &&
672 git tag -n3 -l tag-lines >actual &&
673 test_cmp expect actual &&
674 git tag -n4 -l | grep "^ *tag.line" >actual &&
675 test_cmp expect actual &&
676 git tag -n4 -l tag-lines >actual &&
677 test_cmp expect actual &&
678 git tag -n99 -l | grep "^ *tag.line" >actual &&
679 test_cmp expect actual &&
680 git tag -n99 -l tag-lines >actual &&
681 test_cmp expect actual
684 test_expect_success 'annotations for blobs are empty' '
685 blob=$(git hash-object -w --stdin <<-\EOF
691 git tag tag-blob $blob &&
692 echo "tag-blob " >expect &&
693 git tag -n1 -l tag-blob >actual &&
694 test_cmp expect actual
697 # trying to verify annotated non-signed tags:
699 test_expect_success GPG \
700 'trying to verify an annotated non-signed tag should fail' '
701 tag_exists annotated-tag &&
702 test_must_fail git tag -v annotated-tag
705 test_expect_success GPG \
706 'trying to verify a file-annotated non-signed tag should fail' '
707 tag_exists file-annotated-tag &&
708 test_must_fail git tag -v file-annotated-tag
711 test_expect_success GPG \
712 'trying to verify two annotated non-signed tags should fail' '
713 tag_exists annotated-tag file-annotated-tag &&
714 test_must_fail git tag -v annotated-tag file-annotated-tag
717 # creating and verifying signed tags:
719 get_tag_header signed-tag $commit commit $time >expect
720 echo 'A signed tag message' >>expect
721 echo '-----BEGIN PGP SIGNATURE-----' >>expect
722 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
723 git tag -s -m "A signed tag message" signed-tag &&
724 get_tag_msg signed-tag >actual &&
725 test_cmp expect actual
728 get_tag_header u-signed-tag $commit commit $time >expect
729 echo 'Another message' >>expect
730 echo '-----BEGIN PGP SIGNATURE-----' >>expect
731 test_expect_success GPG 'sign with a given key id' '
733 git tag -u committer@example.com -m "Another message" u-signed-tag &&
734 get_tag_msg u-signed-tag >actual &&
735 test_cmp expect actual
739 test_expect_success GPG 'sign with an unknown id (1)' '
741 test_must_fail git tag -u author@example.com \
742 -m "Another message" o-signed-tag
746 test_expect_success GPG 'sign with an unknown id (2)' '
748 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
752 cat >fakeeditor <<'EOF'
754 test -n "$1" && exec >"$1"
755 echo A signed tag message
756 echo from a fake editor.
760 get_tag_header implied-sign $commit commit $time >expect
761 ./fakeeditor >>expect
762 echo '-----BEGIN PGP SIGNATURE-----' >>expect
763 test_expect_success GPG '-u implies signed tag' '
764 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
765 get_tag_msg implied-sign >actual &&
766 test_cmp expect actual
769 cat >sigmsgfile <<EOF
773 get_tag_header file-signed-tag $commit commit $time >expect
774 cat sigmsgfile >>expect
775 echo '-----BEGIN PGP SIGNATURE-----' >>expect
776 test_expect_success GPG \
777 'creating a signed tag with -F messagefile should succeed' '
778 git tag -s -F sigmsgfile file-signed-tag &&
779 get_tag_msg file-signed-tag >actual &&
780 test_cmp expect actual
783 cat >siginputmsg <<EOF
784 A signed tag message from
787 get_tag_header stdin-signed-tag $commit commit $time >expect
788 cat siginputmsg >>expect
789 echo '-----BEGIN PGP SIGNATURE-----' >>expect
790 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
791 git tag -s -F - stdin-signed-tag <siginputmsg &&
792 get_tag_msg stdin-signed-tag >actual &&
793 test_cmp expect actual
796 get_tag_header implied-annotate $commit commit $time >expect
797 ./fakeeditor >>expect
798 echo '-----BEGIN PGP SIGNATURE-----' >>expect
799 test_expect_success GPG '-s implies annotated tag' '
800 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
801 get_tag_msg implied-annotate >actual &&
802 test_cmp expect actual
805 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
806 echo "A message" >>expect
807 echo '-----BEGIN PGP SIGNATURE-----' >>expect
808 test_expect_success GPG \
809 'git tag -s implied if configured with tag.forcesignannotated' \
810 'test_config tag.forcesignannotated true &&
811 git tag -m "A message" forcesignannotated-implied-sign &&
812 get_tag_msg forcesignannotated-implied-sign >actual &&
813 test_cmp expect actual
816 test_expect_success GPG \
817 'lightweight with no message when configured with tag.forcesignannotated' \
818 'test_config tag.forcesignannotated true &&
819 git tag forcesignannotated-lightweight &&
820 tag_exists forcesignannotated-lightweight &&
821 test_must_fail git tag -v forcesignannotated-no-message
824 get_tag_header forcesignannotated-annotate $commit commit $time >expect
825 echo "A message" >>expect
826 test_expect_success GPG \
827 'git tag -a disable configured tag.forcesignannotated' \
828 'test_config tag.forcesignannotated true &&
829 git tag -a -m "A message" forcesignannotated-annotate &&
830 get_tag_msg forcesignannotated-annotate >actual &&
831 test_cmp expect actual &&
832 test_must_fail git tag -v forcesignannotated-annotate
835 get_tag_header forcesignannotated-disabled $commit commit $time >expect
836 echo "A message" >>expect
837 echo '-----BEGIN PGP SIGNATURE-----' >>expect
838 test_expect_success GPG \
839 'git tag --sign enable GPG sign' \
840 'test_config tag.forcesignannotated false &&
841 git tag --sign -m "A message" forcesignannotated-disabled &&
842 get_tag_msg forcesignannotated-disabled >actual &&
843 test_cmp expect actual
846 test_expect_success GPG \
847 'trying to create a signed tag with non-existing -F file should fail' '
848 ! test -f nonexistingfile &&
849 ! tag_exists nosigtag &&
850 test_must_fail git tag -s -F nonexistingfile nosigtag &&
851 ! tag_exists nosigtag
854 test_expect_success GPG 'verifying a signed tag should succeed' \
855 'git tag -v signed-tag'
857 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
858 'git tag -v signed-tag file-signed-tag'
860 test_expect_success GPG \
861 'verifying many signed and non-signed tags should fail' '
862 test_must_fail git tag -v signed-tag annotated-tag &&
863 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
864 test_must_fail git tag -v annotated-tag \
865 file-signed-tag file-annotated-tag &&
866 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
869 test_expect_success GPG 'verifying a forged tag should fail' '
870 forged=$(git cat-file tag signed-tag |
871 sed -e "s/signed-tag/forged-tag/" |
873 git tag forged-tag $forged &&
874 test_must_fail git tag -v forged-tag
877 # blank and empty messages for signed tags:
879 get_tag_header empty-signed-tag $commit commit $time >expect
880 echo '-----BEGIN PGP SIGNATURE-----' >>expect
881 test_expect_success GPG \
882 'creating a signed tag with an empty -m message should succeed' '
883 git tag -s -m "" empty-signed-tag &&
884 get_tag_msg empty-signed-tag >actual &&
885 test_cmp expect actual &&
886 git tag -v empty-signed-tag
890 get_tag_header emptyfile-signed-tag $commit commit $time >expect
891 echo '-----BEGIN PGP SIGNATURE-----' >>expect
892 test_expect_success GPG \
893 'creating a signed tag with an empty -F messagefile should succeed' '
894 git tag -s -F sigemptyfile emptyfile-signed-tag &&
895 get_tag_msg emptyfile-signed-tag >actual &&
896 test_cmp expect actual &&
897 git tag -v emptyfile-signed-tag
900 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
901 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
902 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
903 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
904 get_tag_header blanks-signed-tag $commit commit $time >expect
914 echo '-----BEGIN PGP SIGNATURE-----' >>expect
915 test_expect_success GPG \
916 'extra blanks in the message for a signed tag should be removed' '
917 git tag -s -F sigblanksfile blanks-signed-tag &&
918 get_tag_msg blanks-signed-tag >actual &&
919 test_cmp expect actual &&
920 git tag -v blanks-signed-tag
923 get_tag_header blank-signed-tag $commit commit $time >expect
924 echo '-----BEGIN PGP SIGNATURE-----' >>expect
925 test_expect_success GPG \
926 'creating a signed tag with a blank -m message should succeed' '
927 git tag -s -m " " blank-signed-tag &&
928 get_tag_msg blank-signed-tag >actual &&
929 test_cmp expect actual &&
930 git tag -v blank-signed-tag
933 echo ' ' >sigblankfile
934 echo '' >>sigblankfile
935 echo ' ' >>sigblankfile
936 get_tag_header blankfile-signed-tag $commit commit $time >expect
937 echo '-----BEGIN PGP SIGNATURE-----' >>expect
938 test_expect_success GPG \
939 'creating a signed tag with blank -F file with spaces should succeed' '
940 git tag -s -F sigblankfile blankfile-signed-tag &&
941 get_tag_msg blankfile-signed-tag >actual &&
942 test_cmp expect actual &&
943 git tag -v blankfile-signed-tag
946 printf ' ' >sigblanknonlfile
947 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
948 echo '-----BEGIN PGP SIGNATURE-----' >>expect
949 test_expect_success GPG \
950 'creating a signed tag with spaces and no newline should succeed' '
951 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
952 get_tag_msg blanknonlfile-signed-tag >actual &&
953 test_cmp expect actual &&
954 git tag -v signed-tag
957 # messages with commented lines for signed tags:
959 cat >sigcommentsfile <<EOF
976 get_tag_header comments-signed-tag $commit commit $time >expect
985 echo '-----BEGIN PGP SIGNATURE-----' >>expect
986 test_expect_success GPG \
987 'creating a signed tag with a -F file with #comments should succeed' '
988 git tag -s -F sigcommentsfile comments-signed-tag &&
989 get_tag_msg comments-signed-tag >actual &&
990 test_cmp expect actual &&
991 git tag -v comments-signed-tag
994 get_tag_header comment-signed-tag $commit commit $time >expect
995 echo '-----BEGIN PGP SIGNATURE-----' >>expect
996 test_expect_success GPG \
997 'creating a signed tag with #commented -m message should succeed' '
998 git tag -s -m "#comment" comment-signed-tag &&
999 get_tag_msg comment-signed-tag >actual &&
1000 test_cmp expect actual &&
1001 git tag -v comment-signed-tag
1004 echo '#comment' >sigcommentfile
1005 echo '' >>sigcommentfile
1006 echo '####' >>sigcommentfile
1007 get_tag_header commentfile-signed-tag $commit commit $time >expect
1008 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1009 test_expect_success GPG \
1010 'creating a signed tag with #commented -F messagefile should succeed' '
1011 git tag -s -F sigcommentfile commentfile-signed-tag &&
1012 get_tag_msg commentfile-signed-tag >actual &&
1013 test_cmp expect actual &&
1014 git tag -v commentfile-signed-tag
1017 printf '#comment' >sigcommentnonlfile
1018 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1019 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1020 test_expect_success GPG \
1021 'creating a signed tag with a #comment and no newline should succeed' '
1022 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1023 get_tag_msg commentnonlfile-signed-tag >actual &&
1024 test_cmp expect actual &&
1025 git tag -v commentnonlfile-signed-tag
1028 # listing messages for signed tags:
1030 test_expect_success GPG \
1031 'listing the one-line message of a signed tag should succeed' '
1032 git tag -s -m "A message line signed" stag-one-line &&
1034 echo "stag-one-line" >expect &&
1035 git tag -l | grep "^stag-one-line" >actual &&
1036 test_cmp expect actual &&
1037 git tag -n0 -l | grep "^stag-one-line" >actual &&
1038 test_cmp expect actual &&
1039 git tag -n0 -l stag-one-line >actual &&
1040 test_cmp expect actual &&
1042 echo "stag-one-line A message line signed" >expect &&
1043 git tag -n1 -l | grep "^stag-one-line" >actual &&
1044 test_cmp expect actual &&
1045 git tag -n -l | grep "^stag-one-line" >actual &&
1046 test_cmp expect actual &&
1047 git tag -n1 -l stag-one-line >actual &&
1048 test_cmp expect actual &&
1049 git tag -n2 -l stag-one-line >actual &&
1050 test_cmp expect actual &&
1051 git tag -n999 -l stag-one-line >actual &&
1052 test_cmp expect actual
1055 test_expect_success GPG \
1056 'listing the zero-lines message of a signed tag should succeed' '
1057 git tag -s -m "" stag-zero-lines &&
1059 echo "stag-zero-lines" >expect &&
1060 git tag -l | grep "^stag-zero-lines" >actual &&
1061 test_cmp expect actual &&
1062 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1063 test_cmp expect actual &&
1064 git tag -n0 -l stag-zero-lines >actual &&
1065 test_cmp expect actual &&
1067 echo "stag-zero-lines " >expect &&
1068 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1069 test_cmp expect actual &&
1070 git tag -n -l | grep "^stag-zero-lines" >actual &&
1071 test_cmp expect actual &&
1072 git tag -n1 -l stag-zero-lines >actual &&
1073 test_cmp expect actual &&
1074 git tag -n2 -l stag-zero-lines >actual &&
1075 test_cmp expect actual &&
1076 git tag -n999 -l stag-zero-lines >actual &&
1077 test_cmp expect actual
1080 echo 'stag line one' >sigtagmsg
1081 echo 'stag line two' >>sigtagmsg
1082 echo 'stag line three' >>sigtagmsg
1083 test_expect_success GPG \
1084 'listing many message lines of a signed tag should succeed' '
1085 git tag -s -F sigtagmsg stag-lines &&
1087 echo "stag-lines" >expect &&
1088 git tag -l | grep "^stag-lines" >actual &&
1089 test_cmp expect actual &&
1090 git tag -n0 -l | grep "^stag-lines" >actual &&
1091 test_cmp expect actual &&
1092 git tag -n0 -l stag-lines >actual &&
1093 test_cmp expect actual &&
1095 echo "stag-lines stag line one" >expect &&
1096 git tag -n1 -l | grep "^stag-lines" >actual &&
1097 test_cmp expect actual &&
1098 git tag -n -l | grep "^stag-lines" >actual &&
1099 test_cmp expect actual &&
1100 git tag -n1 -l stag-lines >actual &&
1101 test_cmp expect actual &&
1103 echo " stag line two" >>expect &&
1104 git tag -n2 -l | grep "^ *stag.line" >actual &&
1105 test_cmp expect actual &&
1106 git tag -n2 -l stag-lines >actual &&
1107 test_cmp expect actual &&
1109 echo " stag line three" >>expect &&
1110 git tag -n3 -l | grep "^ *stag.line" >actual &&
1111 test_cmp expect actual &&
1112 git tag -n3 -l stag-lines >actual &&
1113 test_cmp expect actual &&
1114 git tag -n4 -l | grep "^ *stag.line" >actual &&
1115 test_cmp expect actual &&
1116 git tag -n4 -l stag-lines >actual &&
1117 test_cmp expect actual &&
1118 git tag -n99 -l | grep "^ *stag.line" >actual &&
1119 test_cmp expect actual &&
1120 git tag -n99 -l stag-lines >actual &&
1121 test_cmp expect actual
1124 # tags pointing to objects different from commits:
1126 tree=$(git rev-parse HEAD^{tree})
1127 blob=$(git rev-parse HEAD:foo)
1128 tag=$(git rev-parse signed-tag 2>/dev/null)
1130 get_tag_header tree-signed-tag $tree tree $time >expect
1131 echo "A message for a tree" >>expect
1132 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1133 test_expect_success GPG \
1134 'creating a signed tag pointing to a tree should succeed' '
1135 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1136 get_tag_msg tree-signed-tag >actual &&
1137 test_cmp expect actual
1140 get_tag_header blob-signed-tag $blob blob $time >expect
1141 echo "A message for a blob" >>expect
1142 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1143 test_expect_success GPG \
1144 'creating a signed tag pointing to a blob should succeed' '
1145 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1146 get_tag_msg blob-signed-tag >actual &&
1147 test_cmp expect actual
1150 get_tag_header tag-signed-tag $tag tag $time >expect
1151 echo "A message for another tag" >>expect
1152 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1153 test_expect_success GPG \
1154 'creating a signed tag pointing to another tag should succeed' '
1155 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1156 get_tag_msg tag-signed-tag >actual &&
1157 test_cmp expect actual
1160 # usage with rfc1991 signatures
1161 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1162 echo "RFC1991 signed tag" >>expect
1163 echo '-----BEGIN PGP MESSAGE-----' >>expect
1164 test_expect_success GPG,RFC1991 \
1165 'creating a signed tag with rfc1991' '
1166 echo "rfc1991" >gpghome/gpg.conf &&
1167 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1168 get_tag_msg rfc1991-signed-tag >actual &&
1169 test_cmp expect actual
1172 cat >fakeeditor <<'EOF'
1178 test_expect_success GPG,RFC1991 \
1179 'reediting a signed tag body omits signature' '
1180 echo "rfc1991" >gpghome/gpg.conf &&
1181 echo "RFC1991 signed tag" >expect &&
1182 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1183 test_cmp expect actual
1186 test_expect_success GPG,RFC1991 \
1187 'verifying rfc1991 signature' '
1188 echo "rfc1991" >gpghome/gpg.conf &&
1189 git tag -v rfc1991-signed-tag
1192 test_expect_success GPG,RFC1991 \
1193 'list tag with rfc1991 signature' '
1194 echo "rfc1991" >gpghome/gpg.conf &&
1195 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1196 git tag -l -n1 rfc1991-signed-tag >actual &&
1197 test_cmp expect actual &&
1198 git tag -l -n2 rfc1991-signed-tag >actual &&
1199 test_cmp expect actual &&
1200 git tag -l -n999 rfc1991-signed-tag >actual &&
1201 test_cmp expect actual
1204 rm -f gpghome/gpg.conf
1206 test_expect_success GPG,RFC1991 \
1207 'verifying rfc1991 signature without --rfc1991' '
1208 git tag -v rfc1991-signed-tag
1211 test_expect_success GPG,RFC1991 \
1212 'list tag with rfc1991 signature without --rfc1991' '
1213 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1214 git tag -l -n1 rfc1991-signed-tag >actual &&
1215 test_cmp expect actual &&
1216 git tag -l -n2 rfc1991-signed-tag >actual &&
1217 test_cmp expect actual &&
1218 git tag -l -n999 rfc1991-signed-tag >actual &&
1219 test_cmp expect actual
1222 test_expect_success GPG,RFC1991 \
1223 'reediting a signed tag body omits signature' '
1224 echo "RFC1991 signed tag" >expect &&
1225 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1226 test_cmp expect actual
1229 # try to sign with bad user.signingkey
1230 git config user.signingkey BobTheMouse
1231 test_expect_success GPG \
1232 'git tag -s fails if gpg is misconfigured (bad key)' \
1233 'test_must_fail git tag -s -m tail tag-gpg-failure'
1234 git config --unset user.signingkey
1236 # try to produce invalid signature
1237 test_expect_success GPG \
1238 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1239 'test_config gpg.program echo &&
1240 test_must_fail git tag -s -m tail tag-gpg-failure'
1243 # try to verify without gpg:
1246 test_expect_success GPG \
1247 'verify signed tag fails when public key is not present' \
1248 'test_must_fail git tag -v signed-tag'
1250 test_expect_success \
1251 'git tag -a fails if tag annotation is empty' '
1252 ! (GIT_EDITOR=cat git tag -a initial-comment)
1255 test_expect_success \
1256 'message in editor has initial comment' '
1257 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1260 test_expect_success 'message in editor has initial comment: first line' '
1261 # check the first line --- should be empty
1262 echo >first.expect &&
1263 sed -e 1q <actual >first.actual &&
1264 test_i18ncmp first.expect first.actual
1267 test_expect_success \
1268 'message in editor has initial comment: remainder' '
1269 # remove commented lines from the remainder -- should be empty
1271 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1272 test_cmp rest.expect rest.actual
1275 get_tag_header reuse $commit commit $time >expect
1276 echo "An annotation to be reused" >> expect
1277 test_expect_success \
1278 'overwriting an annoted tag should use its previous body' '
1279 git tag -a -m "An annotation to be reused" reuse &&
1280 GIT_EDITOR=true git tag -f -a reuse &&
1281 get_tag_msg reuse >actual &&
1282 test_cmp expect actual
1285 test_expect_success 'filename for the message is relative to cwd' '
1287 echo "Tag message in top directory" >msgfile-5 &&
1288 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1291 git tag -a -F msgfile-5 tag-from-subdir
1293 git cat-file tag tag-from-subdir | grep "in sub directory"
1296 test_expect_success 'filename for the message is relative to cwd' '
1297 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1300 git tag -a -F msgfile-6 tag-from-subdir-2
1302 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1305 # create a few more commits to test --contains
1307 hash1=$(git rev-parse HEAD)
1309 test_expect_success 'creating second commit and tag' '
1310 echo foo-2.0 >foo &&
1312 git commit -m second &&
1316 hash2=$(git rev-parse HEAD)
1318 test_expect_success 'creating third commit without tag' '
1319 echo foo-dev >foo &&
1324 hash3=$(git rev-parse HEAD)
1326 # simple linear checks of --continue
1328 cat > expected <<EOF
1336 test_expect_success 'checking that first commit is in all tags (hash)' "
1337 git tag -l --contains $hash1 v* >actual &&
1338 test_cmp expected actual
1341 # other ways of specifying the commit
1342 test_expect_success 'checking that first commit is in all tags (tag)' "
1343 git tag -l --contains v1.0 v* >actual &&
1344 test_cmp expected actual
1347 test_expect_success 'checking that first commit is in all tags (relative)' "
1348 git tag -l --contains HEAD~2 v* >actual &&
1349 test_cmp expected actual
1352 cat > expected <<EOF
1356 test_expect_success 'checking that second commit only has one tag' "
1357 git tag -l --contains $hash2 v* >actual &&
1358 test_cmp expected actual
1362 cat > expected <<EOF
1365 test_expect_success 'checking that third commit has no tags' "
1366 git tag -l --contains $hash3 v* >actual &&
1367 test_cmp expected actual
1370 # how about a simple merge?
1372 test_expect_success 'creating simple branch' '
1373 git branch stable v2.0 &&
1374 git checkout stable &&
1375 echo foo-3.0 > foo &&
1376 git commit foo -m fourth &&
1380 hash4=$(git rev-parse HEAD)
1382 cat > expected <<EOF
1386 test_expect_success 'checking that branch head only has one tag' "
1387 git tag -l --contains $hash4 v* >actual &&
1388 test_cmp expected actual
1391 test_expect_success 'merging original branch into this branch' '
1392 git merge --strategy=ours master &&
1396 cat > expected <<EOF
1400 test_expect_success 'checking that original branch head has one tag now' "
1401 git tag -l --contains $hash3 v* >actual &&
1402 test_cmp expected actual
1405 cat > expected <<EOF
1415 test_expect_success 'checking that initial commit is in all tags' "
1416 git tag -l --contains $hash1 v* >actual &&
1417 test_cmp expected actual
1420 # mixing modes and options:
1422 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1423 test_must_fail git tag -a &&
1424 test_must_fail git tag -l -v &&
1425 test_must_fail git tag -n 100 &&
1426 test_must_fail git tag -l -m msg &&
1427 test_must_fail git tag -l -F some file &&
1428 test_must_fail git tag -v -s
1433 test_expect_success '--points-at cannot be used in non-list mode' '
1434 test_must_fail git tag --points-at=v4.0 foo
1437 test_expect_success '--points-at finds lightweight tags' '
1438 echo v4.0 >expect &&
1439 git tag --points-at v4.0 >actual &&
1440 test_cmp expect actual
1443 test_expect_success '--points-at finds annotated tags of commits' '
1444 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1445 echo annotated-v4.0 >expect &&
1446 git tag -l --points-at v4.0 "annotated*" >actual &&
1447 test_cmp expect actual
1450 test_expect_success '--points-at finds annotated tags of tags' '
1451 git tag -m "describing the v4.0 tag object" \
1452 annotated-again-v4.0 annotated-v4.0 &&
1453 cat >expect <<-\EOF &&
1454 annotated-again-v4.0
1457 git tag --points-at=annotated-v4.0 >actual &&
1458 test_cmp expect actual
1461 test_expect_success 'multiple --points-at are OR-ed together' '
1462 cat >expect <<-\EOF &&
1466 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1467 test_cmp expect actual
1470 test_expect_success 'lexical sort' '
1474 git tag -l --sort=refname "foo*" >actual &&
1475 cat >expect <<-\EOF &&
1480 test_cmp expect actual
1483 test_expect_success 'version sort' '
1484 git tag -l --sort=version:refname "foo*" >actual &&
1485 cat >expect <<-\EOF &&
1490 test_cmp expect actual
1493 test_expect_success 'reverse version sort' '
1494 git tag -l --sort=-version:refname "foo*" >actual &&
1495 cat >expect <<-\EOF &&
1500 test_cmp expect actual
1503 test_expect_success 'reverse lexical sort' '
1504 git tag -l --sort=-refname "foo*" >actual &&
1505 cat >expect <<-\EOF &&
1510 test_cmp expect actual
1513 test_expect_success 'configured lexical sort' '
1514 git config tag.sort "v:refname" &&
1515 git tag -l "foo*" >actual &&
1516 cat >expect <<-\EOF &&
1521 test_cmp expect actual
1524 test_expect_success 'option override configured sort' '
1525 git tag -l --sort=-refname "foo*" >actual &&
1526 cat >expect <<-\EOF &&
1531 test_cmp expect actual
1534 test_expect_success 'invalid sort parameter on command line' '
1535 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1538 test_expect_success 'invalid sort parameter in configuratoin' '
1539 git config tag.sort "v:notvalid" &&
1540 test_must_fail git tag -l "foo*"
1543 test_expect_success 'version sort with prerelease reordering' '
1544 git config --unset tag.sort &&
1545 git config versionsort.prereleaseSuffix -rc &&
1546 git tag foo1.6-rc1 &&
1547 git tag foo1.6-rc2 &&
1548 git tag -l --sort=version:refname "foo*" >actual &&
1549 cat >expect <<-\EOF &&
1556 test_cmp expect actual
1559 test_expect_success 'reverse version sort with prerelease reordering' '
1560 git tag -l --sort=-version:refname "foo*" >actual &&
1561 cat >expect <<-\EOF &&
1568 test_cmp expect actual
1571 run_with_limited_stack () {
1572 (ulimit -s 128 && "$@")
1575 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1577 # we require ulimit, this excludes Windows
1578 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1581 while test $i -lt 8000
1583 echo "commit refs/heads/master
1584 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1588 test $i = 1 && echo "from refs/heads/master^0"
1590 done | git fast-import &&
1591 git checkout master &&
1592 git tag far-far-away HEAD^ &&
1593 run_with_limited_stack git tag --contains HEAD >actual &&
1594 test_cmp expect actual
1597 test_expect_success '--format should list tags as per format given' '
1598 cat >expect <<-\EOF &&
1599 refname : refs/tags/foo1.10
1600 refname : refs/tags/foo1.3
1601 refname : refs/tags/foo1.6
1602 refname : refs/tags/foo1.6-rc1
1603 refname : refs/tags/foo1.6-rc2
1605 git tag -l --format="refname : %(refname)" "foo*" >actual &&
1606 test_cmp expect actual
1609 test_expect_success 'setup --merged test tags' '
1610 git tag mergetest-1 HEAD~2 &&
1611 git tag mergetest-2 HEAD~1 &&
1612 git tag mergetest-3 HEAD
1615 test_expect_success '--merged cannot be used in non-list mode' '
1616 test_must_fail git tag --merged=mergetest-2 foo
1619 test_expect_success '--merged shows merged tags' '
1620 cat >expect <<-\EOF &&
1624 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1625 test_cmp expect actual
1628 test_expect_success '--no-merged show unmerged tags' '
1629 cat >expect <<-\EOF &&
1632 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1633 test_cmp expect actual
1636 test_expect_success 'ambiguous branch/tags not marked' '
1637 git tag ambiguous &&
1638 git branch ambiguous &&
1639 echo ambiguous >expect &&
1640 git tag -l ambiguous >actual &&
1641 test_cmp expect actual