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
329 test_expect_success \
330 'listing tags using v.* should print nothing because none have v.' '
331 git tag -l "v.*" > actual &&
332 test_cmp expect actual
341 test_expect_success \
342 'listing tags using v* should print only those having v' '
343 git tag -l "v*" > actual &&
344 test_cmp expect actual
347 test_expect_success 'tag -l can accept multiple patterns' '
348 git tag -l "v1*" "v0*" >actual &&
349 test_cmp expect actual
352 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
353 # could leave you with the impression that "-l <pattern> -l <pattern>"
354 # was how we wanted to accept multiple patterns.
356 # This test should not imply that this is a sane thing to support. but
357 # since the documentation was worded like it was let's at least find
358 # out if we're going to break this long-documented form of taking
360 test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
361 git tag -l "v1*" -l "v0*" >actual &&
362 test_cmp expect actual
365 test_expect_success 'listing tags in column' '
366 COLUMNS=40 git tag -l --column=row >actual &&
367 cat >expected <<\EOF &&
369 v0.2.1 v1.0 v1.0.1 v1.1.3
371 test_cmp expected actual
374 test_expect_success 'listing tags in column with column.*' '
375 test_config column.tag row &&
376 test_config column.ui dense &&
377 COLUMNS=40 git tag -l >actual &&
378 cat >expected <<\EOF &&
380 v0.2.1 v1.0 v1.0.1 v1.1.3
382 test_cmp expected actual
385 test_expect_success 'listing tag with -n --column should fail' '
386 test_must_fail git tag --column -n
389 test_expect_success 'listing tags -n in column with column.ui ignored' '
390 test_config column.ui "row dense" &&
391 COLUMNS=40 git tag -l -n >actual &&
392 cat >expected <<\EOF &&
403 test_cmp expected actual
406 # creating and verifying lightweight tags:
408 test_expect_success \
409 'a non-annotated tag created without parameters should point to HEAD' '
410 git tag non-annotated-tag &&
411 test $(git cat-file -t non-annotated-tag) = commit &&
412 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
415 test_expect_success 'trying to verify an unknown tag should fail' \
416 'test_must_fail git tag -v unknown-tag'
418 test_expect_success \
419 'trying to verify a non-annotated and non-signed tag should fail' \
420 'test_must_fail git tag -v non-annotated-tag'
422 test_expect_success \
423 'trying to verify many non-annotated or unknown tags, should fail' \
424 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
426 # creating annotated tags:
429 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
432 # run test_tick before committing always gives the time in that timezone
438 tagger C O Mitter <committer@example.com> $4 -0700
443 commit=$(git rev-parse HEAD)
446 get_tag_header annotated-tag $commit commit $time >expect
447 echo "A message" >>expect
448 test_expect_success \
449 'creating an annotated tag with -m message should succeed' '
450 git tag -m "A message" annotated-tag &&
451 get_tag_msg annotated-tag >actual &&
452 test_cmp expect actual
459 get_tag_header file-annotated-tag $commit commit $time >expect
461 test_expect_success \
462 'creating an annotated tag with -F messagefile should succeed' '
463 git tag -F msgfile file-annotated-tag &&
464 get_tag_msg file-annotated-tag >actual &&
465 test_cmp expect actual
472 get_tag_header stdin-annotated-tag $commit commit $time >expect
473 cat inputmsg >>expect
474 test_expect_success 'creating an annotated tag with -F - should succeed' '
475 git tag -F - stdin-annotated-tag <inputmsg &&
476 get_tag_msg stdin-annotated-tag >actual &&
477 test_cmp expect actual
480 test_expect_success \
481 'trying to create a tag with a non-existing -F file should fail' '
482 ! test -f nonexistingfile &&
483 ! tag_exists notag &&
484 test_must_fail git tag -F nonexistingfile notag &&
488 test_expect_success \
489 'trying to create tags giving both -m or -F options should fail' '
490 echo "message file 1" >msgfile1 &&
491 echo "message file 2" >msgfile2 &&
492 ! tag_exists msgtag &&
493 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
494 ! tag_exists msgtag &&
495 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
496 ! tag_exists msgtag &&
497 test_must_fail git tag -m "message 1" -F msgfile1 \
498 -m "message 2" msgtag &&
502 # blank and empty messages:
504 get_tag_header empty-annotated-tag $commit commit $time >expect
505 test_expect_success \
506 'creating a tag with an empty -m message should succeed' '
507 git tag -m "" empty-annotated-tag &&
508 get_tag_msg empty-annotated-tag >actual &&
509 test_cmp expect actual
513 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
514 test_expect_success \
515 'creating a tag with an empty -F messagefile should succeed' '
516 git tag -F emptyfile emptyfile-annotated-tag &&
517 get_tag_msg emptyfile-annotated-tag >actual &&
518 test_cmp expect actual
521 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
522 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
523 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
524 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
525 get_tag_header blanks-annotated-tag $commit commit $time >expect
535 test_expect_success \
536 'extra blanks in the message for an annotated tag should be removed' '
537 git tag -F blanksfile blanks-annotated-tag &&
538 get_tag_msg blanks-annotated-tag >actual &&
539 test_cmp expect actual
542 get_tag_header blank-annotated-tag $commit commit $time >expect
543 test_expect_success \
544 'creating a tag with blank -m message with spaces should succeed' '
545 git tag -m " " blank-annotated-tag &&
546 get_tag_msg blank-annotated-tag >actual &&
547 test_cmp expect actual
553 get_tag_header blankfile-annotated-tag $commit commit $time >expect
554 test_expect_success \
555 'creating a tag with blank -F messagefile with spaces should succeed' '
556 git tag -F blankfile blankfile-annotated-tag &&
557 get_tag_msg blankfile-annotated-tag >actual &&
558 test_cmp expect actual
561 printf ' ' >blanknonlfile
562 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
563 test_expect_success \
564 'creating a tag with -F file of spaces and no newline should succeed' '
565 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
566 get_tag_msg blanknonlfile-annotated-tag >actual &&
567 test_cmp expect actual
570 # messages with commented lines:
572 cat >commentsfile <<EOF
589 get_tag_header comments-annotated-tag $commit commit $time >expect
598 test_expect_success \
599 'creating a tag using a -F messagefile with #comments should succeed' '
600 git tag -F commentsfile comments-annotated-tag &&
601 get_tag_msg comments-annotated-tag >actual &&
602 test_cmp expect actual
605 get_tag_header comment-annotated-tag $commit commit $time >expect
606 test_expect_success \
607 'creating a tag with a #comment in the -m message should succeed' '
608 git tag -m "#comment" comment-annotated-tag &&
609 get_tag_msg comment-annotated-tag >actual &&
610 test_cmp expect actual
613 echo '#comment' >commentfile
614 echo '' >>commentfile
615 echo '####' >>commentfile
616 get_tag_header commentfile-annotated-tag $commit commit $time >expect
617 test_expect_success \
618 'creating a tag with #comments in the -F messagefile should succeed' '
619 git tag -F commentfile commentfile-annotated-tag &&
620 get_tag_msg commentfile-annotated-tag >actual &&
621 test_cmp expect actual
624 printf '#comment' >commentnonlfile
625 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
626 test_expect_success \
627 'creating a tag with a file of #comment and no newline should succeed' '
628 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
629 get_tag_msg commentnonlfile-annotated-tag >actual &&
630 test_cmp expect actual
633 # listing messages for annotated non-signed tags:
635 test_expect_success \
636 'listing the one-line message of a non-signed tag should succeed' '
637 git tag -m "A msg" tag-one-line &&
639 echo "tag-one-line" >expect &&
640 git tag -l | grep "^tag-one-line" >actual &&
641 test_cmp expect actual &&
642 git tag -n0 -l | grep "^tag-one-line" >actual &&
643 test_cmp expect actual &&
644 git tag -n0 -l tag-one-line >actual &&
645 test_cmp expect actual &&
647 git tag -n0 | grep "^tag-one-line" >actual &&
648 test_cmp expect actual &&
649 git tag -n0 tag-one-line >actual &&
650 test_cmp expect actual &&
652 echo "tag-one-line A msg" >expect &&
653 git tag -n1 -l | grep "^tag-one-line" >actual &&
654 test_cmp expect actual &&
655 git tag -n -l | grep "^tag-one-line" >actual &&
656 test_cmp expect actual &&
657 git tag -n1 -l tag-one-line >actual &&
658 test_cmp expect actual &&
659 git tag -n2 -l tag-one-line >actual &&
660 test_cmp expect actual &&
661 git tag -n999 -l tag-one-line >actual &&
662 test_cmp expect actual
665 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
667 git tag -n 100 >actual &&
668 test_cmp expect actual &&
670 git tag -m "A msg" 100 &&
671 echo "100 A msg" >expect &&
672 git tag -n 100 >actual &&
673 test_cmp expect actual
676 test_expect_success \
677 'listing the zero-lines message of a non-signed tag should succeed' '
678 git tag -m "" tag-zero-lines &&
680 echo "tag-zero-lines" >expect &&
681 git tag -l | grep "^tag-zero-lines" >actual &&
682 test_cmp expect actual &&
683 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
684 test_cmp expect actual &&
685 git tag -n0 -l tag-zero-lines >actual &&
686 test_cmp expect actual &&
688 echo "tag-zero-lines " >expect &&
689 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
690 test_cmp expect actual &&
691 git tag -n -l | grep "^tag-zero-lines" >actual &&
692 test_cmp expect actual &&
693 git tag -n1 -l tag-zero-lines >actual &&
694 test_cmp expect actual &&
695 git tag -n2 -l tag-zero-lines >actual &&
696 test_cmp expect actual &&
697 git tag -n999 -l tag-zero-lines >actual &&
698 test_cmp expect actual
701 echo 'tag line one' >annotagmsg
702 echo 'tag line two' >>annotagmsg
703 echo 'tag line three' >>annotagmsg
704 test_expect_success \
705 'listing many message lines of a non-signed tag should succeed' '
706 git tag -F annotagmsg tag-lines &&
708 echo "tag-lines" >expect &&
709 git tag -l | grep "^tag-lines" >actual &&
710 test_cmp expect actual &&
711 git tag -n0 -l | grep "^tag-lines" >actual &&
712 test_cmp expect actual &&
713 git tag -n0 -l tag-lines >actual &&
714 test_cmp expect actual &&
716 echo "tag-lines tag line one" >expect &&
717 git tag -n1 -l | grep "^tag-lines" >actual &&
718 test_cmp expect actual &&
719 git tag -n -l | grep "^tag-lines" >actual &&
720 test_cmp expect actual &&
721 git tag -n1 -l tag-lines >actual &&
722 test_cmp expect actual &&
724 echo " tag line two" >>expect &&
725 git tag -n2 -l | grep "^ *tag.line" >actual &&
726 test_cmp expect actual &&
727 git tag -n2 -l tag-lines >actual &&
728 test_cmp expect actual &&
730 echo " tag line three" >>expect &&
731 git tag -n3 -l | grep "^ *tag.line" >actual &&
732 test_cmp expect actual &&
733 git tag -n3 -l tag-lines >actual &&
734 test_cmp expect actual &&
735 git tag -n4 -l | grep "^ *tag.line" >actual &&
736 test_cmp expect actual &&
737 git tag -n4 -l tag-lines >actual &&
738 test_cmp expect actual &&
739 git tag -n99 -l | grep "^ *tag.line" >actual &&
740 test_cmp expect actual &&
741 git tag -n99 -l tag-lines >actual &&
742 test_cmp expect actual
745 test_expect_success 'annotations for blobs are empty' '
746 blob=$(git hash-object -w --stdin <<-\EOF
752 git tag tag-blob $blob &&
753 echo "tag-blob " >expect &&
754 git tag -n1 -l tag-blob >actual &&
755 test_cmp expect actual
758 # trying to verify annotated non-signed tags:
760 test_expect_success GPG \
761 'trying to verify an annotated non-signed tag should fail' '
762 tag_exists annotated-tag &&
763 test_must_fail git tag -v annotated-tag
766 test_expect_success GPG \
767 'trying to verify a file-annotated non-signed tag should fail' '
768 tag_exists file-annotated-tag &&
769 test_must_fail git tag -v file-annotated-tag
772 test_expect_success GPG \
773 'trying to verify two annotated non-signed tags should fail' '
774 tag_exists annotated-tag file-annotated-tag &&
775 test_must_fail git tag -v annotated-tag file-annotated-tag
778 # creating and verifying signed tags:
780 get_tag_header signed-tag $commit commit $time >expect
781 echo 'A signed tag message' >>expect
782 echo '-----BEGIN PGP SIGNATURE-----' >>expect
783 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
784 git tag -s -m "A signed tag message" signed-tag &&
785 get_tag_msg signed-tag >actual &&
786 test_cmp expect actual
789 get_tag_header u-signed-tag $commit commit $time >expect
790 echo 'Another message' >>expect
791 echo '-----BEGIN PGP SIGNATURE-----' >>expect
792 test_expect_success GPG 'sign with a given key id' '
794 git tag -u committer@example.com -m "Another message" u-signed-tag &&
795 get_tag_msg u-signed-tag >actual &&
796 test_cmp expect actual
800 test_expect_success GPG 'sign with an unknown id (1)' '
802 test_must_fail git tag -u author@example.com \
803 -m "Another message" o-signed-tag
807 test_expect_success GPG 'sign with an unknown id (2)' '
809 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
813 cat >fakeeditor <<'EOF'
815 test -n "$1" && exec >"$1"
816 echo A signed tag message
817 echo from a fake editor.
821 get_tag_header implied-sign $commit commit $time >expect
822 ./fakeeditor >>expect
823 echo '-----BEGIN PGP SIGNATURE-----' >>expect
824 test_expect_success GPG '-u implies signed tag' '
825 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
826 get_tag_msg implied-sign >actual &&
827 test_cmp expect actual
830 cat >sigmsgfile <<EOF
834 get_tag_header file-signed-tag $commit commit $time >expect
835 cat sigmsgfile >>expect
836 echo '-----BEGIN PGP SIGNATURE-----' >>expect
837 test_expect_success GPG \
838 'creating a signed tag with -F messagefile should succeed' '
839 git tag -s -F sigmsgfile file-signed-tag &&
840 get_tag_msg file-signed-tag >actual &&
841 test_cmp expect actual
844 cat >siginputmsg <<EOF
845 A signed tag message from
848 get_tag_header stdin-signed-tag $commit commit $time >expect
849 cat siginputmsg >>expect
850 echo '-----BEGIN PGP SIGNATURE-----' >>expect
851 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
852 git tag -s -F - stdin-signed-tag <siginputmsg &&
853 get_tag_msg stdin-signed-tag >actual &&
854 test_cmp expect actual
857 get_tag_header implied-annotate $commit commit $time >expect
858 ./fakeeditor >>expect
859 echo '-----BEGIN PGP SIGNATURE-----' >>expect
860 test_expect_success GPG '-s implies annotated tag' '
861 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
862 get_tag_msg implied-annotate >actual &&
863 test_cmp expect actual
866 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
867 echo "A message" >>expect
868 echo '-----BEGIN PGP SIGNATURE-----' >>expect
869 test_expect_success GPG \
870 'git tag -s implied if configured with tag.forcesignannotated' \
871 'test_config tag.forcesignannotated true &&
872 git tag -m "A message" forcesignannotated-implied-sign &&
873 get_tag_msg forcesignannotated-implied-sign >actual &&
874 test_cmp expect actual
877 test_expect_success GPG \
878 'lightweight with no message when configured with tag.forcesignannotated' \
879 'test_config tag.forcesignannotated true &&
880 git tag forcesignannotated-lightweight &&
881 tag_exists forcesignannotated-lightweight &&
882 test_must_fail git tag -v forcesignannotated-no-message
885 get_tag_header forcesignannotated-annotate $commit commit $time >expect
886 echo "A message" >>expect
887 test_expect_success GPG \
888 'git tag -a disable configured tag.forcesignannotated' \
889 'test_config tag.forcesignannotated true &&
890 git tag -a -m "A message" forcesignannotated-annotate &&
891 get_tag_msg forcesignannotated-annotate >actual &&
892 test_cmp expect actual &&
893 test_must_fail git tag -v forcesignannotated-annotate
896 get_tag_header forcesignannotated-disabled $commit commit $time >expect
897 echo "A message" >>expect
898 echo '-----BEGIN PGP SIGNATURE-----' >>expect
899 test_expect_success GPG \
900 'git tag --sign enable GPG sign' \
901 'test_config tag.forcesignannotated false &&
902 git tag --sign -m "A message" forcesignannotated-disabled &&
903 get_tag_msg forcesignannotated-disabled >actual &&
904 test_cmp expect actual
907 test_expect_success GPG \
908 'trying to create a signed tag with non-existing -F file should fail' '
909 ! test -f nonexistingfile &&
910 ! tag_exists nosigtag &&
911 test_must_fail git tag -s -F nonexistingfile nosigtag &&
912 ! tag_exists nosigtag
915 test_expect_success GPG 'verifying a signed tag should succeed' \
916 'git tag -v signed-tag'
918 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
919 'git tag -v signed-tag file-signed-tag'
921 test_expect_success GPG \
922 'verifying many signed and non-signed tags should fail' '
923 test_must_fail git tag -v signed-tag annotated-tag &&
924 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
925 test_must_fail git tag -v annotated-tag \
926 file-signed-tag file-annotated-tag &&
927 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
930 test_expect_success GPG 'verifying a forged tag should fail' '
931 forged=$(git cat-file tag signed-tag |
932 sed -e "s/signed-tag/forged-tag/" |
934 git tag forged-tag $forged &&
935 test_must_fail git tag -v forged-tag
938 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
939 cat >expect <<-\EOF &&
942 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
943 test_cmp expect actual
946 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
948 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
949 test_cmp expect actual
952 # blank and empty messages for signed tags:
954 get_tag_header empty-signed-tag $commit commit $time >expect
955 echo '-----BEGIN PGP SIGNATURE-----' >>expect
956 test_expect_success GPG \
957 'creating a signed tag with an empty -m message should succeed' '
958 git tag -s -m "" empty-signed-tag &&
959 get_tag_msg empty-signed-tag >actual &&
960 test_cmp expect actual &&
961 git tag -v empty-signed-tag
965 get_tag_header emptyfile-signed-tag $commit commit $time >expect
966 echo '-----BEGIN PGP SIGNATURE-----' >>expect
967 test_expect_success GPG \
968 'creating a signed tag with an empty -F messagefile should succeed' '
969 git tag -s -F sigemptyfile emptyfile-signed-tag &&
970 get_tag_msg emptyfile-signed-tag >actual &&
971 test_cmp expect actual &&
972 git tag -v emptyfile-signed-tag
975 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
976 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
977 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
978 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
979 get_tag_header blanks-signed-tag $commit commit $time >expect
989 echo '-----BEGIN PGP SIGNATURE-----' >>expect
990 test_expect_success GPG \
991 'extra blanks in the message for a signed tag should be removed' '
992 git tag -s -F sigblanksfile blanks-signed-tag &&
993 get_tag_msg blanks-signed-tag >actual &&
994 test_cmp expect actual &&
995 git tag -v blanks-signed-tag
998 get_tag_header blank-signed-tag $commit commit $time >expect
999 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1000 test_expect_success GPG \
1001 'creating a signed tag with a blank -m message should succeed' '
1002 git tag -s -m " " blank-signed-tag &&
1003 get_tag_msg blank-signed-tag >actual &&
1004 test_cmp expect actual &&
1005 git tag -v blank-signed-tag
1008 echo ' ' >sigblankfile
1009 echo '' >>sigblankfile
1010 echo ' ' >>sigblankfile
1011 get_tag_header blankfile-signed-tag $commit commit $time >expect
1012 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1013 test_expect_success GPG \
1014 'creating a signed tag with blank -F file with spaces should succeed' '
1015 git tag -s -F sigblankfile blankfile-signed-tag &&
1016 get_tag_msg blankfile-signed-tag >actual &&
1017 test_cmp expect actual &&
1018 git tag -v blankfile-signed-tag
1021 printf ' ' >sigblanknonlfile
1022 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1023 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1024 test_expect_success GPG \
1025 'creating a signed tag with spaces and no newline should succeed' '
1026 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1027 get_tag_msg blanknonlfile-signed-tag >actual &&
1028 test_cmp expect actual &&
1029 git tag -v signed-tag
1032 # messages with commented lines for signed tags:
1034 cat >sigcommentsfile <<EOF
1051 get_tag_header comments-signed-tag $commit commit $time >expect
1060 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1061 test_expect_success GPG \
1062 'creating a signed tag with a -F file with #comments should succeed' '
1063 git tag -s -F sigcommentsfile comments-signed-tag &&
1064 get_tag_msg comments-signed-tag >actual &&
1065 test_cmp expect actual &&
1066 git tag -v comments-signed-tag
1069 get_tag_header comment-signed-tag $commit commit $time >expect
1070 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1071 test_expect_success GPG \
1072 'creating a signed tag with #commented -m message should succeed' '
1073 git tag -s -m "#comment" comment-signed-tag &&
1074 get_tag_msg comment-signed-tag >actual &&
1075 test_cmp expect actual &&
1076 git tag -v comment-signed-tag
1079 echo '#comment' >sigcommentfile
1080 echo '' >>sigcommentfile
1081 echo '####' >>sigcommentfile
1082 get_tag_header commentfile-signed-tag $commit commit $time >expect
1083 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1084 test_expect_success GPG \
1085 'creating a signed tag with #commented -F messagefile should succeed' '
1086 git tag -s -F sigcommentfile commentfile-signed-tag &&
1087 get_tag_msg commentfile-signed-tag >actual &&
1088 test_cmp expect actual &&
1089 git tag -v commentfile-signed-tag
1092 printf '#comment' >sigcommentnonlfile
1093 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1094 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1095 test_expect_success GPG \
1096 'creating a signed tag with a #comment and no newline should succeed' '
1097 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1098 get_tag_msg commentnonlfile-signed-tag >actual &&
1099 test_cmp expect actual &&
1100 git tag -v commentnonlfile-signed-tag
1103 # listing messages for signed tags:
1105 test_expect_success GPG \
1106 'listing the one-line message of a signed tag should succeed' '
1107 git tag -s -m "A message line signed" stag-one-line &&
1109 echo "stag-one-line" >expect &&
1110 git tag -l | grep "^stag-one-line" >actual &&
1111 test_cmp expect actual &&
1112 git tag -n0 -l | grep "^stag-one-line" >actual &&
1113 test_cmp expect actual &&
1114 git tag -n0 -l stag-one-line >actual &&
1115 test_cmp expect actual &&
1117 echo "stag-one-line A message line signed" >expect &&
1118 git tag -n1 -l | grep "^stag-one-line" >actual &&
1119 test_cmp expect actual &&
1120 git tag -n -l | grep "^stag-one-line" >actual &&
1121 test_cmp expect actual &&
1122 git tag -n1 -l stag-one-line >actual &&
1123 test_cmp expect actual &&
1124 git tag -n2 -l stag-one-line >actual &&
1125 test_cmp expect actual &&
1126 git tag -n999 -l stag-one-line >actual &&
1127 test_cmp expect actual
1130 test_expect_success GPG \
1131 'listing the zero-lines message of a signed tag should succeed' '
1132 git tag -s -m "" stag-zero-lines &&
1134 echo "stag-zero-lines" >expect &&
1135 git tag -l | grep "^stag-zero-lines" >actual &&
1136 test_cmp expect actual &&
1137 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1138 test_cmp expect actual &&
1139 git tag -n0 -l stag-zero-lines >actual &&
1140 test_cmp expect actual &&
1142 echo "stag-zero-lines " >expect &&
1143 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1144 test_cmp expect actual &&
1145 git tag -n -l | grep "^stag-zero-lines" >actual &&
1146 test_cmp expect actual &&
1147 git tag -n1 -l stag-zero-lines >actual &&
1148 test_cmp expect actual &&
1149 git tag -n2 -l stag-zero-lines >actual &&
1150 test_cmp expect actual &&
1151 git tag -n999 -l stag-zero-lines >actual &&
1152 test_cmp expect actual
1155 echo 'stag line one' >sigtagmsg
1156 echo 'stag line two' >>sigtagmsg
1157 echo 'stag line three' >>sigtagmsg
1158 test_expect_success GPG \
1159 'listing many message lines of a signed tag should succeed' '
1160 git tag -s -F sigtagmsg stag-lines &&
1162 echo "stag-lines" >expect &&
1163 git tag -l | grep "^stag-lines" >actual &&
1164 test_cmp expect actual &&
1165 git tag -n0 -l | grep "^stag-lines" >actual &&
1166 test_cmp expect actual &&
1167 git tag -n0 -l stag-lines >actual &&
1168 test_cmp expect actual &&
1170 echo "stag-lines stag line one" >expect &&
1171 git tag -n1 -l | grep "^stag-lines" >actual &&
1172 test_cmp expect actual &&
1173 git tag -n -l | grep "^stag-lines" >actual &&
1174 test_cmp expect actual &&
1175 git tag -n1 -l stag-lines >actual &&
1176 test_cmp expect actual &&
1178 echo " stag line two" >>expect &&
1179 git tag -n2 -l | grep "^ *stag.line" >actual &&
1180 test_cmp expect actual &&
1181 git tag -n2 -l stag-lines >actual &&
1182 test_cmp expect actual &&
1184 echo " stag line three" >>expect &&
1185 git tag -n3 -l | grep "^ *stag.line" >actual &&
1186 test_cmp expect actual &&
1187 git tag -n3 -l stag-lines >actual &&
1188 test_cmp expect actual &&
1189 git tag -n4 -l | grep "^ *stag.line" >actual &&
1190 test_cmp expect actual &&
1191 git tag -n4 -l stag-lines >actual &&
1192 test_cmp expect actual &&
1193 git tag -n99 -l | grep "^ *stag.line" >actual &&
1194 test_cmp expect actual &&
1195 git tag -n99 -l stag-lines >actual &&
1196 test_cmp expect actual
1199 # tags pointing to objects different from commits:
1201 tree=$(git rev-parse HEAD^{tree})
1202 blob=$(git rev-parse HEAD:foo)
1203 tag=$(git rev-parse signed-tag 2>/dev/null)
1205 get_tag_header tree-signed-tag $tree tree $time >expect
1206 echo "A message for a tree" >>expect
1207 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1208 test_expect_success GPG \
1209 'creating a signed tag pointing to a tree should succeed' '
1210 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1211 get_tag_msg tree-signed-tag >actual &&
1212 test_cmp expect actual
1215 get_tag_header blob-signed-tag $blob blob $time >expect
1216 echo "A message for a blob" >>expect
1217 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1218 test_expect_success GPG \
1219 'creating a signed tag pointing to a blob should succeed' '
1220 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1221 get_tag_msg blob-signed-tag >actual &&
1222 test_cmp expect actual
1225 get_tag_header tag-signed-tag $tag tag $time >expect
1226 echo "A message for another tag" >>expect
1227 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1228 test_expect_success GPG \
1229 'creating a signed tag pointing to another tag should succeed' '
1230 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1231 get_tag_msg tag-signed-tag >actual &&
1232 test_cmp expect actual
1235 # usage with rfc1991 signatures
1236 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1237 echo "RFC1991 signed tag" >>expect
1238 echo '-----BEGIN PGP MESSAGE-----' >>expect
1239 test_expect_success GPG,RFC1991 \
1240 'creating a signed tag with rfc1991' '
1241 echo "rfc1991" >gpghome/gpg.conf &&
1242 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1243 get_tag_msg rfc1991-signed-tag >actual &&
1244 test_cmp expect actual
1247 cat >fakeeditor <<'EOF'
1253 test_expect_success GPG,RFC1991 \
1254 'reediting a signed tag body omits signature' '
1255 echo "rfc1991" >gpghome/gpg.conf &&
1256 echo "RFC1991 signed tag" >expect &&
1257 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1258 test_cmp expect actual
1261 test_expect_success GPG,RFC1991 \
1262 'verifying rfc1991 signature' '
1263 echo "rfc1991" >gpghome/gpg.conf &&
1264 git tag -v rfc1991-signed-tag
1267 test_expect_success GPG,RFC1991 \
1268 'list tag with rfc1991 signature' '
1269 echo "rfc1991" >gpghome/gpg.conf &&
1270 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1271 git tag -l -n1 rfc1991-signed-tag >actual &&
1272 test_cmp expect actual &&
1273 git tag -l -n2 rfc1991-signed-tag >actual &&
1274 test_cmp expect actual &&
1275 git tag -l -n999 rfc1991-signed-tag >actual &&
1276 test_cmp expect actual
1279 rm -f gpghome/gpg.conf
1281 test_expect_success GPG,RFC1991 \
1282 'verifying rfc1991 signature without --rfc1991' '
1283 git tag -v rfc1991-signed-tag
1286 test_expect_success GPG,RFC1991 \
1287 'list tag with rfc1991 signature without --rfc1991' '
1288 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1289 git tag -l -n1 rfc1991-signed-tag >actual &&
1290 test_cmp expect actual &&
1291 git tag -l -n2 rfc1991-signed-tag >actual &&
1292 test_cmp expect actual &&
1293 git tag -l -n999 rfc1991-signed-tag >actual &&
1294 test_cmp expect actual
1297 test_expect_success GPG,RFC1991 \
1298 'reediting a signed tag body omits signature' '
1299 echo "RFC1991 signed tag" >expect &&
1300 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1301 test_cmp expect actual
1304 # try to sign with bad user.signingkey
1305 test_expect_success GPG \
1306 'git tag -s fails if gpg is misconfigured (bad key)' \
1307 'test_config user.signingkey BobTheMouse &&
1308 test_must_fail git tag -s -m tail tag-gpg-failure'
1310 # try to produce invalid signature
1311 test_expect_success GPG \
1312 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1313 'test_config gpg.program echo &&
1314 test_must_fail git tag -s -m tail tag-gpg-failure'
1317 # try to verify without gpg:
1320 test_expect_success GPG \
1321 'verify signed tag fails when public key is not present' \
1322 'test_must_fail git tag -v signed-tag'
1324 test_expect_success \
1325 'git tag -a fails if tag annotation is empty' '
1326 ! (GIT_EDITOR=cat git tag -a initial-comment)
1329 test_expect_success \
1330 'message in editor has initial comment' '
1331 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1334 test_expect_success 'message in editor has initial comment: first line' '
1335 # check the first line --- should be empty
1336 echo >first.expect &&
1337 sed -e 1q <actual >first.actual &&
1338 test_i18ncmp first.expect first.actual
1341 test_expect_success \
1342 'message in editor has initial comment: remainder' '
1343 # remove commented lines from the remainder -- should be empty
1345 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1346 test_cmp rest.expect rest.actual
1349 get_tag_header reuse $commit commit $time >expect
1350 echo "An annotation to be reused" >> expect
1351 test_expect_success \
1352 'overwriting an annoted tag should use its previous body' '
1353 git tag -a -m "An annotation to be reused" reuse &&
1354 GIT_EDITOR=true git tag -f -a reuse &&
1355 get_tag_msg reuse >actual &&
1356 test_cmp expect actual
1359 test_expect_success 'filename for the message is relative to cwd' '
1361 echo "Tag message in top directory" >msgfile-5 &&
1362 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1365 git tag -a -F msgfile-5 tag-from-subdir
1367 git cat-file tag tag-from-subdir | grep "in sub directory"
1370 test_expect_success 'filename for the message is relative to cwd' '
1371 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1374 git tag -a -F msgfile-6 tag-from-subdir-2
1376 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1379 # create a few more commits to test --contains
1381 hash1=$(git rev-parse HEAD)
1383 test_expect_success 'creating second commit and tag' '
1384 echo foo-2.0 >foo &&
1386 git commit -m second &&
1390 hash2=$(git rev-parse HEAD)
1392 test_expect_success 'creating third commit without tag' '
1393 echo foo-dev >foo &&
1398 hash3=$(git rev-parse HEAD)
1400 # simple linear checks of --continue
1402 cat > expected <<EOF
1410 test_expect_success 'checking that first commit is in all tags (hash)' "
1411 git tag -l --contains $hash1 v* >actual &&
1412 test_cmp expected actual
1415 # other ways of specifying the commit
1416 test_expect_success 'checking that first commit is in all tags (tag)' "
1417 git tag -l --contains v1.0 v* >actual &&
1418 test_cmp expected actual
1421 test_expect_success 'checking that first commit is in all tags (relative)' "
1422 git tag -l --contains HEAD~2 v* >actual &&
1423 test_cmp expected actual
1426 # All the --contains tests above, but with --no-contains
1427 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1429 git tag -l --no-contains $hash1 v* >actual &&
1430 test_cmp expected actual
1433 test_expect_success 'checking that first commit is in all tags (tag)' "
1434 git tag -l --no-contains v1.0 v* >actual &&
1435 test_cmp expected actual
1438 test_expect_success 'checking that first commit is in all tags (relative)' "
1439 git tag -l --no-contains HEAD~2 v* >actual &&
1440 test_cmp expected actual
1443 cat > expected <<EOF
1447 test_expect_success 'checking that second commit only has one tag' "
1448 git tag -l --contains $hash2 v* >actual &&
1449 test_cmp expected actual
1452 cat > expected <<EOF
1459 test_expect_success 'inverse of the last test, with --no-contains' "
1460 git tag -l --no-contains $hash2 v* >actual &&
1461 test_cmp expected actual
1464 cat > expected <<EOF
1467 test_expect_success 'checking that third commit has no tags' "
1468 git tag -l --contains $hash3 v* >actual &&
1469 test_cmp expected actual
1472 cat > expected <<EOF
1480 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1481 git tag -l --no-contains $hash3 v* >actual &&
1482 test_cmp expected actual
1485 # how about a simple merge?
1487 test_expect_success 'creating simple branch' '
1488 git branch stable v2.0 &&
1489 git checkout stable &&
1490 echo foo-3.0 > foo &&
1491 git commit foo -m fourth &&
1495 hash4=$(git rev-parse HEAD)
1497 cat > expected <<EOF
1501 test_expect_success 'checking that branch head only has one tag' "
1502 git tag -l --contains $hash4 v* >actual &&
1503 test_cmp expected actual
1506 cat > expected <<EOF
1514 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1515 git tag -l --no-contains $hash4 v* >actual &&
1516 test_cmp expected actual
1519 test_expect_success 'merging original branch into this branch' '
1520 git merge --strategy=ours master &&
1524 cat > expected <<EOF
1528 test_expect_success 'checking that original branch head has one tag now' "
1529 git tag -l --contains $hash3 v* >actual &&
1530 test_cmp expected actual
1533 cat > expected <<EOF
1542 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1543 git tag -l --no-contains $hash3 v* >actual &&
1544 test_cmp expected actual
1547 cat > expected <<EOF
1557 test_expect_success 'checking that initial commit is in all tags' "
1558 git tag -l --contains $hash1 v* >actual &&
1559 test_cmp expected actual
1562 test_expect_success 'checking that --contains can be used in non-list mode' '
1563 git tag --contains $hash1 v* >actual &&
1564 test_cmp expected actual
1567 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1569 git tag -l --no-contains $hash1 v* >actual &&
1570 test_cmp expected actual
1573 # mixing modes and options:
1575 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1576 test_must_fail git tag -a &&
1577 test_must_fail git tag -a -l &&
1578 test_must_fail git tag -s &&
1579 test_must_fail git tag -s -l &&
1580 test_must_fail git tag -m &&
1581 test_must_fail git tag -m -l &&
1582 test_must_fail git tag -m "hlagh" &&
1583 test_must_fail git tag -m "hlagh" -l &&
1584 test_must_fail git tag -F &&
1585 test_must_fail git tag -F -l &&
1586 test_must_fail git tag -f &&
1587 test_must_fail git tag -f -l &&
1588 test_must_fail git tag -a -s -m -F &&
1589 test_must_fail git tag -a -s -m -F -l &&
1590 test_must_fail git tag -l -v &&
1591 test_must_fail git tag -l -d &&
1592 test_must_fail git tag -l -v -d &&
1593 test_must_fail git tag -n 100 -v &&
1594 test_must_fail git tag -l -m msg &&
1595 test_must_fail git tag -l -F some file &&
1596 test_must_fail git tag -v -s &&
1597 test_must_fail git tag --contains tag-tree &&
1598 test_must_fail git tag --contains tag-blob &&
1599 test_must_fail git tag --no-contains tag-tree &&
1600 test_must_fail git tag --no-contains tag-blob &&
1601 test_must_fail git tag --contains --no-contains &&
1602 test_must_fail git tag --no-with HEAD &&
1603 test_must_fail git tag --no-without HEAD
1606 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1608 test_expect_success "mixing incompatible modes with $option is forbidden" "
1609 test_must_fail git tag -d $option HEAD &&
1610 test_must_fail git tag -d $option HEAD some-tag &&
1611 test_must_fail git tag -v $option HEAD
1613 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1614 git tag -n $option HEAD HEAD &&
1615 git tag $option HEAD HEAD &&
1622 test_expect_success '--points-at can be used in non-list mode' '
1623 echo v4.0 >expect &&
1624 git tag --points-at=v4.0 "v*" >actual &&
1625 test_cmp expect actual
1628 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1629 echo v4.0 >expect &&
1630 git tag --points-at >actual &&
1631 test_cmp expect actual
1634 test_expect_success '--points-at finds lightweight tags' '
1635 echo v4.0 >expect &&
1636 git tag --points-at v4.0 >actual &&
1637 test_cmp expect actual
1640 test_expect_success '--points-at finds annotated tags of commits' '
1641 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1642 echo annotated-v4.0 >expect &&
1643 git tag -l --points-at v4.0 "annotated*" >actual &&
1644 test_cmp expect actual
1647 test_expect_success '--points-at finds annotated tags of tags' '
1648 git tag -m "describing the v4.0 tag object" \
1649 annotated-again-v4.0 annotated-v4.0 &&
1650 cat >expect <<-\EOF &&
1651 annotated-again-v4.0
1654 git tag --points-at=annotated-v4.0 >actual &&
1655 test_cmp expect actual
1658 test_expect_success 'multiple --points-at are OR-ed together' '
1659 cat >expect <<-\EOF &&
1663 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1664 test_cmp expect actual
1667 test_expect_success 'lexical sort' '
1671 git tag -l --sort=refname "foo*" >actual &&
1672 cat >expect <<-\EOF &&
1677 test_cmp expect actual
1680 test_expect_success 'version sort' '
1681 git tag -l --sort=version:refname "foo*" >actual &&
1682 cat >expect <<-\EOF &&
1687 test_cmp expect actual
1690 test_expect_success 'reverse version sort' '
1691 git tag -l --sort=-version:refname "foo*" >actual &&
1692 cat >expect <<-\EOF &&
1697 test_cmp expect actual
1700 test_expect_success 'reverse lexical sort' '
1701 git tag -l --sort=-refname "foo*" >actual &&
1702 cat >expect <<-\EOF &&
1707 test_cmp expect actual
1710 test_expect_success 'configured lexical sort' '
1711 test_config tag.sort "v:refname" &&
1712 git tag -l "foo*" >actual &&
1713 cat >expect <<-\EOF &&
1718 test_cmp expect actual
1721 test_expect_success 'option override configured sort' '
1722 test_config tag.sort "v:refname" &&
1723 git tag -l --sort=-refname "foo*" >actual &&
1724 cat >expect <<-\EOF &&
1729 test_cmp expect actual
1732 test_expect_success 'invalid sort parameter on command line' '
1733 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1736 test_expect_success 'invalid sort parameter in configuratoin' '
1737 test_config tag.sort "v:notvalid" &&
1738 test_must_fail git tag -l "foo*"
1741 test_expect_success 'version sort with prerelease reordering' '
1742 test_config versionsort.prereleaseSuffix -rc &&
1743 git tag foo1.6-rc1 &&
1744 git tag foo1.6-rc2 &&
1745 git tag -l --sort=version:refname "foo*" >actual &&
1746 cat >expect <<-\EOF &&
1753 test_cmp expect actual
1756 test_expect_success 'reverse version sort with prerelease reordering' '
1757 test_config versionsort.prereleaseSuffix -rc &&
1758 git tag -l --sort=-version:refname "foo*" >actual &&
1759 cat >expect <<-\EOF &&
1766 test_cmp expect actual
1769 test_expect_success 'version sort with prerelease reordering and common leading character' '
1770 test_config versionsort.prereleaseSuffix -before &&
1771 git tag foo1.7-before1 &&
1773 git tag foo1.7-after1 &&
1774 git tag -l --sort=version:refname "foo1.7*" >actual &&
1775 cat >expect <<-\EOF &&
1780 test_cmp expect actual
1783 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1784 test_config versionsort.prereleaseSuffix -before &&
1785 git config --add versionsort.prereleaseSuffix -after &&
1786 git tag -l --sort=version:refname "foo1.7*" >actual &&
1787 cat >expect <<-\EOF &&
1792 test_cmp expect actual
1795 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1796 test_config versionsort.prereleaseSuffix -bar &&
1797 git config --add versionsort.prereleaseSuffix -foo-baz &&
1798 git config --add versionsort.prereleaseSuffix -foo-bar &&
1799 git tag foo1.8-foo-bar &&
1800 git tag foo1.8-foo-baz &&
1802 git tag -l --sort=version:refname "foo1.8*" >actual &&
1803 cat >expect <<-\EOF &&
1808 test_cmp expect actual
1811 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1812 test_config versionsort.prereleaseSuffix -pre &&
1813 git config --add versionsort.prereleaseSuffix -prerelease &&
1814 git tag foo1.9-pre1 &&
1815 git tag foo1.9-pre2 &&
1816 git tag foo1.9-prerelease1 &&
1817 git tag -l --sort=version:refname "foo1.9*" >actual &&
1818 cat >expect <<-\EOF &&
1823 test_cmp expect actual
1826 test_expect_success 'version sort with general suffix reordering' '
1827 test_config versionsort.suffix -alpha &&
1828 git config --add versionsort.suffix -beta &&
1829 git config --add versionsort.suffix "" &&
1830 git config --add versionsort.suffix -gamma &&
1831 git config --add versionsort.suffix -delta &&
1832 git tag foo1.10-alpha &&
1833 git tag foo1.10-beta &&
1834 git tag foo1.10-gamma &&
1835 git tag foo1.10-delta &&
1836 git tag foo1.10-unlisted-suffix &&
1837 git tag -l --sort=version:refname "foo1.10*" >actual &&
1838 cat >expect <<-\EOF &&
1842 foo1.10-unlisted-suffix
1846 test_cmp expect actual
1849 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1850 test_config versionsort.suffix -before &&
1851 test_config versionsort.prereleaseSuffix -after &&
1852 git tag -l --sort=version:refname "foo1.7*" >actual &&
1853 cat >expect <<-\EOF &&
1858 test_cmp expect actual
1861 test_expect_success 'version sort with very long prerelease suffix' '
1862 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1863 git tag -l --sort=version:refname
1866 run_with_limited_stack () {
1867 (ulimit -s 128 && "$@")
1870 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1872 # we require ulimit, this excludes Windows
1873 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1876 while test $i -lt 8000
1878 echo "commit refs/heads/master
1879 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1883 test $i = 1 && echo "from refs/heads/master^0"
1885 done | git fast-import &&
1886 git checkout master &&
1887 git tag far-far-away HEAD^ &&
1888 run_with_limited_stack git tag --contains HEAD >actual &&
1889 test_cmp expect actual &&
1890 run_with_limited_stack git tag --no-contains HEAD >actual &&
1891 test_line_count ">" 10 actual
1894 test_expect_success '--format should list tags as per format given' '
1895 cat >expect <<-\EOF &&
1896 refname : refs/tags/v1.0
1897 refname : refs/tags/v1.0.1
1898 refname : refs/tags/v1.1.3
1900 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1901 test_cmp expect actual
1904 test_expect_success "set up color tests" '
1905 echo "<RED>v1.0<RESET>" >expect.color &&
1906 echo "v1.0" >expect.bare &&
1907 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1910 test_expect_success '%(color) omitted without tty' '
1911 TERM=vt100 git tag $color_args >actual.raw &&
1912 test_decode_color <actual.raw >actual &&
1913 test_cmp expect.bare actual
1916 test_expect_success TTY '%(color) present with tty' '
1917 test_terminal env TERM=vt100 git tag $color_args >actual.raw &&
1918 test_decode_color <actual.raw >actual &&
1919 test_cmp expect.color actual
1922 test_expect_success 'color.ui=always overrides auto-color' '
1923 git -c color.ui=always tag $color_args >actual.raw &&
1924 test_decode_color <actual.raw >actual &&
1925 test_cmp expect.color actual
1928 test_expect_success 'setup --merged test tags' '
1929 git tag mergetest-1 HEAD~2 &&
1930 git tag mergetest-2 HEAD~1 &&
1931 git tag mergetest-3 HEAD
1934 test_expect_success '--merged can be used in non-list mode' '
1935 cat >expect <<-\EOF &&
1939 git tag --merged=mergetest-2 "mergetest*" >actual &&
1940 test_cmp expect actual
1943 test_expect_success '--merged is incompatible with --no-merged' '
1944 test_must_fail git tag --merged HEAD --no-merged HEAD
1947 test_expect_success '--merged shows merged tags' '
1948 cat >expect <<-\EOF &&
1952 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1953 test_cmp expect actual
1956 test_expect_success '--no-merged show unmerged tags' '
1957 cat >expect <<-\EOF &&
1960 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1961 test_cmp expect actual
1964 test_expect_success '--no-merged can be used in non-list mode' '
1965 git tag --no-merged=mergetest-2 mergetest-* >actual &&
1966 test_cmp expect actual
1969 test_expect_success 'ambiguous branch/tags not marked' '
1970 git tag ambiguous &&
1971 git branch ambiguous &&
1972 echo ambiguous >expect &&
1973 git tag -l ambiguous >actual &&
1974 test_cmp expect actual
1977 test_expect_success '--contains combined with --no-contains' '
1979 git init no-contains &&
1986 cat >expected <<-\EOF &&
1991 git tag --contains v0.2 --no-contains v0.5 >actual &&
1992 test_cmp expected actual
1996 # As the docs say, list tags which contain a specified *commit*. We
1997 # don't recurse down to tags for trees or blobs pointed to by *those*
1999 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2001 blob=$(git rev-parse v0.3:v0.3.t) &&
2002 tree=$(git rev-parse v0.3^{tree}) &&
2003 git tag tag-blob $blob &&
2004 git tag tag-tree $tree &&
2005 git tag --contains v0.3 >actual &&
2006 cat >expected <<-\EOF &&
2011 test_cmp expected actual &&
2012 git tag --no-contains v0.3 >actual &&
2013 cat >expected <<-\EOF &&
2017 test_cmp expected actual