3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
11 . "$TEST_DIRECTORY"/lib-gpg.sh
12 . "$TEST_DIRECTORY"/lib-terminal.sh
14 # creating and listing lightweight tags:
17 git show-ref --quiet --verify refs/tags/"$1"
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' '
74 test_config core.logAllRefUpdates true &&
80 test_must_fail git reflog exists refs/tags/mytag
83 test_expect_success 'creating a tag with --create-reflog should create reflog' '
85 --format="format:tag: tagging %h (%s, %cd)%n" \
86 --date=format:%Y-%m-%d >expected &&
87 test_when_finished "git tag -d tag_with_reflog" &&
88 git tag --create-reflog tag_with_reflog &&
89 git reflog exists refs/tags/tag_with_reflog &&
90 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
91 test_i18ncmp expected actual
94 test_expect_success 'annotated tag with --create-reflog has correct message' '
96 --format="format:tag: tagging %h (%s, %cd)%n" \
97 --date=format:%Y-%m-%d >expected &&
98 test_when_finished "git tag -d tag_with_reflog" &&
99 git tag -m "annotated tag" --create-reflog tag_with_reflog &&
100 git reflog exists refs/tags/tag_with_reflog &&
101 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
102 test_i18ncmp expected actual
105 test_expect_success '--create-reflog does not create reflog on failure' '
106 test_must_fail git tag --create-reflog mytag &&
107 test_must_fail git reflog exists refs/tags/mytag
110 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
111 test_when_finished "git tag -d tag_with_reflog" &&
112 test_config core.logAllRefUpdates always &&
113 git tag tag_with_reflog &&
114 git reflog exists refs/tags/tag_with_reflog
117 test_expect_success 'listing all tags if one exists should succeed' '
125 test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
126 git tag -l -l >actual &&
127 test_cmp expect actual &&
128 git tag --list --list >actual &&
129 test_cmp expect actual &&
130 git tag --list -l --list >actual &&
131 test_cmp expect actual
134 test_expect_success 'listing all tags if one exists should output that tag' '
135 test $(git tag -l) = mytag &&
136 test $(git tag) = mytag
141 test_expect_success 'listing a tag using a matching pattern should succeed' \
144 test_expect_success 'listing a tag with --ignore-case' \
145 'test $(git tag -l --ignore-case MYTAG) = mytag'
147 test_expect_success \
148 'listing a tag using a matching pattern should output that tag' \
149 'test $(git tag -l mytag) = mytag'
151 test_expect_success \
152 'listing tags using a non-matching pattern should succeed' \
155 test_expect_success \
156 'listing tags using a non-matching pattern should output nothing' \
157 'test $(git tag -l xxx | wc -l) -eq 0'
159 # special cases for creating tags:
161 test_expect_success \
162 'trying to create a tag with the name of one existing should fail' \
163 'test_must_fail git tag mytag'
165 test_expect_success \
166 'trying to create a tag with a non-valid name should fail' '
167 test $(git tag -l | wc -l) -eq 1 &&
168 test_must_fail git tag "" &&
169 test_must_fail git tag .othertag &&
170 test_must_fail git tag "other tag" &&
171 test_must_fail git tag "othertag^" &&
172 test_must_fail git tag "other~tag" &&
173 test $(git tag -l | wc -l) -eq 1
176 test_expect_success 'creating a tag using HEAD directly should succeed' '
177 git tag myhead HEAD &&
181 test_expect_success '--force can create a tag with the name of one existing' '
183 git tag --force mytag &&
186 test_expect_success '--force is moot with a non-existing tag name' '
187 test_when_finished git tag -d newtag forcetag &&
188 git tag newtag >expect &&
189 git tag --force forcetag >actual &&
190 test_cmp expect actual
195 test_expect_success 'trying to delete an unknown tag should fail' '
196 ! tag_exists unknown-tag &&
197 test_must_fail git tag -d unknown-tag
204 test_expect_success \
205 'trying to delete tags without params should succeed and do nothing' '
206 git tag -l > actual && test_cmp expect actual &&
208 git tag -l > actual && test_cmp expect actual
211 test_expect_success \
212 'deleting two existing tags in one command should succeed' '
215 git tag -d mytag myhead &&
216 ! tag_exists mytag &&
220 test_expect_success \
221 'creating a tag with the name of another deleted one should succeed' '
222 ! tag_exists mytag &&
227 test_expect_success \
228 'trying to delete two tags, existing and not, should fail in the 2nd' '
230 ! tag_exists myhead &&
231 test_must_fail git tag -d mytag anothertag &&
232 ! tag_exists mytag &&
236 test_expect_success 'trying to delete an already deleted tag should fail' \
237 'test_must_fail git tag -d mytag'
239 # listing various tags with pattern matching:
252 test_expect_success 'listing all tags should print them ordered' '
262 git tag -l > actual &&
263 test_cmp expect actual &&
265 test_cmp expect actual
273 test_expect_success \
274 'listing tags with substring as pattern must print those matching' '
276 git tag -l "*a*" > current &&
277 test_cmp expect current
284 test_expect_success \
285 'listing tags with a suffix as pattern must print those matching' '
286 git tag -l "*.1" > actual &&
287 test_cmp expect actual
294 test_expect_success \
295 'listing tags with a prefix as pattern must print those matching' '
296 git tag -l "t21*" > actual &&
297 test_cmp expect actual
303 test_expect_success \
304 'listing tags using a name as pattern must print that one matching' '
305 git tag -l a1 > actual &&
306 test_cmp expect actual
312 test_expect_success \
313 'listing tags using a name as pattern must print that one matching' '
314 git tag -l v1.0 > actual &&
315 test_cmp expect actual
322 test_expect_success \
323 'listing tags with ? in the pattern should print those matching' '
324 git tag -l "v1.?.?" > actual &&
325 test_cmp expect actual
328 test_expect_success \
329 'listing tags using v.* should print nothing because none have v.' '
330 git tag -l "v.*" > actual &&
331 test_must_be_empty actual
340 test_expect_success \
341 'listing tags using v* should print only those having v' '
342 git tag -l "v*" > actual &&
343 test_cmp expect actual
346 test_expect_success 'tag -l can accept multiple patterns' '
347 git tag -l "v1*" "v0*" >actual &&
348 test_cmp expect actual
351 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
352 # could leave you with the impression that "-l <pattern> -l <pattern>"
353 # was how we wanted to accept multiple patterns.
355 # This test should not imply that this is a sane thing to support. but
356 # since the documentation was worded like it was let's at least find
357 # out if we're going to break this long-documented form of taking
359 test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
360 git tag -l "v1*" -l "v0*" >actual &&
361 test_cmp expect actual
364 test_expect_success 'listing tags in column' '
365 COLUMNS=41 git tag -l --column=row >actual &&
366 cat >expected <<\EOF &&
368 v0.2.1 v1.0 v1.0.1 v1.1.3
370 test_cmp expected actual
373 test_expect_success 'listing tags in column with column.*' '
374 test_config column.tag row &&
375 test_config column.ui dense &&
376 COLUMNS=40 git tag -l >actual &&
377 cat >expected <<\EOF &&
379 v0.2.1 v1.0 v1.0.1 v1.1.3
381 test_cmp expected actual
384 test_expect_success 'listing tag with -n --column should fail' '
385 test_must_fail git tag --column -n
388 test_expect_success 'listing tags -n in column with column.ui ignored' '
389 test_config column.ui "row dense" &&
390 COLUMNS=40 git tag -l -n >actual &&
391 cat >expected <<\EOF &&
402 test_cmp expected actual
405 # creating and verifying lightweight tags:
407 test_expect_success \
408 'a non-annotated tag created without parameters should point to HEAD' '
409 git tag non-annotated-tag &&
410 test $(git cat-file -t non-annotated-tag) = commit &&
411 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
414 test_expect_success 'trying to verify an unknown tag should fail' \
415 'test_must_fail git tag -v unknown-tag'
417 test_expect_success \
418 'trying to verify a non-annotated and non-signed tag should fail' \
419 'test_must_fail git tag -v non-annotated-tag'
421 test_expect_success \
422 'trying to verify many non-annotated or unknown tags, should fail' \
423 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
425 # creating annotated tags:
428 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
431 # run test_tick before committing always gives the time in that timezone
437 tagger C O Mitter <committer@example.com> $4 -0700
442 commit=$(git rev-parse HEAD)
445 get_tag_header annotated-tag $commit commit $time >expect
446 echo "A message" >>expect
447 test_expect_success \
448 'creating an annotated tag with -m message should succeed' '
449 git tag -m "A message" annotated-tag &&
450 get_tag_msg annotated-tag >actual &&
451 test_cmp expect actual
454 get_tag_header annotated-tag-edit $commit commit $time >expect
455 echo "An edited message" >>expect
456 test_expect_success 'set up editor' '
457 write_script fakeeditor <<-\EOF
458 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
462 test_expect_success \
463 'creating an annotated tag with -m message --edit should succeed' '
464 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
465 get_tag_msg annotated-tag-edit >actual &&
466 test_cmp expect actual
473 get_tag_header file-annotated-tag $commit commit $time >expect
475 test_expect_success \
476 'creating an annotated tag with -F messagefile should succeed' '
477 git tag -F msgfile file-annotated-tag &&
478 get_tag_msg file-annotated-tag >actual &&
479 test_cmp expect actual
482 get_tag_header file-annotated-tag-edit $commit commit $time >expect
483 sed -e "s/Another message/Another edited message/g" msgfile >>expect
484 test_expect_success 'set up editor' '
485 write_script fakeeditor <<-\EOF
486 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
490 test_expect_success \
491 'creating an annotated tag with -F messagefile --edit should succeed' '
492 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
493 get_tag_msg file-annotated-tag-edit >actual &&
494 test_cmp expect actual
501 get_tag_header stdin-annotated-tag $commit commit $time >expect
502 cat inputmsg >>expect
503 test_expect_success 'creating an annotated tag with -F - should succeed' '
504 git tag -F - stdin-annotated-tag <inputmsg &&
505 get_tag_msg stdin-annotated-tag >actual &&
506 test_cmp expect actual
509 test_expect_success \
510 'trying to create a tag with a non-existing -F file should fail' '
511 ! test -f nonexistingfile &&
512 ! tag_exists notag &&
513 test_must_fail git tag -F nonexistingfile notag &&
517 test_expect_success \
518 'trying to create tags giving both -m or -F options should fail' '
519 echo "message file 1" >msgfile1 &&
520 echo "message file 2" >msgfile2 &&
521 ! tag_exists msgtag &&
522 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
523 ! tag_exists msgtag &&
524 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
525 ! tag_exists msgtag &&
526 test_must_fail git tag -m "message 1" -F msgfile1 \
527 -m "message 2" msgtag &&
531 # blank and empty messages:
533 get_tag_header empty-annotated-tag $commit commit $time >expect
534 test_expect_success \
535 'creating a tag with an empty -m message should succeed' '
536 git tag -m "" empty-annotated-tag &&
537 get_tag_msg empty-annotated-tag >actual &&
538 test_cmp expect actual
542 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
543 test_expect_success \
544 'creating a tag with an empty -F messagefile should succeed' '
545 git tag -F emptyfile emptyfile-annotated-tag &&
546 get_tag_msg emptyfile-annotated-tag >actual &&
547 test_cmp expect actual
550 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
551 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
552 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
553 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
554 get_tag_header blanks-annotated-tag $commit commit $time >expect
564 test_expect_success \
565 'extra blanks in the message for an annotated tag should be removed' '
566 git tag -F blanksfile blanks-annotated-tag &&
567 get_tag_msg blanks-annotated-tag >actual &&
568 test_cmp expect actual
571 get_tag_header blank-annotated-tag $commit commit $time >expect
572 test_expect_success \
573 'creating a tag with blank -m message with spaces should succeed' '
574 git tag -m " " blank-annotated-tag &&
575 get_tag_msg blank-annotated-tag >actual &&
576 test_cmp expect actual
582 get_tag_header blankfile-annotated-tag $commit commit $time >expect
583 test_expect_success \
584 'creating a tag with blank -F messagefile with spaces should succeed' '
585 git tag -F blankfile blankfile-annotated-tag &&
586 get_tag_msg blankfile-annotated-tag >actual &&
587 test_cmp expect actual
590 printf ' ' >blanknonlfile
591 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
592 test_expect_success \
593 'creating a tag with -F file of spaces and no newline should succeed' '
594 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
595 get_tag_msg blanknonlfile-annotated-tag >actual &&
596 test_cmp expect actual
599 # messages with commented lines:
601 cat >commentsfile <<EOF
618 get_tag_header comments-annotated-tag $commit commit $time >expect
627 test_expect_success \
628 'creating a tag using a -F messagefile with #comments should succeed' '
629 git tag -F commentsfile comments-annotated-tag &&
630 get_tag_msg comments-annotated-tag >actual &&
631 test_cmp expect actual
634 get_tag_header comment-annotated-tag $commit commit $time >expect
635 test_expect_success \
636 'creating a tag with a #comment in the -m message should succeed' '
637 git tag -m "#comment" comment-annotated-tag &&
638 get_tag_msg comment-annotated-tag >actual &&
639 test_cmp expect actual
642 echo '#comment' >commentfile
643 echo '' >>commentfile
644 echo '####' >>commentfile
645 get_tag_header commentfile-annotated-tag $commit commit $time >expect
646 test_expect_success \
647 'creating a tag with #comments in the -F messagefile should succeed' '
648 git tag -F commentfile commentfile-annotated-tag &&
649 get_tag_msg commentfile-annotated-tag >actual &&
650 test_cmp expect actual
653 printf '#comment' >commentnonlfile
654 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
655 test_expect_success \
656 'creating a tag with a file of #comment and no newline should succeed' '
657 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
658 get_tag_msg commentnonlfile-annotated-tag >actual &&
659 test_cmp expect actual
662 # listing messages for annotated non-signed tags:
664 test_expect_success \
665 'listing the one-line message of a non-signed tag should succeed' '
666 git tag -m "A msg" tag-one-line &&
668 echo "tag-one-line" >expect &&
669 git tag -l | grep "^tag-one-line" >actual &&
670 test_cmp expect actual &&
671 git tag -n0 -l | grep "^tag-one-line" >actual &&
672 test_cmp expect actual &&
673 git tag -n0 -l tag-one-line >actual &&
674 test_cmp expect actual &&
676 git tag -n0 | grep "^tag-one-line" >actual &&
677 test_cmp expect actual &&
678 git tag -n0 tag-one-line >actual &&
679 test_cmp expect actual &&
681 echo "tag-one-line A msg" >expect &&
682 git tag -n1 -l | grep "^tag-one-line" >actual &&
683 test_cmp expect actual &&
684 git tag -n -l | grep "^tag-one-line" >actual &&
685 test_cmp expect actual &&
686 git tag -n1 -l tag-one-line >actual &&
687 test_cmp expect actual &&
688 git tag -n2 -l tag-one-line >actual &&
689 test_cmp expect actual &&
690 git tag -n999 -l tag-one-line >actual &&
691 test_cmp expect actual
694 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
695 git tag -n 100 >actual &&
696 test_must_be_empty actual &&
698 git tag -m "A msg" 100 &&
699 echo "100 A msg" >expect &&
700 git tag -n 100 >actual &&
701 test_cmp expect actual
704 test_expect_success \
705 'listing the zero-lines message of a non-signed tag should succeed' '
706 git tag -m "" tag-zero-lines &&
708 echo "tag-zero-lines" >expect &&
709 git tag -l | grep "^tag-zero-lines" >actual &&
710 test_cmp expect actual &&
711 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
712 test_cmp expect actual &&
713 git tag -n0 -l tag-zero-lines >actual &&
714 test_cmp expect actual &&
716 echo "tag-zero-lines " >expect &&
717 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
718 test_cmp expect actual &&
719 git tag -n -l | grep "^tag-zero-lines" >actual &&
720 test_cmp expect actual &&
721 git tag -n1 -l tag-zero-lines >actual &&
722 test_cmp expect actual &&
723 git tag -n2 -l tag-zero-lines >actual &&
724 test_cmp expect actual &&
725 git tag -n999 -l tag-zero-lines >actual &&
726 test_cmp expect actual
729 echo 'tag line one' >annotagmsg
730 echo 'tag line two' >>annotagmsg
731 echo 'tag line three' >>annotagmsg
732 test_expect_success \
733 'listing many message lines of a non-signed tag should succeed' '
734 git tag -F annotagmsg tag-lines &&
736 echo "tag-lines" >expect &&
737 git tag -l | grep "^tag-lines" >actual &&
738 test_cmp expect actual &&
739 git tag -n0 -l | grep "^tag-lines" >actual &&
740 test_cmp expect actual &&
741 git tag -n0 -l tag-lines >actual &&
742 test_cmp expect actual &&
744 echo "tag-lines tag line one" >expect &&
745 git tag -n1 -l | grep "^tag-lines" >actual &&
746 test_cmp expect actual &&
747 git tag -n -l | grep "^tag-lines" >actual &&
748 test_cmp expect actual &&
749 git tag -n1 -l tag-lines >actual &&
750 test_cmp expect actual &&
752 echo " tag line two" >>expect &&
753 git tag -n2 -l | grep "^ *tag.line" >actual &&
754 test_cmp expect actual &&
755 git tag -n2 -l tag-lines >actual &&
756 test_cmp expect actual &&
758 echo " tag line three" >>expect &&
759 git tag -n3 -l | grep "^ *tag.line" >actual &&
760 test_cmp expect actual &&
761 git tag -n3 -l tag-lines >actual &&
762 test_cmp expect actual &&
763 git tag -n4 -l | grep "^ *tag.line" >actual &&
764 test_cmp expect actual &&
765 git tag -n4 -l tag-lines >actual &&
766 test_cmp expect actual &&
767 git tag -n99 -l | grep "^ *tag.line" >actual &&
768 test_cmp expect actual &&
769 git tag -n99 -l tag-lines >actual &&
770 test_cmp expect actual
773 test_expect_success 'annotations for blobs are empty' '
774 blob=$(git hash-object -w --stdin <<-\EOF
780 git tag tag-blob $blob &&
781 echo "tag-blob " >expect &&
782 git tag -n1 -l tag-blob >actual &&
783 test_cmp expect actual
786 # trying to verify annotated non-signed tags:
788 test_expect_success GPG \
789 'trying to verify an annotated non-signed tag should fail' '
790 tag_exists annotated-tag &&
791 test_must_fail git tag -v annotated-tag
794 test_expect_success GPG \
795 'trying to verify a file-annotated non-signed tag should fail' '
796 tag_exists file-annotated-tag &&
797 test_must_fail git tag -v file-annotated-tag
800 test_expect_success GPG \
801 'trying to verify two annotated non-signed tags should fail' '
802 tag_exists annotated-tag file-annotated-tag &&
803 test_must_fail git tag -v annotated-tag file-annotated-tag
806 # creating and verifying signed tags:
808 get_tag_header signed-tag $commit commit $time >expect
809 echo 'A signed tag message' >>expect
810 echo '-----BEGIN PGP SIGNATURE-----' >>expect
811 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
812 git tag -s -m "A signed tag message" signed-tag &&
813 get_tag_msg signed-tag >actual &&
814 test_cmp expect actual
817 get_tag_header u-signed-tag $commit commit $time >expect
818 echo 'Another message' >>expect
819 echo '-----BEGIN PGP SIGNATURE-----' >>expect
820 test_expect_success GPG 'sign with a given key id' '
822 git tag -u committer@example.com -m "Another message" u-signed-tag &&
823 get_tag_msg u-signed-tag >actual &&
824 test_cmp expect actual
828 test_expect_success GPG 'sign with an unknown id (1)' '
830 test_must_fail git tag -u author@example.com \
831 -m "Another message" o-signed-tag
835 test_expect_success GPG 'sign with an unknown id (2)' '
837 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
841 cat >fakeeditor <<'EOF'
843 test -n "$1" && exec >"$1"
844 echo A signed tag message
845 echo from a fake editor.
849 get_tag_header implied-sign $commit commit $time >expect
850 ./fakeeditor >>expect
851 echo '-----BEGIN PGP SIGNATURE-----' >>expect
852 test_expect_success GPG '-u implies signed tag' '
853 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
854 get_tag_msg implied-sign >actual &&
855 test_cmp expect actual
858 cat >sigmsgfile <<EOF
862 get_tag_header file-signed-tag $commit commit $time >expect
863 cat sigmsgfile >>expect
864 echo '-----BEGIN PGP SIGNATURE-----' >>expect
865 test_expect_success GPG \
866 'creating a signed tag with -F messagefile should succeed' '
867 git tag -s -F sigmsgfile file-signed-tag &&
868 get_tag_msg file-signed-tag >actual &&
869 test_cmp expect actual
872 cat >siginputmsg <<EOF
873 A signed tag message from
876 get_tag_header stdin-signed-tag $commit commit $time >expect
877 cat siginputmsg >>expect
878 echo '-----BEGIN PGP SIGNATURE-----' >>expect
879 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
880 git tag -s -F - stdin-signed-tag <siginputmsg &&
881 get_tag_msg stdin-signed-tag >actual &&
882 test_cmp expect actual
885 get_tag_header implied-annotate $commit commit $time >expect
886 ./fakeeditor >>expect
887 echo '-----BEGIN PGP SIGNATURE-----' >>expect
888 test_expect_success GPG '-s implies annotated tag' '
889 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
890 get_tag_msg implied-annotate >actual &&
891 test_cmp expect actual
894 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
895 echo "A message" >>expect
896 echo '-----BEGIN PGP SIGNATURE-----' >>expect
897 test_expect_success GPG \
898 'git tag -s implied if configured with tag.forcesignannotated' \
899 'test_config tag.forcesignannotated true &&
900 git tag -m "A message" forcesignannotated-implied-sign &&
901 get_tag_msg forcesignannotated-implied-sign >actual &&
902 test_cmp expect actual
905 test_expect_success GPG \
906 'lightweight with no message when configured with tag.forcesignannotated' \
907 'test_config tag.forcesignannotated true &&
908 git tag forcesignannotated-lightweight &&
909 tag_exists forcesignannotated-lightweight &&
910 test_must_fail git tag -v forcesignannotated-no-message
913 get_tag_header forcesignannotated-annotate $commit commit $time >expect
914 echo "A message" >>expect
915 test_expect_success GPG \
916 'git tag -a disable configured tag.forcesignannotated' \
917 'test_config tag.forcesignannotated true &&
918 git tag -a -m "A message" forcesignannotated-annotate &&
919 get_tag_msg forcesignannotated-annotate >actual &&
920 test_cmp expect actual &&
921 test_must_fail git tag -v forcesignannotated-annotate
924 get_tag_header forcesignannotated-disabled $commit commit $time >expect
925 echo "A message" >>expect
926 echo '-----BEGIN PGP SIGNATURE-----' >>expect
927 test_expect_success GPG \
928 'git tag --sign enable GPG sign' \
929 'test_config tag.forcesignannotated false &&
930 git tag --sign -m "A message" forcesignannotated-disabled &&
931 get_tag_msg forcesignannotated-disabled >actual &&
932 test_cmp expect actual
935 test_expect_success GPG \
936 'trying to create a signed tag with non-existing -F file should fail' '
937 ! test -f nonexistingfile &&
938 ! tag_exists nosigtag &&
939 test_must_fail git tag -s -F nonexistingfile nosigtag &&
940 ! tag_exists nosigtag
943 test_expect_success GPG 'verifying a signed tag should succeed' \
944 'git tag -v signed-tag'
946 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
947 'git tag -v signed-tag file-signed-tag'
949 test_expect_success GPG \
950 'verifying many signed and non-signed tags should fail' '
951 test_must_fail git tag -v signed-tag annotated-tag &&
952 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
953 test_must_fail git tag -v annotated-tag \
954 file-signed-tag file-annotated-tag &&
955 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
958 test_expect_success GPG 'verifying a forged tag should fail' '
959 forged=$(git cat-file tag signed-tag |
960 sed -e "s/signed-tag/forged-tag/" |
962 git tag forged-tag $forged &&
963 test_must_fail git tag -v forged-tag
966 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
967 cat >expect <<-\EOF &&
970 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
971 test_cmp expect actual
974 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
975 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
976 test_must_be_empty actual
979 # blank and empty messages for signed tags:
981 get_tag_header empty-signed-tag $commit commit $time >expect
982 echo '-----BEGIN PGP SIGNATURE-----' >>expect
983 test_expect_success GPG \
984 'creating a signed tag with an empty -m message should succeed' '
985 git tag -s -m "" empty-signed-tag &&
986 get_tag_msg empty-signed-tag >actual &&
987 test_cmp expect actual &&
988 git tag -v empty-signed-tag
992 get_tag_header emptyfile-signed-tag $commit commit $time >expect
993 echo '-----BEGIN PGP SIGNATURE-----' >>expect
994 test_expect_success GPG \
995 'creating a signed tag with an empty -F messagefile should succeed' '
996 git tag -s -F sigemptyfile emptyfile-signed-tag &&
997 get_tag_msg emptyfile-signed-tag >actual &&
998 test_cmp expect actual &&
999 git tag -v emptyfile-signed-tag
1002 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1003 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1004 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1005 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1006 get_tag_header blanks-signed-tag $commit commit $time >expect
1010 Repeated blank lines
1014 Trailing blank lines
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success GPG \
1018 'extra blanks in the message for a signed tag should be removed' '
1019 git tag -s -F sigblanksfile blanks-signed-tag &&
1020 get_tag_msg blanks-signed-tag >actual &&
1021 test_cmp expect actual &&
1022 git tag -v blanks-signed-tag
1025 get_tag_header blank-signed-tag $commit commit $time >expect
1026 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1027 test_expect_success GPG \
1028 'creating a signed tag with a blank -m message should succeed' '
1029 git tag -s -m " " blank-signed-tag &&
1030 get_tag_msg blank-signed-tag >actual &&
1031 test_cmp expect actual &&
1032 git tag -v blank-signed-tag
1035 echo ' ' >sigblankfile
1036 echo '' >>sigblankfile
1037 echo ' ' >>sigblankfile
1038 get_tag_header blankfile-signed-tag $commit commit $time >expect
1039 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1040 test_expect_success GPG \
1041 'creating a signed tag with blank -F file with spaces should succeed' '
1042 git tag -s -F sigblankfile blankfile-signed-tag &&
1043 get_tag_msg blankfile-signed-tag >actual &&
1044 test_cmp expect actual &&
1045 git tag -v blankfile-signed-tag
1048 printf ' ' >sigblanknonlfile
1049 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1050 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1051 test_expect_success GPG \
1052 'creating a signed tag with spaces and no newline should succeed' '
1053 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1054 get_tag_msg blanknonlfile-signed-tag >actual &&
1055 test_cmp expect actual &&
1056 git tag -v blanknonlfile-signed-tag
1059 test_expect_success GPG 'signed tag with embedded PGP message' '
1061 -----BEGIN PGP MESSAGE-----
1063 this is not a real PGP message
1064 -----END PGP MESSAGE-----
1066 git tag -s -F msg confusing-pgp-message &&
1067 git tag -v confusing-pgp-message
1070 # messages with commented lines for signed tags:
1072 cat >sigcommentsfile <<EOF
1089 get_tag_header comments-signed-tag $commit commit $time >expect
1098 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1099 test_expect_success GPG \
1100 'creating a signed tag with a -F file with #comments should succeed' '
1101 git tag -s -F sigcommentsfile comments-signed-tag &&
1102 get_tag_msg comments-signed-tag >actual &&
1103 test_cmp expect actual &&
1104 git tag -v comments-signed-tag
1107 get_tag_header comment-signed-tag $commit commit $time >expect
1108 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1109 test_expect_success GPG \
1110 'creating a signed tag with #commented -m message should succeed' '
1111 git tag -s -m "#comment" comment-signed-tag &&
1112 get_tag_msg comment-signed-tag >actual &&
1113 test_cmp expect actual &&
1114 git tag -v comment-signed-tag
1117 echo '#comment' >sigcommentfile
1118 echo '' >>sigcommentfile
1119 echo '####' >>sigcommentfile
1120 get_tag_header commentfile-signed-tag $commit commit $time >expect
1121 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1122 test_expect_success GPG \
1123 'creating a signed tag with #commented -F messagefile should succeed' '
1124 git tag -s -F sigcommentfile commentfile-signed-tag &&
1125 get_tag_msg commentfile-signed-tag >actual &&
1126 test_cmp expect actual &&
1127 git tag -v commentfile-signed-tag
1130 printf '#comment' >sigcommentnonlfile
1131 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1132 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1133 test_expect_success GPG \
1134 'creating a signed tag with a #comment and no newline should succeed' '
1135 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1136 get_tag_msg commentnonlfile-signed-tag >actual &&
1137 test_cmp expect actual &&
1138 git tag -v commentnonlfile-signed-tag
1141 # listing messages for signed tags:
1143 test_expect_success GPG \
1144 'listing the one-line message of a signed tag should succeed' '
1145 git tag -s -m "A message line signed" stag-one-line &&
1147 echo "stag-one-line" >expect &&
1148 git tag -l | grep "^stag-one-line" >actual &&
1149 test_cmp expect actual &&
1150 git tag -n0 -l | grep "^stag-one-line" >actual &&
1151 test_cmp expect actual &&
1152 git tag -n0 -l stag-one-line >actual &&
1153 test_cmp expect actual &&
1155 echo "stag-one-line A message line signed" >expect &&
1156 git tag -n1 -l | grep "^stag-one-line" >actual &&
1157 test_cmp expect actual &&
1158 git tag -n -l | grep "^stag-one-line" >actual &&
1159 test_cmp expect actual &&
1160 git tag -n1 -l stag-one-line >actual &&
1161 test_cmp expect actual &&
1162 git tag -n2 -l stag-one-line >actual &&
1163 test_cmp expect actual &&
1164 git tag -n999 -l stag-one-line >actual &&
1165 test_cmp expect actual
1168 test_expect_success GPG \
1169 'listing the zero-lines message of a signed tag should succeed' '
1170 git tag -s -m "" stag-zero-lines &&
1172 echo "stag-zero-lines" >expect &&
1173 git tag -l | grep "^stag-zero-lines" >actual &&
1174 test_cmp expect actual &&
1175 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1176 test_cmp expect actual &&
1177 git tag -n0 -l stag-zero-lines >actual &&
1178 test_cmp expect actual &&
1180 echo "stag-zero-lines " >expect &&
1181 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1182 test_cmp expect actual &&
1183 git tag -n -l | grep "^stag-zero-lines" >actual &&
1184 test_cmp expect actual &&
1185 git tag -n1 -l stag-zero-lines >actual &&
1186 test_cmp expect actual &&
1187 git tag -n2 -l stag-zero-lines >actual &&
1188 test_cmp expect actual &&
1189 git tag -n999 -l stag-zero-lines >actual &&
1190 test_cmp expect actual
1193 echo 'stag line one' >sigtagmsg
1194 echo 'stag line two' >>sigtagmsg
1195 echo 'stag line three' >>sigtagmsg
1196 test_expect_success GPG \
1197 'listing many message lines of a signed tag should succeed' '
1198 git tag -s -F sigtagmsg stag-lines &&
1200 echo "stag-lines" >expect &&
1201 git tag -l | grep "^stag-lines" >actual &&
1202 test_cmp expect actual &&
1203 git tag -n0 -l | grep "^stag-lines" >actual &&
1204 test_cmp expect actual &&
1205 git tag -n0 -l stag-lines >actual &&
1206 test_cmp expect actual &&
1208 echo "stag-lines stag line one" >expect &&
1209 git tag -n1 -l | grep "^stag-lines" >actual &&
1210 test_cmp expect actual &&
1211 git tag -n -l | grep "^stag-lines" >actual &&
1212 test_cmp expect actual &&
1213 git tag -n1 -l stag-lines >actual &&
1214 test_cmp expect actual &&
1216 echo " stag line two" >>expect &&
1217 git tag -n2 -l | grep "^ *stag.line" >actual &&
1218 test_cmp expect actual &&
1219 git tag -n2 -l stag-lines >actual &&
1220 test_cmp expect actual &&
1222 echo " stag line three" >>expect &&
1223 git tag -n3 -l | grep "^ *stag.line" >actual &&
1224 test_cmp expect actual &&
1225 git tag -n3 -l stag-lines >actual &&
1226 test_cmp expect actual &&
1227 git tag -n4 -l | grep "^ *stag.line" >actual &&
1228 test_cmp expect actual &&
1229 git tag -n4 -l stag-lines >actual &&
1230 test_cmp expect actual &&
1231 git tag -n99 -l | grep "^ *stag.line" >actual &&
1232 test_cmp expect actual &&
1233 git tag -n99 -l stag-lines >actual &&
1234 test_cmp expect actual
1237 # tags pointing to objects different from commits:
1239 tree=$(git rev-parse HEAD^{tree})
1240 blob=$(git rev-parse HEAD:foo)
1241 tag=$(git rev-parse signed-tag 2>/dev/null)
1243 get_tag_header tree-signed-tag $tree tree $time >expect
1244 echo "A message for a tree" >>expect
1245 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1246 test_expect_success GPG \
1247 'creating a signed tag pointing to a tree should succeed' '
1248 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1249 get_tag_msg tree-signed-tag >actual &&
1250 test_cmp expect actual
1253 get_tag_header blob-signed-tag $blob blob $time >expect
1254 echo "A message for a blob" >>expect
1255 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1256 test_expect_success GPG \
1257 'creating a signed tag pointing to a blob should succeed' '
1258 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1259 get_tag_msg blob-signed-tag >actual &&
1260 test_cmp expect actual
1263 get_tag_header tag-signed-tag $tag tag $time >expect
1264 echo "A message for another tag" >>expect
1265 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1266 test_expect_success GPG \
1267 'creating a signed tag pointing to another tag should succeed' '
1268 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1269 get_tag_msg tag-signed-tag >actual &&
1270 test_cmp expect actual
1273 # usage with rfc1991 signatures
1274 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1275 echo "RFC1991 signed tag" >>expect
1276 echo '-----BEGIN PGP MESSAGE-----' >>expect
1277 test_expect_success GPG,RFC1991 \
1278 'creating a signed tag with rfc1991' '
1279 echo "rfc1991" >gpghome/gpg.conf &&
1280 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1281 get_tag_msg rfc1991-signed-tag >actual &&
1282 test_cmp expect actual
1285 cat >fakeeditor <<'EOF'
1291 test_expect_success GPG,RFC1991 \
1292 'reediting a signed tag body omits signature' '
1293 echo "rfc1991" >gpghome/gpg.conf &&
1294 echo "RFC1991 signed tag" >expect &&
1295 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1296 test_cmp expect actual
1299 test_expect_success GPG,RFC1991 \
1300 'verifying rfc1991 signature' '
1301 echo "rfc1991" >gpghome/gpg.conf &&
1302 git tag -v rfc1991-signed-tag
1305 test_expect_success GPG,RFC1991 \
1306 'list tag with rfc1991 signature' '
1307 echo "rfc1991" >gpghome/gpg.conf &&
1308 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1309 git tag -l -n1 rfc1991-signed-tag >actual &&
1310 test_cmp expect actual &&
1311 git tag -l -n2 rfc1991-signed-tag >actual &&
1312 test_cmp expect actual &&
1313 git tag -l -n999 rfc1991-signed-tag >actual &&
1314 test_cmp expect actual
1317 rm -f gpghome/gpg.conf
1319 test_expect_success GPG,RFC1991 \
1320 'verifying rfc1991 signature without --rfc1991' '
1321 git tag -v rfc1991-signed-tag
1324 test_expect_success GPG,RFC1991 \
1325 'list tag with rfc1991 signature without --rfc1991' '
1326 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1327 git tag -l -n1 rfc1991-signed-tag >actual &&
1328 test_cmp expect actual &&
1329 git tag -l -n2 rfc1991-signed-tag >actual &&
1330 test_cmp expect actual &&
1331 git tag -l -n999 rfc1991-signed-tag >actual &&
1332 test_cmp expect actual
1335 test_expect_success GPG,RFC1991 \
1336 'reediting a signed tag body omits signature' '
1337 echo "RFC1991 signed tag" >expect &&
1338 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1339 test_cmp expect actual
1342 # try to sign with bad user.signingkey
1343 test_expect_success GPG \
1344 'git tag -s fails if gpg is misconfigured (bad key)' \
1345 'test_config user.signingkey BobTheMouse &&
1346 test_must_fail git tag -s -m tail tag-gpg-failure'
1348 # try to produce invalid signature
1349 test_expect_success GPG \
1350 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1351 'test_config gpg.program echo &&
1352 test_must_fail git tag -s -m tail tag-gpg-failure'
1354 # try to sign with bad user.signingkey
1355 test_expect_success GPGSM \
1356 'git tag -s fails if gpgsm is misconfigured (bad key)' \
1357 'test_config user.signingkey BobTheMouse &&
1358 test_config gpg.format x509 &&
1359 test_must_fail git tag -s -m tail tag-gpg-failure'
1361 # try to produce invalid signature
1362 test_expect_success GPGSM \
1363 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1364 'test_config gpg.x509.program echo &&
1365 test_config gpg.format x509 &&
1366 test_must_fail git tag -s -m tail tag-gpg-failure'
1368 # try to verify without gpg:
1371 test_expect_success GPG \
1372 'verify signed tag fails when public key is not present' \
1373 'test_must_fail git tag -v signed-tag'
1375 test_expect_success \
1376 'git tag -a fails if tag annotation is empty' '
1377 ! (GIT_EDITOR=cat git tag -a initial-comment)
1380 test_expect_success \
1381 'message in editor has initial comment' '
1382 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1385 test_expect_success 'message in editor has initial comment: first line' '
1386 # check the first line --- should be empty
1387 echo >first.expect &&
1388 sed -e 1q <actual >first.actual &&
1389 test_i18ncmp first.expect first.actual
1392 test_expect_success \
1393 'message in editor has initial comment: remainder' '
1394 # remove commented lines from the remainder -- should be empty
1395 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1396 test_must_be_empty rest.actual
1399 get_tag_header reuse $commit commit $time >expect
1400 echo "An annotation to be reused" >> expect
1401 test_expect_success \
1402 'overwriting an annoted tag should use its previous body' '
1403 git tag -a -m "An annotation to be reused" reuse &&
1404 GIT_EDITOR=true git tag -f -a reuse &&
1405 get_tag_msg reuse >actual &&
1406 test_cmp expect actual
1409 test_expect_success 'filename for the message is relative to cwd' '
1411 echo "Tag message in top directory" >msgfile-5 &&
1412 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1415 git tag -a -F msgfile-5 tag-from-subdir
1417 git cat-file tag tag-from-subdir | grep "in sub directory"
1420 test_expect_success 'filename for the message is relative to cwd' '
1421 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1424 git tag -a -F msgfile-6 tag-from-subdir-2
1426 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1429 # create a few more commits to test --contains
1431 hash1=$(git rev-parse HEAD)
1433 test_expect_success 'creating second commit and tag' '
1434 echo foo-2.0 >foo &&
1436 git commit -m second &&
1440 hash2=$(git rev-parse HEAD)
1442 test_expect_success 'creating third commit without tag' '
1443 echo foo-dev >foo &&
1448 hash3=$(git rev-parse HEAD)
1450 # simple linear checks of --continue
1452 cat > expected <<EOF
1460 test_expect_success 'checking that first commit is in all tags (hash)' "
1461 git tag -l --contains $hash1 v* >actual &&
1462 test_cmp expected actual
1465 # other ways of specifying the commit
1466 test_expect_success 'checking that first commit is in all tags (tag)' "
1467 git tag -l --contains v1.0 v* >actual &&
1468 test_cmp expected actual
1471 test_expect_success 'checking that first commit is in all tags (relative)' "
1472 git tag -l --contains HEAD~2 v* >actual &&
1473 test_cmp expected actual
1476 # All the --contains tests above, but with --no-contains
1477 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1478 git tag -l --no-contains $hash1 v* >actual &&
1479 test_must_be_empty actual
1482 test_expect_success 'checking that first commit is in all tags (tag)' "
1483 git tag -l --no-contains v1.0 v* >actual &&
1484 test_must_be_empty actual
1487 test_expect_success 'checking that first commit is in all tags (relative)' "
1488 git tag -l --no-contains HEAD~2 v* >actual &&
1489 test_must_be_empty actual
1492 cat > expected <<EOF
1496 test_expect_success 'checking that second commit only has one tag' "
1497 git tag -l --contains $hash2 v* >actual &&
1498 test_cmp expected actual
1501 cat > expected <<EOF
1508 test_expect_success 'inverse of the last test, with --no-contains' "
1509 git tag -l --no-contains $hash2 v* >actual &&
1510 test_cmp expected actual
1513 test_expect_success 'checking that third commit has no tags' "
1514 git tag -l --contains $hash3 v* >actual &&
1515 test_must_be_empty actual
1518 cat > expected <<EOF
1526 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1527 git tag -l --no-contains $hash3 v* >actual &&
1528 test_cmp expected actual
1531 # how about a simple merge?
1533 test_expect_success 'creating simple branch' '
1534 git branch stable v2.0 &&
1535 git checkout stable &&
1536 echo foo-3.0 > foo &&
1537 git commit foo -m fourth &&
1541 hash4=$(git rev-parse HEAD)
1543 cat > expected <<EOF
1547 test_expect_success 'checking that branch head only has one tag' "
1548 git tag -l --contains $hash4 v* >actual &&
1549 test_cmp expected actual
1552 cat > expected <<EOF
1560 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1561 git tag -l --no-contains $hash4 v* >actual &&
1562 test_cmp expected actual
1565 test_expect_success 'merging original branch into this branch' '
1566 git merge --strategy=ours master &&
1570 cat > expected <<EOF
1574 test_expect_success 'checking that original branch head has one tag now' "
1575 git tag -l --contains $hash3 v* >actual &&
1576 test_cmp expected actual
1579 cat > expected <<EOF
1588 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1589 git tag -l --no-contains $hash3 v* >actual &&
1590 test_cmp expected actual
1593 cat > expected <<EOF
1603 test_expect_success 'checking that initial commit is in all tags' "
1604 git tag -l --contains $hash1 v* >actual &&
1605 test_cmp expected actual
1608 test_expect_success 'checking that --contains can be used in non-list mode' '
1609 git tag --contains $hash1 v* >actual &&
1610 test_cmp expected actual
1613 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1614 git tag -l --no-contains $hash1 v* >actual &&
1615 test_must_be_empty actual
1618 # mixing modes and options:
1620 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1621 test_must_fail git tag -a &&
1622 test_must_fail git tag -a -l &&
1623 test_must_fail git tag -s &&
1624 test_must_fail git tag -s -l &&
1625 test_must_fail git tag -m &&
1626 test_must_fail git tag -m -l &&
1627 test_must_fail git tag -m "hlagh" &&
1628 test_must_fail git tag -m "hlagh" -l &&
1629 test_must_fail git tag -F &&
1630 test_must_fail git tag -F -l &&
1631 test_must_fail git tag -f &&
1632 test_must_fail git tag -f -l &&
1633 test_must_fail git tag -a -s -m -F &&
1634 test_must_fail git tag -a -s -m -F -l &&
1635 test_must_fail git tag -l -v &&
1636 test_must_fail git tag -l -d &&
1637 test_must_fail git tag -l -v -d &&
1638 test_must_fail git tag -n 100 -v &&
1639 test_must_fail git tag -l -m msg &&
1640 test_must_fail git tag -l -F some file &&
1641 test_must_fail git tag -v -s &&
1642 test_must_fail git tag --contains tag-tree &&
1643 test_must_fail git tag --contains tag-blob &&
1644 test_must_fail git tag --no-contains tag-tree &&
1645 test_must_fail git tag --no-contains tag-blob &&
1646 test_must_fail git tag --contains --no-contains &&
1647 test_must_fail git tag --no-with HEAD &&
1648 test_must_fail git tag --no-without HEAD
1651 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1653 test_expect_success "mixing incompatible modes with $option is forbidden" "
1654 test_must_fail git tag -d $option HEAD &&
1655 test_must_fail git tag -d $option HEAD some-tag &&
1656 test_must_fail git tag -v $option HEAD
1658 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1659 git tag -n $option HEAD HEAD &&
1660 git tag $option HEAD HEAD &&
1667 test_expect_success '--points-at can be used in non-list mode' '
1668 echo v4.0 >expect &&
1669 git tag --points-at=v4.0 "v*" >actual &&
1670 test_cmp expect actual
1673 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1674 echo v4.0 >expect &&
1675 git tag --points-at >actual &&
1676 test_cmp expect actual
1679 test_expect_success '--points-at finds lightweight tags' '
1680 echo v4.0 >expect &&
1681 git tag --points-at v4.0 >actual &&
1682 test_cmp expect actual
1685 test_expect_success '--points-at finds annotated tags of commits' '
1686 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1687 echo annotated-v4.0 >expect &&
1688 git tag -l --points-at v4.0 "annotated*" >actual &&
1689 test_cmp expect actual
1692 test_expect_success '--points-at finds annotated tags of tags' '
1693 git tag -m "describing the v4.0 tag object" \
1694 annotated-again-v4.0 annotated-v4.0 &&
1695 cat >expect <<-\EOF &&
1696 annotated-again-v4.0
1699 git tag --points-at=annotated-v4.0 >actual &&
1700 test_cmp expect actual
1703 test_expect_success 'recursive tagging should give advice' '
1704 sed -e "s/|$//" <<-EOF >expect &&
1705 hint: You have created a nested tag. The object referred to by your new tag is
1706 hint: already a tag. If you meant to tag the object that it points to, use:
1708 hint: git tag -f nested annotated-v4.0^{}
1710 git tag -m nested nested annotated-v4.0 2>actual &&
1711 test_i18ncmp expect actual
1714 test_expect_success 'multiple --points-at are OR-ed together' '
1715 cat >expect <<-\EOF &&
1719 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1720 test_cmp expect actual
1723 test_expect_success 'lexical sort' '
1727 git tag -l --sort=refname "foo*" >actual &&
1728 cat >expect <<-\EOF &&
1733 test_cmp expect actual
1736 test_expect_success 'version sort' '
1737 git tag -l --sort=version:refname "foo*" >actual &&
1738 cat >expect <<-\EOF &&
1743 test_cmp expect actual
1746 test_expect_success 'reverse version sort' '
1747 git tag -l --sort=-version:refname "foo*" >actual &&
1748 cat >expect <<-\EOF &&
1753 test_cmp expect actual
1756 test_expect_success 'reverse lexical sort' '
1757 git tag -l --sort=-refname "foo*" >actual &&
1758 cat >expect <<-\EOF &&
1763 test_cmp expect actual
1766 test_expect_success 'configured lexical sort' '
1767 test_config tag.sort "v:refname" &&
1768 git tag -l "foo*" >actual &&
1769 cat >expect <<-\EOF &&
1774 test_cmp expect actual
1777 test_expect_success 'option override configured sort' '
1778 test_config tag.sort "v:refname" &&
1779 git tag -l --sort=-refname "foo*" >actual &&
1780 cat >expect <<-\EOF &&
1785 test_cmp expect actual
1788 test_expect_success 'invalid sort parameter on command line' '
1789 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1792 test_expect_success 'invalid sort parameter in configuratoin' '
1793 test_config tag.sort "v:notvalid" &&
1794 test_must_fail git tag -l "foo*"
1797 test_expect_success 'version sort with prerelease reordering' '
1798 test_config versionsort.prereleaseSuffix -rc &&
1799 git tag foo1.6-rc1 &&
1800 git tag foo1.6-rc2 &&
1801 git tag -l --sort=version:refname "foo*" >actual &&
1802 cat >expect <<-\EOF &&
1809 test_cmp expect actual
1812 test_expect_success 'reverse version sort with prerelease reordering' '
1813 test_config versionsort.prereleaseSuffix -rc &&
1814 git tag -l --sort=-version:refname "foo*" >actual &&
1815 cat >expect <<-\EOF &&
1822 test_cmp expect actual
1825 test_expect_success 'version sort with prerelease reordering and common leading character' '
1826 test_config versionsort.prereleaseSuffix -before &&
1827 git tag foo1.7-before1 &&
1829 git tag foo1.7-after1 &&
1830 git tag -l --sort=version:refname "foo1.7*" >actual &&
1831 cat >expect <<-\EOF &&
1836 test_cmp expect actual
1839 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1840 test_config versionsort.prereleaseSuffix -before &&
1841 git config --add versionsort.prereleaseSuffix -after &&
1842 git tag -l --sort=version:refname "foo1.7*" >actual &&
1843 cat >expect <<-\EOF &&
1848 test_cmp expect actual
1851 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1852 test_config versionsort.prereleaseSuffix -bar &&
1853 git config --add versionsort.prereleaseSuffix -foo-baz &&
1854 git config --add versionsort.prereleaseSuffix -foo-bar &&
1855 git tag foo1.8-foo-bar &&
1856 git tag foo1.8-foo-baz &&
1858 git tag -l --sort=version:refname "foo1.8*" >actual &&
1859 cat >expect <<-\EOF &&
1864 test_cmp expect actual
1867 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1868 test_config versionsort.prereleaseSuffix -pre &&
1869 git config --add versionsort.prereleaseSuffix -prerelease &&
1870 git tag foo1.9-pre1 &&
1871 git tag foo1.9-pre2 &&
1872 git tag foo1.9-prerelease1 &&
1873 git tag -l --sort=version:refname "foo1.9*" >actual &&
1874 cat >expect <<-\EOF &&
1879 test_cmp expect actual
1882 test_expect_success 'version sort with general suffix reordering' '
1883 test_config versionsort.suffix -alpha &&
1884 git config --add versionsort.suffix -beta &&
1885 git config --add versionsort.suffix "" &&
1886 git config --add versionsort.suffix -gamma &&
1887 git config --add versionsort.suffix -delta &&
1888 git tag foo1.10-alpha &&
1889 git tag foo1.10-beta &&
1890 git tag foo1.10-gamma &&
1891 git tag foo1.10-delta &&
1892 git tag foo1.10-unlisted-suffix &&
1893 git tag -l --sort=version:refname "foo1.10*" >actual &&
1894 cat >expect <<-\EOF &&
1898 foo1.10-unlisted-suffix
1902 test_cmp expect actual
1905 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1906 test_config versionsort.suffix -before &&
1907 test_config versionsort.prereleaseSuffix -after &&
1908 git tag -l --sort=version:refname "foo1.7*" >actual &&
1909 cat >expect <<-\EOF &&
1914 test_cmp expect actual
1917 test_expect_success 'version sort with very long prerelease suffix' '
1918 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1919 git tag -l --sort=version:refname
1922 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1924 while test $i -lt 8000
1926 echo "commit refs/heads/master
1927 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1931 test $i = 1 && echo "from refs/heads/master^0"
1933 done | git fast-import &&
1934 git checkout master &&
1935 git tag far-far-away HEAD^ &&
1936 run_with_limited_stack git tag --contains HEAD >actual &&
1937 test_must_be_empty actual &&
1938 run_with_limited_stack git tag --no-contains HEAD >actual &&
1939 test_line_count "-gt" 10 actual
1942 test_expect_success '--format should list tags as per format given' '
1943 cat >expect <<-\EOF &&
1944 refname : refs/tags/v1.0
1945 refname : refs/tags/v1.0.1
1946 refname : refs/tags/v1.1.3
1948 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1949 test_cmp expect actual
1952 test_expect_success "set up color tests" '
1953 echo "<RED>v1.0<RESET>" >expect.color &&
1954 echo "v1.0" >expect.bare &&
1955 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1958 test_expect_success '%(color) omitted without tty' '
1959 TERM=vt100 git tag $color_args >actual.raw &&
1960 test_decode_color <actual.raw >actual &&
1961 test_cmp expect.bare actual
1964 test_expect_success TTY '%(color) present with tty' '
1965 test_terminal git tag $color_args >actual.raw &&
1966 test_decode_color <actual.raw >actual &&
1967 test_cmp expect.color actual
1970 test_expect_success '--color overrides auto-color' '
1971 git tag --color $color_args >actual.raw &&
1972 test_decode_color <actual.raw >actual &&
1973 test_cmp expect.color actual
1976 test_expect_success 'color.ui=always overrides auto-color' '
1977 git -c color.ui=always tag $color_args >actual.raw &&
1978 test_decode_color <actual.raw >actual &&
1979 test_cmp expect.color actual
1982 test_expect_success 'setup --merged test tags' '
1983 git tag mergetest-1 HEAD~2 &&
1984 git tag mergetest-2 HEAD~1 &&
1985 git tag mergetest-3 HEAD
1988 test_expect_success '--merged can be used in non-list mode' '
1989 cat >expect <<-\EOF &&
1993 git tag --merged=mergetest-2 "mergetest*" >actual &&
1994 test_cmp expect actual
1997 test_expect_success '--merged is incompatible with --no-merged' '
1998 test_must_fail git tag --merged HEAD --no-merged HEAD
2001 test_expect_success '--merged shows merged tags' '
2002 cat >expect <<-\EOF &&
2006 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2007 test_cmp expect actual
2010 test_expect_success '--no-merged show unmerged tags' '
2011 cat >expect <<-\EOF &&
2014 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2015 test_cmp expect actual
2018 test_expect_success '--no-merged can be used in non-list mode' '
2019 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2020 test_cmp expect actual
2023 test_expect_success 'ambiguous branch/tags not marked' '
2024 git tag ambiguous &&
2025 git branch ambiguous &&
2026 echo ambiguous >expect &&
2027 git tag -l ambiguous >actual &&
2028 test_cmp expect actual
2031 test_expect_success '--contains combined with --no-contains' '
2033 git init no-contains &&
2040 cat >expected <<-\EOF &&
2045 git tag --contains v0.2 --no-contains v0.5 >actual &&
2046 test_cmp expected actual
2050 # As the docs say, list tags which contain a specified *commit*. We
2051 # don't recurse down to tags for trees or blobs pointed to by *those*
2053 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2055 blob=$(git rev-parse v0.3:v0.3.t) &&
2056 tree=$(git rev-parse v0.3^{tree}) &&
2057 git tag tag-blob $blob &&
2058 git tag tag-tree $tree &&
2059 git tag --contains v0.3 >actual &&
2060 cat >expected <<-\EOF &&
2065 test_cmp expected actual &&
2066 git tag --no-contains v0.3 >actual &&
2067 cat >expected <<-\EOF &&
2071 test_cmp expected actual