3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 . "$TEST_DIRECTORY"/lib-gpg.sh
15 . "$TEST_DIRECTORY"/lib-terminal.sh
17 # creating and listing lightweight tags:
20 git show-ref --quiet --verify refs/tags/"$1"
23 test_expect_success 'listing all tags in an empty tree should succeed' '
28 test_expect_success 'listing all tags in an empty tree should output nothing' '
29 test $(git tag -l | wc -l) -eq 0 &&
30 test $(git tag | wc -l) -eq 0
33 test_expect_success 'sort tags, ignore case' '
37 test_commit initial &&
41 cat >expected <<-\EOF &&
46 test_cmp expected actual &&
47 git tag -l -i >actual &&
48 cat >expected <<-\EOF &&
53 test_cmp expected actual
57 test_expect_success 'looking for a tag in an empty tree should fail' \
58 '! (tag_exists mytag)'
60 test_expect_success 'creating a tag in an empty tree should fail' '
61 test_must_fail git tag mynotag &&
65 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
66 test_must_fail git tag mytaghead HEAD &&
67 ! tag_exists mytaghead
70 test_expect_success 'creating a tag for an unknown revision should fail' '
71 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
72 ! tag_exists mytagnorev
75 # commit used in the tests, test_tick is also called here to freeze the date:
76 test_expect_success 'creating a tag using default HEAD should succeed' '
77 test_config core.logAllRefUpdates true &&
83 test_must_fail git reflog exists refs/tags/mytag
86 test_expect_success 'creating a tag with --create-reflog should create reflog' '
88 --format="format:tag: tagging %h (%s, %cd)%n" \
89 --date=format:%Y-%m-%d >expected &&
90 test_when_finished "git tag -d tag_with_reflog" &&
91 git tag --create-reflog tag_with_reflog &&
92 git reflog exists refs/tags/tag_with_reflog &&
93 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
94 test_i18ncmp expected actual
97 test_expect_success 'annotated tag with --create-reflog has correct message' '
99 --format="format:tag: tagging %h (%s, %cd)%n" \
100 --date=format:%Y-%m-%d >expected &&
101 test_when_finished "git tag -d tag_with_reflog" &&
102 git tag -m "annotated tag" --create-reflog tag_with_reflog &&
103 git reflog exists refs/tags/tag_with_reflog &&
104 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
105 test_i18ncmp expected actual
108 test_expect_success '--create-reflog does not create reflog on failure' '
109 test_must_fail git tag --create-reflog mytag &&
110 test_must_fail git reflog exists refs/tags/mytag
113 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
114 test_when_finished "git tag -d tag_with_reflog" &&
115 test_config core.logAllRefUpdates always &&
116 git tag tag_with_reflog &&
117 git reflog exists refs/tags/tag_with_reflog
120 test_expect_success 'listing all tags if one exists should succeed' '
128 test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
129 git tag -l -l >actual &&
130 test_cmp expect actual &&
131 git tag --list --list >actual &&
132 test_cmp expect actual &&
133 git tag --list -l --list >actual &&
134 test_cmp expect actual
137 test_expect_success 'listing all tags if one exists should output that tag' '
138 test $(git tag -l) = mytag &&
139 test $(git tag) = mytag
144 test_expect_success 'listing a tag using a matching pattern should succeed' \
147 test_expect_success 'listing a tag with --ignore-case' \
148 'test $(git tag -l --ignore-case MYTAG) = mytag'
150 test_expect_success \
151 'listing a tag using a matching pattern should output that tag' \
152 'test $(git tag -l mytag) = mytag'
154 test_expect_success \
155 'listing tags using a non-matching pattern should succeed' \
158 test_expect_success \
159 'listing tags using a non-matching pattern should output nothing' \
160 'test $(git tag -l xxx | wc -l) -eq 0'
162 # special cases for creating tags:
164 test_expect_success \
165 'trying to create a tag with the name of one existing should fail' \
166 'test_must_fail git tag mytag'
168 test_expect_success \
169 'trying to create a tag with a non-valid name should fail' '
170 test $(git tag -l | wc -l) -eq 1 &&
171 test_must_fail git tag "" &&
172 test_must_fail git tag .othertag &&
173 test_must_fail git tag "other tag" &&
174 test_must_fail git tag "othertag^" &&
175 test_must_fail git tag "other~tag" &&
176 test $(git tag -l | wc -l) -eq 1
179 test_expect_success 'creating a tag using HEAD directly should succeed' '
180 git tag myhead HEAD &&
184 test_expect_success '--force can create a tag with the name of one existing' '
186 git tag --force mytag &&
189 test_expect_success '--force is moot with a non-existing tag name' '
190 test_when_finished git tag -d newtag forcetag &&
191 git tag newtag >expect &&
192 git tag --force forcetag >actual &&
193 test_cmp expect actual
198 test_expect_success 'trying to delete an unknown tag should fail' '
199 ! tag_exists unknown-tag &&
200 test_must_fail git tag -d unknown-tag
207 test_expect_success \
208 'trying to delete tags without params should succeed and do nothing' '
209 git tag -l > actual && test_cmp expect actual &&
211 git tag -l > actual && test_cmp expect actual
214 test_expect_success \
215 'deleting two existing tags in one command should succeed' '
218 git tag -d mytag myhead &&
219 ! tag_exists mytag &&
223 test_expect_success \
224 'creating a tag with the name of another deleted one should succeed' '
225 ! tag_exists mytag &&
230 test_expect_success \
231 'trying to delete two tags, existing and not, should fail in the 2nd' '
233 ! tag_exists nonexistingtag &&
234 test_must_fail git tag -d mytag nonexistingtag &&
235 ! tag_exists mytag &&
236 ! tag_exists nonexistingtag
239 test_expect_success 'trying to delete an already deleted tag should fail' \
240 'test_must_fail git tag -d mytag'
242 # listing various tags with pattern matching:
255 test_expect_success 'listing all tags should print them ordered' '
265 git tag -l > actual &&
266 test_cmp expect actual &&
268 test_cmp expect actual
276 test_expect_success \
277 'listing tags with substring as pattern must print those matching' '
279 git tag -l "*a*" > current &&
280 test_cmp expect current
287 test_expect_success \
288 'listing tags with a suffix as pattern must print those matching' '
289 git tag -l "*.1" > actual &&
290 test_cmp expect actual
297 test_expect_success \
298 'listing tags with a prefix as pattern must print those matching' '
299 git tag -l "t21*" > actual &&
300 test_cmp expect actual
306 test_expect_success \
307 'listing tags using a name as pattern must print that one matching' '
308 git tag -l a1 > actual &&
309 test_cmp expect actual
315 test_expect_success \
316 'listing tags using a name as pattern must print that one matching' '
317 git tag -l v1.0 > actual &&
318 test_cmp expect actual
325 test_expect_success \
326 'listing tags with ? in the pattern should print those matching' '
327 git tag -l "v1.?.?" > actual &&
328 test_cmp expect actual
331 test_expect_success \
332 'listing tags using v.* should print nothing because none have v.' '
333 git tag -l "v.*" > actual &&
334 test_must_be_empty actual
343 test_expect_success \
344 'listing tags using v* should print only those having v' '
345 git tag -l "v*" > actual &&
346 test_cmp expect actual
349 test_expect_success 'tag -l can accept multiple patterns' '
350 git tag -l "v1*" "v0*" >actual &&
351 test_cmp expect actual
354 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
355 # could leave you with the impression that "-l <pattern> -l <pattern>"
356 # was how we wanted to accept multiple patterns.
358 # This test should not imply that this is a sane thing to support. but
359 # since the documentation was worded like it was let's at least find
360 # out if we're going to break this long-documented form of taking
362 test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
363 git tag -l "v1*" -l "v0*" >actual &&
364 test_cmp expect actual
367 test_expect_success 'listing tags in column' '
368 COLUMNS=41 git tag -l --column=row >actual &&
369 cat >expected <<\EOF &&
371 v0.2.1 v1.0 v1.0.1 v1.1.3
373 test_cmp expected actual
376 test_expect_success 'listing tags in column with column.*' '
377 test_config column.tag row &&
378 test_config column.ui dense &&
379 COLUMNS=40 git tag -l >actual &&
380 cat >expected <<\EOF &&
382 v0.2.1 v1.0 v1.0.1 v1.1.3
384 test_cmp expected actual
387 test_expect_success 'listing tag with -n --column should fail' '
388 test_must_fail git tag --column -n
391 test_expect_success 'listing tags -n in column with column.ui ignored' '
392 test_config column.ui "row dense" &&
393 COLUMNS=40 git tag -l -n >actual &&
394 cat >expected <<\EOF &&
405 test_cmp expected actual
408 # creating and verifying lightweight tags:
410 test_expect_success \
411 'a non-annotated tag created without parameters should point to HEAD' '
412 git tag non-annotated-tag &&
413 test $(git cat-file -t non-annotated-tag) = commit &&
414 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
417 test_expect_success 'trying to verify an unknown tag should fail' \
418 'test_must_fail git tag -v unknown-tag'
420 test_expect_success \
421 'trying to verify a non-annotated and non-signed tag should fail' \
422 'test_must_fail git tag -v non-annotated-tag'
424 test_expect_success \
425 'trying to verify many non-annotated or unknown tags, should fail' \
426 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
428 # creating annotated tags:
431 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
434 # run test_tick before committing always gives the time in that timezone
440 tagger C O Mitter <committer@example.com> $4 -0700
445 commit=$(git rev-parse HEAD)
448 get_tag_header annotated-tag $commit commit $time >expect
449 echo "A message" >>expect
450 test_expect_success \
451 'creating an annotated tag with -m message should succeed' '
452 git tag -m "A message" annotated-tag &&
453 get_tag_msg annotated-tag >actual &&
454 test_cmp expect actual
457 get_tag_header annotated-tag-edit $commit commit $time >expect
458 echo "An edited message" >>expect
459 test_expect_success 'set up editor' '
460 write_script fakeeditor <<-\EOF
461 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
465 test_expect_success \
466 'creating an annotated tag with -m message --edit should succeed' '
467 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
468 get_tag_msg annotated-tag-edit >actual &&
469 test_cmp expect actual
476 get_tag_header file-annotated-tag $commit commit $time >expect
478 test_expect_success \
479 'creating an annotated tag with -F messagefile should succeed' '
480 git tag -F msgfile file-annotated-tag &&
481 get_tag_msg file-annotated-tag >actual &&
482 test_cmp expect actual
485 get_tag_header file-annotated-tag-edit $commit commit $time >expect
486 sed -e "s/Another message/Another edited message/g" msgfile >>expect
487 test_expect_success 'set up editor' '
488 write_script fakeeditor <<-\EOF
489 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
493 test_expect_success \
494 'creating an annotated tag with -F messagefile --edit should succeed' '
495 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
496 get_tag_msg file-annotated-tag-edit >actual &&
497 test_cmp expect actual
504 get_tag_header stdin-annotated-tag $commit commit $time >expect
505 cat inputmsg >>expect
506 test_expect_success 'creating an annotated tag with -F - should succeed' '
507 git tag -F - stdin-annotated-tag <inputmsg &&
508 get_tag_msg stdin-annotated-tag >actual &&
509 test_cmp expect actual
512 test_expect_success \
513 'trying to create a tag with a non-existing -F file should fail' '
514 ! test -f nonexistingfile &&
515 ! tag_exists notag &&
516 test_must_fail git tag -F nonexistingfile notag &&
520 test_expect_success \
521 'trying to create tags giving both -m or -F options should fail' '
522 echo "message file 1" >msgfile1 &&
523 ! tag_exists msgtag &&
524 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
525 ! tag_exists msgtag &&
526 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
527 ! tag_exists msgtag &&
528 test_must_fail git tag -m "message 1" -F msgfile1 \
529 -m "message 2" msgtag &&
533 # blank and empty messages:
535 get_tag_header empty-annotated-tag $commit commit $time >expect
536 test_expect_success \
537 'creating a tag with an empty -m message should succeed' '
538 git tag -m "" empty-annotated-tag &&
539 get_tag_msg empty-annotated-tag >actual &&
540 test_cmp expect actual
544 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
545 test_expect_success \
546 'creating a tag with an empty -F messagefile should succeed' '
547 git tag -F emptyfile emptyfile-annotated-tag &&
548 get_tag_msg emptyfile-annotated-tag >actual &&
549 test_cmp expect actual
552 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
553 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
554 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
555 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
556 get_tag_header blanks-annotated-tag $commit commit $time >expect
566 test_expect_success \
567 'extra blanks in the message for an annotated tag should be removed' '
568 git tag -F blanksfile blanks-annotated-tag &&
569 get_tag_msg blanks-annotated-tag >actual &&
570 test_cmp expect actual
573 get_tag_header blank-annotated-tag $commit commit $time >expect
574 test_expect_success \
575 'creating a tag with blank -m message with spaces should succeed' '
576 git tag -m " " blank-annotated-tag &&
577 get_tag_msg blank-annotated-tag >actual &&
578 test_cmp expect actual
584 get_tag_header blankfile-annotated-tag $commit commit $time >expect
585 test_expect_success \
586 'creating a tag with blank -F messagefile with spaces should succeed' '
587 git tag -F blankfile blankfile-annotated-tag &&
588 get_tag_msg blankfile-annotated-tag >actual &&
589 test_cmp expect actual
592 printf ' ' >blanknonlfile
593 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
594 test_expect_success \
595 'creating a tag with -F file of spaces and no newline should succeed' '
596 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
597 get_tag_msg blanknonlfile-annotated-tag >actual &&
598 test_cmp expect actual
601 # messages with commented lines:
603 cat >commentsfile <<EOF
620 get_tag_header comments-annotated-tag $commit commit $time >expect
629 test_expect_success \
630 'creating a tag using a -F messagefile with #comments should succeed' '
631 git tag -F commentsfile comments-annotated-tag &&
632 get_tag_msg comments-annotated-tag >actual &&
633 test_cmp expect actual
636 get_tag_header comment-annotated-tag $commit commit $time >expect
637 test_expect_success \
638 'creating a tag with a #comment in the -m message should succeed' '
639 git tag -m "#comment" comment-annotated-tag &&
640 get_tag_msg comment-annotated-tag >actual &&
641 test_cmp expect actual
644 echo '#comment' >commentfile
645 echo '' >>commentfile
646 echo '####' >>commentfile
647 get_tag_header commentfile-annotated-tag $commit commit $time >expect
648 test_expect_success \
649 'creating a tag with #comments in the -F messagefile should succeed' '
650 git tag -F commentfile commentfile-annotated-tag &&
651 get_tag_msg commentfile-annotated-tag >actual &&
652 test_cmp expect actual
655 printf '#comment' >commentnonlfile
656 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
657 test_expect_success \
658 'creating a tag with a file of #comment and no newline should succeed' '
659 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
660 get_tag_msg commentnonlfile-annotated-tag >actual &&
661 test_cmp expect actual
664 # listing messages for annotated non-signed tags:
666 test_expect_success \
667 'listing the one-line message of a non-signed tag should succeed' '
668 git tag -m "A msg" tag-one-line &&
670 echo "tag-one-line" >expect &&
671 git tag -l | grep "^tag-one-line" >actual &&
672 test_cmp expect actual &&
673 git tag -n0 -l | grep "^tag-one-line" >actual &&
674 test_cmp expect actual &&
675 git tag -n0 -l tag-one-line >actual &&
676 test_cmp expect actual &&
678 git tag -n0 | grep "^tag-one-line" >actual &&
679 test_cmp expect actual &&
680 git tag -n0 tag-one-line >actual &&
681 test_cmp expect actual &&
683 echo "tag-one-line A msg" >expect &&
684 git tag -n1 -l | grep "^tag-one-line" >actual &&
685 test_cmp expect actual &&
686 git tag -n -l | grep "^tag-one-line" >actual &&
687 test_cmp expect actual &&
688 git tag -n1 -l tag-one-line >actual &&
689 test_cmp expect actual &&
690 git tag -n2 -l tag-one-line >actual &&
691 test_cmp expect actual &&
692 git tag -n999 -l tag-one-line >actual &&
693 test_cmp expect actual
696 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
697 git tag -n 100 >actual &&
698 test_must_be_empty actual &&
700 git tag -m "A msg" 100 &&
701 echo "100 A msg" >expect &&
702 git tag -n 100 >actual &&
703 test_cmp expect actual
706 test_expect_success \
707 'listing the zero-lines message of a non-signed tag should succeed' '
708 git tag -m "" tag-zero-lines &&
710 echo "tag-zero-lines" >expect &&
711 git tag -l | grep "^tag-zero-lines" >actual &&
712 test_cmp expect actual &&
713 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
714 test_cmp expect actual &&
715 git tag -n0 -l tag-zero-lines >actual &&
716 test_cmp expect actual &&
718 echo "tag-zero-lines " >expect &&
719 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
720 test_cmp expect actual &&
721 git tag -n -l | grep "^tag-zero-lines" >actual &&
722 test_cmp expect actual &&
723 git tag -n1 -l tag-zero-lines >actual &&
724 test_cmp expect actual &&
725 git tag -n2 -l tag-zero-lines >actual &&
726 test_cmp expect actual &&
727 git tag -n999 -l tag-zero-lines >actual &&
728 test_cmp expect actual
731 echo 'tag line one' >annotagmsg
732 echo 'tag line two' >>annotagmsg
733 echo 'tag line three' >>annotagmsg
734 test_expect_success \
735 'listing many message lines of a non-signed tag should succeed' '
736 git tag -F annotagmsg tag-lines &&
738 echo "tag-lines" >expect &&
739 git tag -l | grep "^tag-lines" >actual &&
740 test_cmp expect actual &&
741 git tag -n0 -l | grep "^tag-lines" >actual &&
742 test_cmp expect actual &&
743 git tag -n0 -l tag-lines >actual &&
744 test_cmp expect actual &&
746 echo "tag-lines tag line one" >expect &&
747 git tag -n1 -l | grep "^tag-lines" >actual &&
748 test_cmp expect actual &&
749 git tag -n -l | grep "^tag-lines" >actual &&
750 test_cmp expect actual &&
751 git tag -n1 -l tag-lines >actual &&
752 test_cmp expect actual &&
754 echo " tag line two" >>expect &&
755 git tag -n2 -l | grep "^ *tag.line" >actual &&
756 test_cmp expect actual &&
757 git tag -n2 -l tag-lines >actual &&
758 test_cmp expect actual &&
760 echo " tag line three" >>expect &&
761 git tag -n3 -l | grep "^ *tag.line" >actual &&
762 test_cmp expect actual &&
763 git tag -n3 -l tag-lines >actual &&
764 test_cmp expect actual &&
765 git tag -n4 -l | grep "^ *tag.line" >actual &&
766 test_cmp expect actual &&
767 git tag -n4 -l tag-lines >actual &&
768 test_cmp expect actual &&
769 git tag -n99 -l | grep "^ *tag.line" >actual &&
770 test_cmp expect actual &&
771 git tag -n99 -l tag-lines >actual &&
772 test_cmp expect actual
775 test_expect_success 'annotations for blobs are empty' '
776 blob=$(git hash-object -w --stdin <<-\EOF
782 git tag tag-blob $blob &&
783 echo "tag-blob " >expect &&
784 git tag -n1 -l tag-blob >actual &&
785 test_cmp expect actual
788 # trying to verify annotated non-signed tags:
790 test_expect_success GPG \
791 'trying to verify an annotated non-signed tag should fail' '
792 tag_exists annotated-tag &&
793 test_must_fail git tag -v annotated-tag
796 test_expect_success GPG \
797 'trying to verify a file-annotated non-signed tag should fail' '
798 tag_exists file-annotated-tag &&
799 test_must_fail git tag -v file-annotated-tag
802 test_expect_success GPG \
803 'trying to verify two annotated non-signed tags should fail' '
804 tag_exists annotated-tag file-annotated-tag &&
805 test_must_fail git tag -v annotated-tag file-annotated-tag
808 # creating and verifying signed tags:
810 get_tag_header signed-tag $commit commit $time >expect
811 echo 'A signed tag message' >>expect
812 echo '-----BEGIN PGP SIGNATURE-----' >>expect
813 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
814 git tag -s -m "A signed tag message" signed-tag &&
815 get_tag_msg signed-tag >actual &&
816 test_cmp expect actual
819 get_tag_header u-signed-tag $commit commit $time >expect
820 echo 'Another message' >>expect
821 echo '-----BEGIN PGP SIGNATURE-----' >>expect
822 test_expect_success GPG 'sign with a given key id' '
824 git tag -u committer@example.com -m "Another message" u-signed-tag &&
825 get_tag_msg u-signed-tag >actual &&
826 test_cmp expect actual
830 test_expect_success GPG 'sign with an unknown id (1)' '
832 test_must_fail git tag -u author@example.com \
833 -m "Another message" o-signed-tag
837 test_expect_success GPG 'sign with an unknown id (2)' '
839 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
843 cat >fakeeditor <<'EOF'
845 test -n "$1" && exec >"$1"
846 echo A signed tag message
847 echo from a fake editor.
851 get_tag_header implied-sign $commit commit $time >expect
852 ./fakeeditor >>expect
853 echo '-----BEGIN PGP SIGNATURE-----' >>expect
854 test_expect_success GPG '-u implies signed tag' '
855 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
856 get_tag_msg implied-sign >actual &&
857 test_cmp expect actual
860 cat >sigmsgfile <<EOF
864 get_tag_header file-signed-tag $commit commit $time >expect
865 cat sigmsgfile >>expect
866 echo '-----BEGIN PGP SIGNATURE-----' >>expect
867 test_expect_success GPG \
868 'creating a signed tag with -F messagefile should succeed' '
869 git tag -s -F sigmsgfile file-signed-tag &&
870 get_tag_msg file-signed-tag >actual &&
871 test_cmp expect actual
874 cat >siginputmsg <<EOF
875 A signed tag message from
878 get_tag_header stdin-signed-tag $commit commit $time >expect
879 cat siginputmsg >>expect
880 echo '-----BEGIN PGP SIGNATURE-----' >>expect
881 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
882 git tag -s -F - stdin-signed-tag <siginputmsg &&
883 get_tag_msg stdin-signed-tag >actual &&
884 test_cmp expect actual
887 get_tag_header implied-annotate $commit commit $time >expect
888 ./fakeeditor >>expect
889 echo '-----BEGIN PGP SIGNATURE-----' >>expect
890 test_expect_success GPG '-s implies annotated tag' '
891 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
892 get_tag_msg implied-annotate >actual &&
893 test_cmp expect actual
896 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
897 echo "A message" >>expect
898 echo '-----BEGIN PGP SIGNATURE-----' >>expect
899 test_expect_success GPG \
900 'git tag -s implied if configured with tag.forcesignannotated' \
901 'test_config tag.forcesignannotated true &&
902 git tag -m "A message" forcesignannotated-implied-sign &&
903 get_tag_msg forcesignannotated-implied-sign >actual &&
904 test_cmp expect actual
907 test_expect_success GPG \
908 'lightweight with no message when configured with tag.forcesignannotated' \
909 'test_config tag.forcesignannotated true &&
910 git tag forcesignannotated-lightweight &&
911 tag_exists forcesignannotated-lightweight &&
912 test_must_fail git tag -v forcesignannotated-no-message
915 get_tag_header forcesignannotated-annotate $commit commit $time >expect
916 echo "A message" >>expect
917 test_expect_success GPG \
918 'git tag -a disable configured tag.forcesignannotated' \
919 'test_config tag.forcesignannotated true &&
920 git tag -a -m "A message" forcesignannotated-annotate &&
921 get_tag_msg forcesignannotated-annotate >actual &&
922 test_cmp expect actual &&
923 test_must_fail git tag -v forcesignannotated-annotate
926 get_tag_header forcesignannotated-disabled $commit commit $time >expect
927 echo "A message" >>expect
928 echo '-----BEGIN PGP SIGNATURE-----' >>expect
929 test_expect_success GPG \
930 'git tag --sign enable GPG sign' \
931 'test_config tag.forcesignannotated false &&
932 git tag --sign -m "A message" forcesignannotated-disabled &&
933 get_tag_msg forcesignannotated-disabled >actual &&
934 test_cmp expect actual
937 get_tag_header gpgsign-enabled $commit commit $time >expect
938 echo "A message" >>expect
939 echo '-----BEGIN PGP SIGNATURE-----' >>expect
940 test_expect_success GPG \
941 'git tag configured tag.gpgsign enables GPG sign' \
942 'test_config tag.gpgsign true &&
943 git tag -m "A message" gpgsign-enabled &&
944 get_tag_msg gpgsign-enabled>actual &&
945 test_cmp expect actual
948 get_tag_header no-sign $commit commit $time >expect
949 echo "A message" >>expect
950 test_expect_success GPG \
951 'git tag --no-sign configured tag.gpgsign skip GPG sign' \
952 'test_config tag.gpgsign true &&
953 git tag -a --no-sign -m "A message" no-sign &&
954 get_tag_msg no-sign>actual &&
955 test_cmp expect actual
958 test_expect_success GPG \
959 'trying to create a signed tag with non-existing -F file should fail' '
960 ! test -f nonexistingfile &&
961 ! tag_exists nosigtag &&
962 test_must_fail git tag -s -F nonexistingfile nosigtag &&
963 ! tag_exists nosigtag
966 test_expect_success GPG 'verifying a signed tag should succeed' \
967 'git tag -v signed-tag'
969 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
970 'git tag -v signed-tag file-signed-tag'
972 test_expect_success GPG \
973 'verifying many signed and non-signed tags should fail' '
974 test_must_fail git tag -v signed-tag annotated-tag &&
975 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
976 test_must_fail git tag -v annotated-tag \
977 file-signed-tag file-annotated-tag &&
978 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
981 test_expect_success GPG 'verifying a forged tag should fail' '
982 forged=$(git cat-file tag signed-tag |
983 sed -e "s/signed-tag/forged-tag/" |
985 git tag forged-tag $forged &&
986 test_must_fail git tag -v forged-tag
989 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
990 cat >expect <<-\EOF &&
993 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
994 test_cmp expect actual
997 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
998 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
999 test_must_be_empty actual
1002 # blank and empty messages for signed tags:
1004 get_tag_header empty-signed-tag $commit commit $time >expect
1005 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1006 test_expect_success GPG \
1007 'creating a signed tag with an empty -m message should succeed' '
1008 git tag -s -m "" empty-signed-tag &&
1009 get_tag_msg empty-signed-tag >actual &&
1010 test_cmp expect actual &&
1011 git tag -v empty-signed-tag
1015 get_tag_header emptyfile-signed-tag $commit commit $time >expect
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success GPG \
1018 'creating a signed tag with an empty -F messagefile should succeed' '
1019 git tag -s -F sigemptyfile emptyfile-signed-tag &&
1020 get_tag_msg emptyfile-signed-tag >actual &&
1021 test_cmp expect actual &&
1022 git tag -v emptyfile-signed-tag
1025 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1026 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1027 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1028 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1029 get_tag_header blanks-signed-tag $commit commit $time >expect
1033 Repeated blank lines
1037 Trailing blank lines
1039 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1040 test_expect_success GPG \
1041 'extra blanks in the message for a signed tag should be removed' '
1042 git tag -s -F sigblanksfile blanks-signed-tag &&
1043 get_tag_msg blanks-signed-tag >actual &&
1044 test_cmp expect actual &&
1045 git tag -v blanks-signed-tag
1048 get_tag_header blank-signed-tag $commit commit $time >expect
1049 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1050 test_expect_success GPG \
1051 'creating a signed tag with a blank -m message should succeed' '
1052 git tag -s -m " " blank-signed-tag &&
1053 get_tag_msg blank-signed-tag >actual &&
1054 test_cmp expect actual &&
1055 git tag -v blank-signed-tag
1058 echo ' ' >sigblankfile
1059 echo '' >>sigblankfile
1060 echo ' ' >>sigblankfile
1061 get_tag_header blankfile-signed-tag $commit commit $time >expect
1062 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1063 test_expect_success GPG \
1064 'creating a signed tag with blank -F file with spaces should succeed' '
1065 git tag -s -F sigblankfile blankfile-signed-tag &&
1066 get_tag_msg blankfile-signed-tag >actual &&
1067 test_cmp expect actual &&
1068 git tag -v blankfile-signed-tag
1071 printf ' ' >sigblanknonlfile
1072 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1073 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1074 test_expect_success GPG \
1075 'creating a signed tag with spaces and no newline should succeed' '
1076 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1077 get_tag_msg blanknonlfile-signed-tag >actual &&
1078 test_cmp expect actual &&
1079 git tag -v blanknonlfile-signed-tag
1082 test_expect_success GPG 'signed tag with embedded PGP message' '
1084 -----BEGIN PGP MESSAGE-----
1086 this is not a real PGP message
1087 -----END PGP MESSAGE-----
1089 git tag -s -F msg confusing-pgp-message &&
1090 git tag -v confusing-pgp-message
1093 # messages with commented lines for signed tags:
1095 cat >sigcommentsfile <<EOF
1112 get_tag_header comments-signed-tag $commit commit $time >expect
1121 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1122 test_expect_success GPG \
1123 'creating a signed tag with a -F file with #comments should succeed' '
1124 git tag -s -F sigcommentsfile comments-signed-tag &&
1125 get_tag_msg comments-signed-tag >actual &&
1126 test_cmp expect actual &&
1127 git tag -v comments-signed-tag
1130 get_tag_header comment-signed-tag $commit commit $time >expect
1131 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1132 test_expect_success GPG \
1133 'creating a signed tag with #commented -m message should succeed' '
1134 git tag -s -m "#comment" comment-signed-tag &&
1135 get_tag_msg comment-signed-tag >actual &&
1136 test_cmp expect actual &&
1137 git tag -v comment-signed-tag
1140 echo '#comment' >sigcommentfile
1141 echo '' >>sigcommentfile
1142 echo '####' >>sigcommentfile
1143 get_tag_header commentfile-signed-tag $commit commit $time >expect
1144 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1145 test_expect_success GPG \
1146 'creating a signed tag with #commented -F messagefile should succeed' '
1147 git tag -s -F sigcommentfile commentfile-signed-tag &&
1148 get_tag_msg commentfile-signed-tag >actual &&
1149 test_cmp expect actual &&
1150 git tag -v commentfile-signed-tag
1153 printf '#comment' >sigcommentnonlfile
1154 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1155 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1156 test_expect_success GPG \
1157 'creating a signed tag with a #comment and no newline should succeed' '
1158 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1159 get_tag_msg commentnonlfile-signed-tag >actual &&
1160 test_cmp expect actual &&
1161 git tag -v commentnonlfile-signed-tag
1164 # listing messages for signed tags:
1166 test_expect_success GPG \
1167 'listing the one-line message of a signed tag should succeed' '
1168 git tag -s -m "A message line signed" stag-one-line &&
1170 echo "stag-one-line" >expect &&
1171 git tag -l | grep "^stag-one-line" >actual &&
1172 test_cmp expect actual &&
1173 git tag -n0 -l | grep "^stag-one-line" >actual &&
1174 test_cmp expect actual &&
1175 git tag -n0 -l stag-one-line >actual &&
1176 test_cmp expect actual &&
1178 echo "stag-one-line A message line signed" >expect &&
1179 git tag -n1 -l | grep "^stag-one-line" >actual &&
1180 test_cmp expect actual &&
1181 git tag -n -l | grep "^stag-one-line" >actual &&
1182 test_cmp expect actual &&
1183 git tag -n1 -l stag-one-line >actual &&
1184 test_cmp expect actual &&
1185 git tag -n2 -l stag-one-line >actual &&
1186 test_cmp expect actual &&
1187 git tag -n999 -l stag-one-line >actual &&
1188 test_cmp expect actual
1191 test_expect_success GPG \
1192 'listing the zero-lines message of a signed tag should succeed' '
1193 git tag -s -m "" stag-zero-lines &&
1195 echo "stag-zero-lines" >expect &&
1196 git tag -l | grep "^stag-zero-lines" >actual &&
1197 test_cmp expect actual &&
1198 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1199 test_cmp expect actual &&
1200 git tag -n0 -l stag-zero-lines >actual &&
1201 test_cmp expect actual &&
1203 echo "stag-zero-lines " >expect &&
1204 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1205 test_cmp expect actual &&
1206 git tag -n -l | grep "^stag-zero-lines" >actual &&
1207 test_cmp expect actual &&
1208 git tag -n1 -l stag-zero-lines >actual &&
1209 test_cmp expect actual &&
1210 git tag -n2 -l stag-zero-lines >actual &&
1211 test_cmp expect actual &&
1212 git tag -n999 -l stag-zero-lines >actual &&
1213 test_cmp expect actual
1216 echo 'stag line one' >sigtagmsg
1217 echo 'stag line two' >>sigtagmsg
1218 echo 'stag line three' >>sigtagmsg
1219 test_expect_success GPG \
1220 'listing many message lines of a signed tag should succeed' '
1221 git tag -s -F sigtagmsg stag-lines &&
1223 echo "stag-lines" >expect &&
1224 git tag -l | grep "^stag-lines" >actual &&
1225 test_cmp expect actual &&
1226 git tag -n0 -l | grep "^stag-lines" >actual &&
1227 test_cmp expect actual &&
1228 git tag -n0 -l stag-lines >actual &&
1229 test_cmp expect actual &&
1231 echo "stag-lines stag line one" >expect &&
1232 git tag -n1 -l | grep "^stag-lines" >actual &&
1233 test_cmp expect actual &&
1234 git tag -n -l | grep "^stag-lines" >actual &&
1235 test_cmp expect actual &&
1236 git tag -n1 -l stag-lines >actual &&
1237 test_cmp expect actual &&
1239 echo " stag line two" >>expect &&
1240 git tag -n2 -l | grep "^ *stag.line" >actual &&
1241 test_cmp expect actual &&
1242 git tag -n2 -l stag-lines >actual &&
1243 test_cmp expect actual &&
1245 echo " stag line three" >>expect &&
1246 git tag -n3 -l | grep "^ *stag.line" >actual &&
1247 test_cmp expect actual &&
1248 git tag -n3 -l stag-lines >actual &&
1249 test_cmp expect actual &&
1250 git tag -n4 -l | grep "^ *stag.line" >actual &&
1251 test_cmp expect actual &&
1252 git tag -n4 -l stag-lines >actual &&
1253 test_cmp expect actual &&
1254 git tag -n99 -l | grep "^ *stag.line" >actual &&
1255 test_cmp expect actual &&
1256 git tag -n99 -l stag-lines >actual &&
1257 test_cmp expect actual
1260 # tags pointing to objects different from commits:
1262 tree=$(git rev-parse HEAD^{tree})
1263 blob=$(git rev-parse HEAD:foo)
1264 tag=$(git rev-parse signed-tag 2>/dev/null)
1266 get_tag_header tree-signed-tag $tree tree $time >expect
1267 echo "A message for a tree" >>expect
1268 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1269 test_expect_success GPG \
1270 'creating a signed tag pointing to a tree should succeed' '
1271 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1272 get_tag_msg tree-signed-tag >actual &&
1273 test_cmp expect actual
1276 get_tag_header blob-signed-tag $blob blob $time >expect
1277 echo "A message for a blob" >>expect
1278 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1279 test_expect_success GPG \
1280 'creating a signed tag pointing to a blob should succeed' '
1281 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1282 get_tag_msg blob-signed-tag >actual &&
1283 test_cmp expect actual
1286 get_tag_header tag-signed-tag $tag tag $time >expect
1287 echo "A message for another tag" >>expect
1288 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1289 test_expect_success GPG \
1290 'creating a signed tag pointing to another tag should succeed' '
1291 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1292 get_tag_msg tag-signed-tag >actual &&
1293 test_cmp expect actual
1296 # usage with rfc1991 signatures
1297 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1298 echo "RFC1991 signed tag" >>expect
1299 echo '-----BEGIN PGP MESSAGE-----' >>expect
1300 test_expect_success GPG,RFC1991 \
1301 'creating a signed tag with rfc1991' '
1302 echo "rfc1991" >gpghome/gpg.conf &&
1303 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1304 get_tag_msg rfc1991-signed-tag >actual &&
1305 test_cmp expect actual
1308 cat >fakeeditor <<'EOF'
1314 test_expect_success GPG,RFC1991 \
1315 'reediting a signed tag body omits signature' '
1316 echo "rfc1991" >gpghome/gpg.conf &&
1317 echo "RFC1991 signed tag" >expect &&
1318 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1319 test_cmp expect actual
1322 test_expect_success GPG,RFC1991 \
1323 'verifying rfc1991 signature' '
1324 echo "rfc1991" >gpghome/gpg.conf &&
1325 git tag -v rfc1991-signed-tag
1328 test_expect_success GPG,RFC1991 \
1329 'list tag with rfc1991 signature' '
1330 echo "rfc1991" >gpghome/gpg.conf &&
1331 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1332 git tag -l -n1 rfc1991-signed-tag >actual &&
1333 test_cmp expect actual &&
1334 git tag -l -n2 rfc1991-signed-tag >actual &&
1335 test_cmp expect actual &&
1336 git tag -l -n999 rfc1991-signed-tag >actual &&
1337 test_cmp expect actual
1340 rm -f gpghome/gpg.conf
1342 test_expect_success GPG,RFC1991 \
1343 'verifying rfc1991 signature without --rfc1991' '
1344 git tag -v rfc1991-signed-tag
1347 test_expect_success GPG,RFC1991 \
1348 'list tag with rfc1991 signature without --rfc1991' '
1349 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1350 git tag -l -n1 rfc1991-signed-tag >actual &&
1351 test_cmp expect actual &&
1352 git tag -l -n2 rfc1991-signed-tag >actual &&
1353 test_cmp expect actual &&
1354 git tag -l -n999 rfc1991-signed-tag >actual &&
1355 test_cmp expect actual
1358 test_expect_success GPG,RFC1991 \
1359 'reediting a signed tag body omits signature' '
1360 echo "RFC1991 signed tag" >expect &&
1361 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1362 test_cmp expect actual
1365 # try to sign with bad user.signingkey
1366 test_expect_success GPG \
1367 'git tag -s fails if gpg is misconfigured (bad key)' \
1368 'test_config user.signingkey BobTheMouse &&
1369 test_must_fail git tag -s -m tail tag-gpg-failure'
1371 # try to produce invalid signature
1372 test_expect_success GPG \
1373 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1374 'test_config gpg.program echo &&
1375 test_must_fail git tag -s -m tail tag-gpg-failure'
1377 # try to sign with bad user.signingkey
1378 test_expect_success GPGSM \
1379 'git tag -s fails if gpgsm is misconfigured (bad key)' \
1380 'test_config user.signingkey BobTheMouse &&
1381 test_config gpg.format x509 &&
1382 test_must_fail git tag -s -m tail tag-gpg-failure'
1384 # try to produce invalid signature
1385 test_expect_success GPGSM \
1386 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1387 'test_config gpg.x509.program echo &&
1388 test_config gpg.format x509 &&
1389 test_must_fail git tag -s -m tail tag-gpg-failure'
1391 # try to verify without gpg:
1394 test_expect_success GPG \
1395 'verify signed tag fails when public key is not present' \
1396 'test_must_fail git tag -v signed-tag'
1398 test_expect_success \
1399 'git tag -a fails if tag annotation is empty' '
1400 ! (GIT_EDITOR=cat git tag -a initial-comment)
1403 test_expect_success \
1404 'message in editor has initial comment' '
1405 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1408 test_expect_success 'message in editor has initial comment: first line' '
1409 # check the first line --- should be empty
1410 echo >first.expect &&
1411 sed -e 1q <actual >first.actual &&
1412 test_i18ncmp first.expect first.actual
1415 test_expect_success \
1416 'message in editor has initial comment: remainder' '
1417 # remove commented lines from the remainder -- should be empty
1418 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1419 test_must_be_empty rest.actual
1422 get_tag_header reuse $commit commit $time >expect
1423 echo "An annotation to be reused" >> expect
1424 test_expect_success \
1425 'overwriting an annotated tag should use its previous body' '
1426 git tag -a -m "An annotation to be reused" reuse &&
1427 GIT_EDITOR=true git tag -f -a reuse &&
1428 get_tag_msg reuse >actual &&
1429 test_cmp expect actual
1432 test_expect_success 'filename for the message is relative to cwd' '
1434 echo "Tag message in top directory" >msgfile-5 &&
1435 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1438 git tag -a -F msgfile-5 tag-from-subdir
1440 git cat-file tag tag-from-subdir | grep "in sub directory"
1443 test_expect_success 'filename for the message is relative to cwd' '
1444 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1447 git tag -a -F msgfile-6 tag-from-subdir-2
1449 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1452 # create a few more commits to test --contains
1454 hash1=$(git rev-parse HEAD)
1456 test_expect_success 'creating second commit and tag' '
1457 echo foo-2.0 >foo &&
1459 git commit -m second &&
1463 hash2=$(git rev-parse HEAD)
1465 test_expect_success 'creating third commit without tag' '
1466 echo foo-dev >foo &&
1471 hash3=$(git rev-parse HEAD)
1473 # simple linear checks of --continue
1475 cat > expected <<EOF
1483 test_expect_success 'checking that first commit is in all tags (hash)' "
1484 git tag -l --contains $hash1 v* >actual &&
1485 test_cmp expected actual
1488 # other ways of specifying the commit
1489 test_expect_success 'checking that first commit is in all tags (tag)' "
1490 git tag -l --contains v1.0 v* >actual &&
1491 test_cmp expected actual
1494 test_expect_success 'checking that first commit is in all tags (relative)' "
1495 git tag -l --contains HEAD~2 v* >actual &&
1496 test_cmp expected actual
1499 # All the --contains tests above, but with --no-contains
1500 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1501 git tag -l --no-contains $hash1 v* >actual &&
1502 test_must_be_empty actual
1505 test_expect_success 'checking that first commit is in all tags (tag)' "
1506 git tag -l --no-contains v1.0 v* >actual &&
1507 test_must_be_empty actual
1510 test_expect_success 'checking that first commit is in all tags (relative)' "
1511 git tag -l --no-contains HEAD~2 v* >actual &&
1512 test_must_be_empty actual
1515 cat > expected <<EOF
1519 test_expect_success 'checking that second commit only has one tag' "
1520 git tag -l --contains $hash2 v* >actual &&
1521 test_cmp expected actual
1524 cat > expected <<EOF
1531 test_expect_success 'inverse of the last test, with --no-contains' "
1532 git tag -l --no-contains $hash2 v* >actual &&
1533 test_cmp expected actual
1536 test_expect_success 'checking that third commit has no tags' "
1537 git tag -l --contains $hash3 v* >actual &&
1538 test_must_be_empty actual
1541 cat > expected <<EOF
1549 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1550 git tag -l --no-contains $hash3 v* >actual &&
1551 test_cmp expected actual
1554 # how about a simple merge?
1556 test_expect_success 'creating simple branch' '
1557 git branch stable v2.0 &&
1558 git checkout stable &&
1559 echo foo-3.0 > foo &&
1560 git commit foo -m fourth &&
1564 hash4=$(git rev-parse HEAD)
1566 cat > expected <<EOF
1570 test_expect_success 'checking that branch head only has one tag' "
1571 git tag -l --contains $hash4 v* >actual &&
1572 test_cmp expected actual
1575 cat > expected <<EOF
1583 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1584 git tag -l --no-contains $hash4 v* >actual &&
1585 test_cmp expected actual
1588 test_expect_success 'merging original branch into this branch' '
1589 git merge --strategy=ours main &&
1593 cat > expected <<EOF
1597 test_expect_success 'checking that original branch head has one tag now' "
1598 git tag -l --contains $hash3 v* >actual &&
1599 test_cmp expected actual
1602 cat > expected <<EOF
1611 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1612 git tag -l --no-contains $hash3 v* >actual &&
1613 test_cmp expected actual
1616 cat > expected <<EOF
1626 test_expect_success 'checking that initial commit is in all tags' "
1627 git tag -l --contains $hash1 v* >actual &&
1628 test_cmp expected actual
1631 test_expect_success 'checking that --contains can be used in non-list mode' '
1632 git tag --contains $hash1 v* >actual &&
1633 test_cmp expected actual
1636 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1637 git tag -l --no-contains $hash1 v* >actual &&
1638 test_must_be_empty actual
1641 # mixing modes and options:
1643 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1644 test_must_fail git tag -a &&
1645 test_must_fail git tag -a -l &&
1646 test_must_fail git tag -s &&
1647 test_must_fail git tag -s -l &&
1648 test_must_fail git tag -m &&
1649 test_must_fail git tag -m -l &&
1650 test_must_fail git tag -m "hlagh" &&
1651 test_must_fail git tag -m "hlagh" -l &&
1652 test_must_fail git tag -F &&
1653 test_must_fail git tag -F -l &&
1654 test_must_fail git tag -f &&
1655 test_must_fail git tag -f -l &&
1656 test_must_fail git tag -a -s -m -F &&
1657 test_must_fail git tag -a -s -m -F -l &&
1658 test_must_fail git tag -l -v &&
1659 test_must_fail git tag -l -d &&
1660 test_must_fail git tag -l -v -d &&
1661 test_must_fail git tag -n 100 -v &&
1662 test_must_fail git tag -l -m msg &&
1663 test_must_fail git tag -l -F some file &&
1664 test_must_fail git tag -v -s &&
1665 test_must_fail git tag --contains tag-tree &&
1666 test_must_fail git tag --contains tag-blob &&
1667 test_must_fail git tag --no-contains tag-tree &&
1668 test_must_fail git tag --no-contains tag-blob &&
1669 test_must_fail git tag --contains --no-contains &&
1670 test_must_fail git tag --no-with HEAD &&
1671 test_must_fail git tag --no-without HEAD
1674 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1676 test_expect_success "mixing incompatible modes with $option is forbidden" "
1677 test_must_fail git tag -d $option HEAD &&
1678 test_must_fail git tag -d $option HEAD some-tag &&
1679 test_must_fail git tag -v $option HEAD
1681 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1682 git tag -n $option HEAD HEAD &&
1683 git tag $option HEAD HEAD &&
1690 test_expect_success '--points-at can be used in non-list mode' '
1691 echo v4.0 >expect &&
1692 git tag --points-at=v4.0 "v*" >actual &&
1693 test_cmp expect actual
1696 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1697 echo v4.0 >expect &&
1698 git tag --points-at >actual &&
1699 test_cmp expect actual
1702 test_expect_success '--points-at finds lightweight tags' '
1703 echo v4.0 >expect &&
1704 git tag --points-at v4.0 >actual &&
1705 test_cmp expect actual
1708 test_expect_success '--points-at finds annotated tags of commits' '
1709 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1710 echo annotated-v4.0 >expect &&
1711 git tag -l --points-at v4.0 "annotated*" >actual &&
1712 test_cmp expect actual
1715 test_expect_success '--points-at finds annotated tags of tags' '
1716 git tag -m "describing the v4.0 tag object" \
1717 annotated-again-v4.0 annotated-v4.0 &&
1718 cat >expect <<-\EOF &&
1719 annotated-again-v4.0
1722 git tag --points-at=annotated-v4.0 >actual &&
1723 test_cmp expect actual
1726 test_expect_success 'recursive tagging should give advice' '
1727 sed -e "s/|$//" <<-EOF >expect &&
1728 hint: You have created a nested tag. The object referred to by your new tag is
1729 hint: already a tag. If you meant to tag the object that it points to, use:
1731 hint: git tag -f nested annotated-v4.0^{}
1732 hint: Disable this message with "git config advice.nestedTag false"
1734 git tag -m nested nested annotated-v4.0 2>actual &&
1735 test_i18ncmp expect actual
1738 test_expect_success 'multiple --points-at are OR-ed together' '
1739 cat >expect <<-\EOF &&
1743 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1744 test_cmp expect actual
1747 test_expect_success 'lexical sort' '
1751 git tag -l --sort=refname "foo*" >actual &&
1752 cat >expect <<-\EOF &&
1757 test_cmp expect actual
1760 test_expect_success 'version sort' '
1761 git tag -l --sort=version:refname "foo*" >actual &&
1762 cat >expect <<-\EOF &&
1767 test_cmp expect actual
1770 test_expect_success 'reverse version sort' '
1771 git tag -l --sort=-version:refname "foo*" >actual &&
1772 cat >expect <<-\EOF &&
1777 test_cmp expect actual
1780 test_expect_success 'reverse lexical sort' '
1781 git tag -l --sort=-refname "foo*" >actual &&
1782 cat >expect <<-\EOF &&
1787 test_cmp expect actual
1790 test_expect_success 'configured lexical sort' '
1791 test_config tag.sort "v:refname" &&
1792 git tag -l "foo*" >actual &&
1793 cat >expect <<-\EOF &&
1798 test_cmp expect actual
1801 test_expect_success 'option override configured sort' '
1802 test_config tag.sort "v:refname" &&
1803 git tag -l --sort=-refname "foo*" >actual &&
1804 cat >expect <<-\EOF &&
1809 test_cmp expect actual
1812 test_expect_success 'invalid sort parameter on command line' '
1813 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1816 test_expect_success 'invalid sort parameter in configuratoin' '
1817 test_config tag.sort "v:notvalid" &&
1818 test_must_fail git tag -l "foo*"
1821 test_expect_success 'version sort with prerelease reordering' '
1822 test_config versionsort.prereleaseSuffix -rc &&
1823 git tag foo1.6-rc1 &&
1824 git tag foo1.6-rc2 &&
1825 git tag -l --sort=version:refname "foo*" >actual &&
1826 cat >expect <<-\EOF &&
1833 test_cmp expect actual
1836 test_expect_success 'reverse version sort with prerelease reordering' '
1837 test_config versionsort.prereleaseSuffix -rc &&
1838 git tag -l --sort=-version:refname "foo*" >actual &&
1839 cat >expect <<-\EOF &&
1846 test_cmp expect actual
1849 test_expect_success 'version sort with prerelease reordering and common leading character' '
1850 test_config versionsort.prereleaseSuffix -before &&
1851 git tag foo1.7-before1 &&
1853 git tag foo1.7-after1 &&
1854 git tag -l --sort=version:refname "foo1.7*" >actual &&
1855 cat >expect <<-\EOF &&
1860 test_cmp expect actual
1863 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1864 test_config versionsort.prereleaseSuffix -before &&
1865 git config --add versionsort.prereleaseSuffix -after &&
1866 git tag -l --sort=version:refname "foo1.7*" >actual &&
1867 cat >expect <<-\EOF &&
1872 test_cmp expect actual
1875 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1876 test_config versionsort.prereleaseSuffix -bar &&
1877 git config --add versionsort.prereleaseSuffix -foo-baz &&
1878 git config --add versionsort.prereleaseSuffix -foo-bar &&
1879 git tag foo1.8-foo-bar &&
1880 git tag foo1.8-foo-baz &&
1882 git tag -l --sort=version:refname "foo1.8*" >actual &&
1883 cat >expect <<-\EOF &&
1888 test_cmp expect actual
1891 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1892 test_config versionsort.prereleaseSuffix -pre &&
1893 git config --add versionsort.prereleaseSuffix -prerelease &&
1894 git tag foo1.9-pre1 &&
1895 git tag foo1.9-pre2 &&
1896 git tag foo1.9-prerelease1 &&
1897 git tag -l --sort=version:refname "foo1.9*" >actual &&
1898 cat >expect <<-\EOF &&
1903 test_cmp expect actual
1906 test_expect_success 'version sort with general suffix reordering' '
1907 test_config versionsort.suffix -alpha &&
1908 git config --add versionsort.suffix -beta &&
1909 git config --add versionsort.suffix "" &&
1910 git config --add versionsort.suffix -gamma &&
1911 git config --add versionsort.suffix -delta &&
1912 git tag foo1.10-alpha &&
1913 git tag foo1.10-beta &&
1914 git tag foo1.10-gamma &&
1915 git tag foo1.10-delta &&
1916 git tag foo1.10-unlisted-suffix &&
1917 git tag -l --sort=version:refname "foo1.10*" >actual &&
1918 cat >expect <<-\EOF &&
1922 foo1.10-unlisted-suffix
1926 test_cmp expect actual
1929 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1930 test_config versionsort.suffix -before &&
1931 test_config versionsort.prereleaseSuffix -after &&
1932 git tag -l --sort=version:refname "foo1.7*" >actual &&
1933 cat >expect <<-\EOF &&
1938 test_cmp expect actual
1941 test_expect_success 'version sort with very long prerelease suffix' '
1942 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1943 git tag -l --sort=version:refname
1946 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1948 while test $i -lt 8000
1950 echo "commit refs/heads/main
1951 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1955 test $i = 1 && echo "from refs/heads/main^0"
1957 done | git fast-import &&
1958 git checkout main &&
1959 git tag far-far-away HEAD^ &&
1960 run_with_limited_stack git tag --contains HEAD >actual &&
1961 test_must_be_empty actual &&
1962 run_with_limited_stack git tag --no-contains HEAD >actual &&
1963 test_line_count "-gt" 10 actual
1966 test_expect_success '--format should list tags as per format given' '
1967 cat >expect <<-\EOF &&
1968 refname : refs/tags/v1.0
1969 refname : refs/tags/v1.0.1
1970 refname : refs/tags/v1.1.3
1972 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1973 test_cmp expect actual
1976 test_expect_success "set up color tests" '
1977 echo "<RED>v1.0<RESET>" >expect.color &&
1978 echo "v1.0" >expect.bare &&
1979 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1982 test_expect_success '%(color) omitted without tty' '
1983 TERM=vt100 git tag $color_args >actual.raw &&
1984 test_decode_color <actual.raw >actual &&
1985 test_cmp expect.bare actual
1988 test_expect_success TTY '%(color) present with tty' '
1989 test_terminal git tag $color_args >actual.raw &&
1990 test_decode_color <actual.raw >actual &&
1991 test_cmp expect.color actual
1994 test_expect_success '--color overrides auto-color' '
1995 git tag --color $color_args >actual.raw &&
1996 test_decode_color <actual.raw >actual &&
1997 test_cmp expect.color actual
2000 test_expect_success 'color.ui=always overrides auto-color' '
2001 git -c color.ui=always tag $color_args >actual.raw &&
2002 test_decode_color <actual.raw >actual &&
2003 test_cmp expect.color actual
2006 test_expect_success 'setup --merged test tags' '
2007 git tag mergetest-1 HEAD~2 &&
2008 git tag mergetest-2 HEAD~1 &&
2009 git tag mergetest-3 HEAD
2012 test_expect_success '--merged can be used in non-list mode' '
2013 cat >expect <<-\EOF &&
2017 git tag --merged=mergetest-2 "mergetest*" >actual &&
2018 test_cmp expect actual
2021 test_expect_success '--merged is compatible with --no-merged' '
2022 git tag --merged HEAD --no-merged HEAD
2025 test_expect_success '--merged shows merged tags' '
2026 cat >expect <<-\EOF &&
2030 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2031 test_cmp expect actual
2034 test_expect_success '--no-merged show unmerged tags' '
2035 cat >expect <<-\EOF &&
2038 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2039 test_cmp expect actual
2042 test_expect_success '--no-merged can be used in non-list mode' '
2043 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2044 test_cmp expect actual
2047 test_expect_success 'ambiguous branch/tags not marked' '
2048 git tag ambiguous &&
2049 git branch ambiguous &&
2050 echo ambiguous >expect &&
2051 git tag -l ambiguous >actual &&
2052 test_cmp expect actual
2055 test_expect_success '--contains combined with --no-contains' '
2057 git init no-contains &&
2064 cat >expected <<-\EOF &&
2069 git tag --contains v0.2 --no-contains v0.5 >actual &&
2070 test_cmp expected actual
2074 # As the docs say, list tags which contain a specified *commit*. We
2075 # don't recurse down to tags for trees or blobs pointed to by *those*
2077 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2079 blob=$(git rev-parse v0.3:v0.3.t) &&
2080 tree=$(git rev-parse v0.3^{tree}) &&
2081 git tag tag-blob $blob &&
2082 git tag tag-tree $tree &&
2083 git tag --contains v0.3 >actual &&
2084 cat >expected <<-\EOF &&
2089 test_cmp expected actual &&
2090 git tag --no-contains v0.3 >actual &&
2091 cat >expected <<-\EOF &&
2095 test_cmp expected actual