3 # Copyright (c) 2007 Carlos Rica
6 test_description
='git tag
8 Tests for operations with tags.'
11 .
"$TEST_DIRECTORY"/lib-gpg.sh
13 # creating and listing lightweight tags:
16 git show-ref
--quiet --verify refs
/tags
/"$1"
19 test_expect_success
'listing all tags in an empty tree should succeed' '
24 test_expect_success
'listing all tags in an empty tree should output nothing' '
25 test $(git tag -l | wc -l) -eq 0 &&
26 test $(git tag | wc -l) -eq 0
29 test_expect_success
'sort tags, ignore case' '
33 test_commit initial &&
37 cat >expected <<-\EOF &&
42 test_cmp expected actual &&
43 git tag -l -i >actual &&
44 cat >expected <<-\EOF &&
49 test_cmp expected actual
53 test_expect_success
'looking for a tag in an empty tree should fail' \
54 '! (tag_exists mytag)'
56 test_expect_success
'creating a tag in an empty tree should fail' '
57 test_must_fail git tag mynotag &&
61 test_expect_success
'creating a tag for HEAD in an empty tree should fail' '
62 test_must_fail git tag mytaghead HEAD &&
63 ! tag_exists mytaghead
66 test_expect_success
'creating a tag for an unknown revision should fail' '
67 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
68 ! tag_exists mytagnorev
71 # commit used in the tests, test_tick is also called here to freeze the date:
72 test_expect_success
'creating a tag using default HEAD should succeed' '
73 test_config core.logAllRefUpdates true &&
79 test_must_fail git reflog exists refs/tags/mytag
82 test_expect_success
'creating a tag with --create-reflog should create reflog' '
84 --format="format:tag: tagging %h (%s, %cd)%n" \
85 --date=format:%Y-%m-%d >expected &&
86 test_when_finished "git tag -d tag_with_reflog" &&
87 git tag --create-reflog tag_with_reflog &&
88 git reflog exists refs/tags/tag_with_reflog &&
89 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
90 test_i18ncmp expected actual
93 test_expect_success
'annotated tag with --create-reflog has correct message' '
95 --format="format:tag: tagging %h (%s, %cd)%n" \
96 --date=format:%Y-%m-%d >expected &&
97 test_when_finished "git tag -d tag_with_reflog" &&
98 git tag -m "annotated tag" --create-reflog tag_with_reflog &&
99 git reflog exists refs/tags/tag_with_reflog &&
100 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
101 test_i18ncmp expected actual
104 test_expect_success
'--create-reflog does not create reflog on failure' '
105 test_must_fail git tag --create-reflog mytag &&
106 test_must_fail git reflog exists refs/tags/mytag
109 test_expect_success
'option core.logAllRefUpdates=always creates reflog' '
110 test_when_finished "git tag -d tag_with_reflog" &&
111 test_config core.logAllRefUpdates always &&
112 git tag tag_with_reflog &&
113 git reflog exists refs/tags/tag_with_reflog
116 test_expect_success
'listing all tags if one exists should succeed' '
124 test_expect_success
'Multiple -l or --list options are equivalent to one -l option' '
125 git tag -l -l >actual &&
126 test_cmp expect actual &&
127 git tag --list --list >actual &&
128 test_cmp expect actual &&
129 git tag --list -l --list >actual &&
130 test_cmp expect actual
133 test_expect_success
'listing all tags if one exists should output that tag' '
134 test $(git tag -l) = mytag &&
135 test $(git tag) = mytag
140 test_expect_success
'listing a tag using a matching pattern should succeed' \
143 test_expect_success
'listing a tag with --ignore-case' \
144 'test $(git tag -l --ignore-case MYTAG) = mytag'
146 test_expect_success \
147 'listing a tag using a matching pattern should output that tag' \
148 'test $(git tag -l mytag) = mytag'
150 test_expect_success \
151 'listing tags using a non-matching pattern should succeed' \
154 test_expect_success \
155 'listing tags using a non-matching pattern should output nothing' \
156 'test $(git tag -l xxx | wc -l) -eq 0'
158 # special cases for creating tags:
160 test_expect_success \
161 'trying to create a tag with the name of one existing should fail' \
162 'test_must_fail git tag mytag'
164 test_expect_success \
165 'trying to create a tag with a non-valid name should fail' '
166 test $(git tag -l | wc -l) -eq 1 &&
167 test_must_fail git tag "" &&
168 test_must_fail git tag .othertag &&
169 test_must_fail git tag "other tag" &&
170 test_must_fail git tag "othertag^" &&
171 test_must_fail git tag "other~tag" &&
172 test $(git tag -l | wc -l) -eq 1
175 test_expect_success
'creating a tag using HEAD directly should succeed' '
176 git tag myhead HEAD &&
180 test_expect_success
'--force can create a tag with the name of one existing' '
182 git tag --force mytag &&
185 test_expect_success
'--force is moot with a non-existing tag name' '
186 test_when_finished git tag -d newtag forcetag &&
187 git tag newtag >expect &&
188 git tag --force forcetag >actual &&
189 test_cmp expect actual
194 test_expect_success
'trying to delete an unknown tag should fail' '
195 ! tag_exists unknown-tag &&
196 test_must_fail git tag -d unknown-tag
203 test_expect_success \
204 'trying to delete tags without params should succeed and do nothing' '
205 git tag -l > actual && test_cmp expect actual &&
207 git tag -l > actual && test_cmp expect actual
210 test_expect_success \
211 'deleting two existing tags in one command should succeed' '
214 git tag -d mytag myhead &&
215 ! tag_exists mytag &&
219 test_expect_success \
220 'creating a tag with the name of another deleted one should succeed' '
221 ! tag_exists mytag &&
226 test_expect_success \
227 'trying to delete two tags, existing and not, should fail in the 2nd' '
229 ! tag_exists myhead &&
230 test_must_fail git tag -d mytag anothertag &&
231 ! tag_exists mytag &&
235 test_expect_success
'trying to delete an already deleted tag should fail' \
236 'test_must_fail git tag -d mytag'
238 # listing various tags with pattern matching:
251 test_expect_success
'listing all tags should print them ordered' '
261 git tag -l > actual &&
262 test_cmp expect actual &&
264 test_cmp expect actual
272 test_expect_success \
273 'listing tags with substring as pattern must print those matching' '
275 git tag -l "*a*" > current &&
276 test_cmp expect current
283 test_expect_success \
284 'listing tags with a suffix as pattern must print those matching' '
285 git tag -l "*.1" > actual &&
286 test_cmp expect actual
293 test_expect_success \
294 'listing tags with a prefix as pattern must print those matching' '
295 git tag -l "t21*" > actual &&
296 test_cmp expect actual
302 test_expect_success \
303 'listing tags using a name as pattern must print that one matching' '
304 git tag -l a1 > actual &&
305 test_cmp expect actual
311 test_expect_success \
312 'listing tags using a name as pattern must print that one matching' '
313 git tag -l v1.0 > actual &&
314 test_cmp expect actual
321 test_expect_success \
322 'listing tags with ? in the pattern should print those matching' '
323 git tag -l "v1.?.?" > actual &&
324 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_cmp expect 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=40 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
458 get_tag_header file-annotated-tag
$commit commit
$time >expect
460 test_expect_success \
461 'creating an annotated tag with -F messagefile should succeed' '
462 git tag -F msgfile file-annotated-tag &&
463 get_tag_msg file-annotated-tag >actual &&
464 test_cmp expect actual
471 get_tag_header stdin-annotated-tag
$commit commit
$time >expect
472 cat inputmsg
>>expect
473 test_expect_success
'creating an annotated tag with -F - should succeed' '
474 git tag -F - stdin-annotated-tag <inputmsg &&
475 get_tag_msg stdin-annotated-tag >actual &&
476 test_cmp expect actual
479 test_expect_success \
480 'trying to create a tag with a non-existing -F file should fail' '
481 ! test -f nonexistingfile &&
482 ! tag_exists notag &&
483 test_must_fail git tag -F nonexistingfile notag &&
487 test_expect_success \
488 'trying to create tags giving both -m or -F options should fail' '
489 echo "message file 1" >msgfile1 &&
490 echo "message file 2" >msgfile2 &&
491 ! tag_exists msgtag &&
492 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
493 ! tag_exists msgtag &&
494 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
495 ! tag_exists msgtag &&
496 test_must_fail git tag -m "message 1" -F msgfile1 \
497 -m "message 2" msgtag &&
501 # blank and empty messages:
503 get_tag_header empty-annotated-tag
$commit commit
$time >expect
504 test_expect_success \
505 'creating a tag with an empty -m message should succeed' '
506 git tag -m "" empty-annotated-tag &&
507 get_tag_msg empty-annotated-tag >actual &&
508 test_cmp expect actual
512 get_tag_header emptyfile-annotated-tag
$commit commit
$time >expect
513 test_expect_success \
514 'creating a tag with an empty -F messagefile should succeed' '
515 git tag -F emptyfile emptyfile-annotated-tag &&
516 get_tag_msg emptyfile-annotated-tag >actual &&
517 test_cmp expect actual
520 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
521 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
522 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
523 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
524 get_tag_header blanks-annotated-tag
$commit commit
$time >expect
534 test_expect_success \
535 'extra blanks in the message for an annotated tag should be removed' '
536 git tag -F blanksfile blanks-annotated-tag &&
537 get_tag_msg blanks-annotated-tag >actual &&
538 test_cmp expect actual
541 get_tag_header blank-annotated-tag
$commit commit
$time >expect
542 test_expect_success \
543 'creating a tag with blank -m message with spaces should succeed' '
544 git tag -m " " blank-annotated-tag &&
545 get_tag_msg blank-annotated-tag >actual &&
546 test_cmp expect actual
552 get_tag_header blankfile-annotated-tag
$commit commit
$time >expect
553 test_expect_success \
554 'creating a tag with blank -F messagefile with spaces should succeed' '
555 git tag -F blankfile blankfile-annotated-tag &&
556 get_tag_msg blankfile-annotated-tag >actual &&
557 test_cmp expect actual
560 printf ' ' >blanknonlfile
561 get_tag_header blanknonlfile-annotated-tag
$commit commit
$time >expect
562 test_expect_success \
563 'creating a tag with -F file of spaces and no newline should succeed' '
564 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
565 get_tag_msg blanknonlfile-annotated-tag >actual &&
566 test_cmp expect actual
569 # messages with commented lines:
571 cat >commentsfile
<<EOF
588 get_tag_header comments-annotated-tag
$commit commit
$time >expect
597 test_expect_success \
598 'creating a tag using a -F messagefile with #comments should succeed' '
599 git tag -F commentsfile comments-annotated-tag &&
600 get_tag_msg comments-annotated-tag >actual &&
601 test_cmp expect actual
604 get_tag_header comment-annotated-tag
$commit commit
$time >expect
605 test_expect_success \
606 'creating a tag with a #comment in the -m message should succeed' '
607 git tag -m "#comment" comment-annotated-tag &&
608 get_tag_msg comment-annotated-tag >actual &&
609 test_cmp expect actual
612 echo '#comment' >commentfile
613 echo '' >>commentfile
614 echo '####' >>commentfile
615 get_tag_header commentfile-annotated-tag
$commit commit
$time >expect
616 test_expect_success \
617 'creating a tag with #comments in the -F messagefile should succeed' '
618 git tag -F commentfile commentfile-annotated-tag &&
619 get_tag_msg commentfile-annotated-tag >actual &&
620 test_cmp expect actual
623 printf '#comment' >commentnonlfile
624 get_tag_header commentnonlfile-annotated-tag
$commit commit
$time >expect
625 test_expect_success \
626 'creating a tag with a file of #comment and no newline should succeed' '
627 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
628 get_tag_msg commentnonlfile-annotated-tag >actual &&
629 test_cmp expect actual
632 # listing messages for annotated non-signed tags:
634 test_expect_success \
635 'listing the one-line message of a non-signed tag should succeed' '
636 git tag -m "A msg" tag-one-line &&
638 echo "tag-one-line" >expect &&
639 git tag -l | grep "^tag-one-line" >actual &&
640 test_cmp expect actual &&
641 git tag -n0 -l | grep "^tag-one-line" >actual &&
642 test_cmp expect actual &&
643 git tag -n0 -l tag-one-line >actual &&
644 test_cmp expect actual &&
646 git tag -n0 | grep "^tag-one-line" >actual &&
647 test_cmp expect actual &&
648 git tag -n0 tag-one-line >actual &&
649 test_cmp expect actual &&
651 echo "tag-one-line A msg" >expect &&
652 git tag -n1 -l | grep "^tag-one-line" >actual &&
653 test_cmp expect actual &&
654 git tag -n -l | grep "^tag-one-line" >actual &&
655 test_cmp expect actual &&
656 git tag -n1 -l tag-one-line >actual &&
657 test_cmp expect actual &&
658 git tag -n2 -l tag-one-line >actual &&
659 test_cmp expect actual &&
660 git tag -n999 -l tag-one-line >actual &&
661 test_cmp expect actual
664 test_expect_success
'The -n 100 invocation means -n --list 100, not -n100' '
666 git tag -n 100 >actual &&
667 test_cmp expect actual &&
669 git tag -m "A msg" 100 &&
670 echo "100 A msg" >expect &&
671 git tag -n 100 >actual &&
672 test_cmp expect actual
675 test_expect_success \
676 'listing the zero-lines message of a non-signed tag should succeed' '
677 git tag -m "" tag-zero-lines &&
679 echo "tag-zero-lines" >expect &&
680 git tag -l | grep "^tag-zero-lines" >actual &&
681 test_cmp expect actual &&
682 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
683 test_cmp expect actual &&
684 git tag -n0 -l tag-zero-lines >actual &&
685 test_cmp expect actual &&
687 echo "tag-zero-lines " >expect &&
688 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
689 test_cmp expect actual &&
690 git tag -n -l | grep "^tag-zero-lines" >actual &&
691 test_cmp expect actual &&
692 git tag -n1 -l tag-zero-lines >actual &&
693 test_cmp expect actual &&
694 git tag -n2 -l tag-zero-lines >actual &&
695 test_cmp expect actual &&
696 git tag -n999 -l tag-zero-lines >actual &&
697 test_cmp expect actual
700 echo 'tag line one' >annotagmsg
701 echo 'tag line two' >>annotagmsg
702 echo 'tag line three' >>annotagmsg
703 test_expect_success \
704 'listing many message lines of a non-signed tag should succeed' '
705 git tag -F annotagmsg tag-lines &&
707 echo "tag-lines" >expect &&
708 git tag -l | grep "^tag-lines" >actual &&
709 test_cmp expect actual &&
710 git tag -n0 -l | grep "^tag-lines" >actual &&
711 test_cmp expect actual &&
712 git tag -n0 -l tag-lines >actual &&
713 test_cmp expect actual &&
715 echo "tag-lines tag line one" >expect &&
716 git tag -n1 -l | grep "^tag-lines" >actual &&
717 test_cmp expect actual &&
718 git tag -n -l | grep "^tag-lines" >actual &&
719 test_cmp expect actual &&
720 git tag -n1 -l tag-lines >actual &&
721 test_cmp expect actual &&
723 echo " tag line two" >>expect &&
724 git tag -n2 -l | grep "^ *tag.line" >actual &&
725 test_cmp expect actual &&
726 git tag -n2 -l tag-lines >actual &&
727 test_cmp expect actual &&
729 echo " tag line three" >>expect &&
730 git tag -n3 -l | grep "^ *tag.line" >actual &&
731 test_cmp expect actual &&
732 git tag -n3 -l tag-lines >actual &&
733 test_cmp expect actual &&
734 git tag -n4 -l | grep "^ *tag.line" >actual &&
735 test_cmp expect actual &&
736 git tag -n4 -l tag-lines >actual &&
737 test_cmp expect actual &&
738 git tag -n99 -l | grep "^ *tag.line" >actual &&
739 test_cmp expect actual &&
740 git tag -n99 -l tag-lines >actual &&
741 test_cmp expect actual
744 test_expect_success
'annotations for blobs are empty' '
745 blob=$(git hash-object -w --stdin <<-\EOF
751 git tag tag-blob $blob &&
752 echo "tag-blob " >expect &&
753 git tag -n1 -l tag-blob >actual &&
754 test_cmp expect actual
757 # trying to verify annotated non-signed tags:
759 test_expect_success GPG \
760 'trying to verify an annotated non-signed tag should fail' '
761 tag_exists annotated-tag &&
762 test_must_fail git tag -v annotated-tag
765 test_expect_success GPG \
766 'trying to verify a file-annotated non-signed tag should fail' '
767 tag_exists file-annotated-tag &&
768 test_must_fail git tag -v file-annotated-tag
771 test_expect_success GPG \
772 'trying to verify two annotated non-signed tags should fail' '
773 tag_exists annotated-tag file-annotated-tag &&
774 test_must_fail git tag -v annotated-tag file-annotated-tag
777 # creating and verifying signed tags:
779 get_tag_header signed-tag
$commit commit
$time >expect
780 echo 'A signed tag message' >>expect
781 echo '-----BEGIN PGP SIGNATURE-----' >>expect
782 test_expect_success GPG
'creating a signed tag with -m message should succeed' '
783 git tag -s -m "A signed tag message" signed-tag &&
784 get_tag_msg signed-tag >actual &&
785 test_cmp expect actual
788 get_tag_header u-signed-tag
$commit commit
$time >expect
789 echo 'Another message' >>expect
790 echo '-----BEGIN PGP SIGNATURE-----' >>expect
791 test_expect_success GPG
'sign with a given key id' '
793 git tag -u committer@example.com -m "Another message" u-signed-tag &&
794 get_tag_msg u-signed-tag >actual &&
795 test_cmp expect actual
799 test_expect_success GPG
'sign with an unknown id (1)' '
801 test_must_fail git tag -u author@example.com \
802 -m "Another message" o-signed-tag
806 test_expect_success GPG
'sign with an unknown id (2)' '
808 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
812 cat >fakeeditor
<<'EOF'
814 test -n "$1" && exec >"$1"
815 echo A signed tag message
816 echo from a fake editor.
820 get_tag_header implied-sign
$commit commit
$time >expect
821 .
/fakeeditor
>>expect
822 echo '-----BEGIN PGP SIGNATURE-----' >>expect
823 test_expect_success GPG
'-u implies signed tag' '
824 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
825 get_tag_msg implied-sign >actual &&
826 test_cmp expect actual
829 cat >sigmsgfile
<<EOF
833 get_tag_header file-signed-tag
$commit commit
$time >expect
834 cat sigmsgfile
>>expect
835 echo '-----BEGIN PGP SIGNATURE-----' >>expect
836 test_expect_success GPG \
837 'creating a signed tag with -F messagefile should succeed' '
838 git tag -s -F sigmsgfile file-signed-tag &&
839 get_tag_msg file-signed-tag >actual &&
840 test_cmp expect actual
843 cat >siginputmsg
<<EOF
844 A signed tag message from
847 get_tag_header stdin-signed-tag
$commit commit
$time >expect
848 cat siginputmsg
>>expect
849 echo '-----BEGIN PGP SIGNATURE-----' >>expect
850 test_expect_success GPG
'creating a signed tag with -F - should succeed' '
851 git tag -s -F - stdin-signed-tag <siginputmsg &&
852 get_tag_msg stdin-signed-tag >actual &&
853 test_cmp expect actual
856 get_tag_header implied-annotate
$commit commit
$time >expect
857 .
/fakeeditor
>>expect
858 echo '-----BEGIN PGP SIGNATURE-----' >>expect
859 test_expect_success GPG
'-s implies annotated tag' '
860 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
861 get_tag_msg implied-annotate >actual &&
862 test_cmp expect actual
865 get_tag_header forcesignannotated-implied-sign
$commit commit
$time >expect
866 echo "A message" >>expect
867 echo '-----BEGIN PGP SIGNATURE-----' >>expect
868 test_expect_success GPG \
869 'git tag -s implied if configured with tag.forcesignannotated' \
870 'test_config tag.forcesignannotated true &&
871 git tag -m "A message" forcesignannotated-implied-sign &&
872 get_tag_msg forcesignannotated-implied-sign >actual &&
873 test_cmp expect actual
876 test_expect_success GPG \
877 'lightweight with no message when configured with tag.forcesignannotated' \
878 'test_config tag.forcesignannotated true &&
879 git tag forcesignannotated-lightweight &&
880 tag_exists forcesignannotated-lightweight &&
881 test_must_fail git tag -v forcesignannotated-no-message
884 get_tag_header forcesignannotated-annotate
$commit commit
$time >expect
885 echo "A message" >>expect
886 test_expect_success GPG \
887 'git tag -a disable configured tag.forcesignannotated' \
888 'test_config tag.forcesignannotated true &&
889 git tag -a -m "A message" forcesignannotated-annotate &&
890 get_tag_msg forcesignannotated-annotate >actual &&
891 test_cmp expect actual &&
892 test_must_fail git tag -v forcesignannotated-annotate
895 get_tag_header forcesignannotated-disabled
$commit commit
$time >expect
896 echo "A message" >>expect
897 echo '-----BEGIN PGP SIGNATURE-----' >>expect
898 test_expect_success GPG \
899 'git tag --sign enable GPG sign' \
900 'test_config tag.forcesignannotated false &&
901 git tag --sign -m "A message" forcesignannotated-disabled &&
902 get_tag_msg forcesignannotated-disabled >actual &&
903 test_cmp expect actual
906 test_expect_success GPG \
907 'trying to create a signed tag with non-existing -F file should fail' '
908 ! test -f nonexistingfile &&
909 ! tag_exists nosigtag &&
910 test_must_fail git tag -s -F nonexistingfile nosigtag &&
911 ! tag_exists nosigtag
914 test_expect_success GPG
'verifying a signed tag should succeed' \
915 'git tag -v signed-tag'
917 test_expect_success GPG
'verifying two signed tags in one command should succeed' \
918 'git tag -v signed-tag file-signed-tag'
920 test_expect_success GPG \
921 'verifying many signed and non-signed tags should fail' '
922 test_must_fail git tag -v signed-tag annotated-tag &&
923 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
924 test_must_fail git tag -v annotated-tag \
925 file-signed-tag file-annotated-tag &&
926 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
929 test_expect_success GPG
'verifying a forged tag should fail' '
930 forged=$(git cat-file tag signed-tag |
931 sed -e "s/signed-tag/forged-tag/" |
933 git tag forged-tag $forged &&
934 test_must_fail git tag -v forged-tag
937 test_expect_success GPG
'verifying a proper tag with --format pass and format accordingly' '
938 cat >expect <<-\EOF &&
941 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
942 test_cmp expect actual
945 test_expect_success GPG
'verifying a forged tag with --format should fail silently' '
947 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
948 test_cmp expect actual
951 # blank and empty messages for signed tags:
953 get_tag_header empty-signed-tag
$commit commit
$time >expect
954 echo '-----BEGIN PGP SIGNATURE-----' >>expect
955 test_expect_success GPG \
956 'creating a signed tag with an empty -m message should succeed' '
957 git tag -s -m "" empty-signed-tag &&
958 get_tag_msg empty-signed-tag >actual &&
959 test_cmp expect actual &&
960 git tag -v empty-signed-tag
964 get_tag_header emptyfile-signed-tag
$commit commit
$time >expect
965 echo '-----BEGIN PGP SIGNATURE-----' >>expect
966 test_expect_success GPG \
967 'creating a signed tag with an empty -F messagefile should succeed' '
968 git tag -s -F sigemptyfile emptyfile-signed-tag &&
969 get_tag_msg emptyfile-signed-tag >actual &&
970 test_cmp expect actual &&
971 git tag -v emptyfile-signed-tag
974 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
975 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
976 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
977 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
978 get_tag_header blanks-signed-tag
$commit commit
$time >expect
988 echo '-----BEGIN PGP SIGNATURE-----' >>expect
989 test_expect_success GPG \
990 'extra blanks in the message for a signed tag should be removed' '
991 git tag -s -F sigblanksfile blanks-signed-tag &&
992 get_tag_msg blanks-signed-tag >actual &&
993 test_cmp expect actual &&
994 git tag -v blanks-signed-tag
997 get_tag_header blank-signed-tag
$commit commit
$time >expect
998 echo '-----BEGIN PGP SIGNATURE-----' >>expect
999 test_expect_success GPG \
1000 'creating a signed tag with a blank -m message should succeed' '
1001 git tag -s -m " " blank-signed-tag &&
1002 get_tag_msg blank-signed-tag >actual &&
1003 test_cmp expect actual &&
1004 git tag -v blank-signed-tag
1007 echo ' ' >sigblankfile
1008 echo '' >>sigblankfile
1009 echo ' ' >>sigblankfile
1010 get_tag_header blankfile-signed-tag
$commit commit
$time >expect
1011 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1012 test_expect_success GPG \
1013 'creating a signed tag with blank -F file with spaces should succeed' '
1014 git tag -s -F sigblankfile blankfile-signed-tag &&
1015 get_tag_msg blankfile-signed-tag >actual &&
1016 test_cmp expect actual &&
1017 git tag -v blankfile-signed-tag
1020 printf ' ' >sigblanknonlfile
1021 get_tag_header blanknonlfile-signed-tag
$commit commit
$time >expect
1022 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1023 test_expect_success GPG \
1024 'creating a signed tag with spaces and no newline should succeed' '
1025 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1026 get_tag_msg blanknonlfile-signed-tag >actual &&
1027 test_cmp expect actual &&
1028 git tag -v signed-tag
1031 # messages with commented lines for signed tags:
1033 cat >sigcommentsfile
<<EOF
1050 get_tag_header comments-signed-tag
$commit commit
$time >expect
1059 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1060 test_expect_success GPG \
1061 'creating a signed tag with a -F file with #comments should succeed' '
1062 git tag -s -F sigcommentsfile comments-signed-tag &&
1063 get_tag_msg comments-signed-tag >actual &&
1064 test_cmp expect actual &&
1065 git tag -v comments-signed-tag
1068 get_tag_header comment-signed-tag
$commit commit
$time >expect
1069 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1070 test_expect_success GPG \
1071 'creating a signed tag with #commented -m message should succeed' '
1072 git tag -s -m "#comment" comment-signed-tag &&
1073 get_tag_msg comment-signed-tag >actual &&
1074 test_cmp expect actual &&
1075 git tag -v comment-signed-tag
1078 echo '#comment' >sigcommentfile
1079 echo '' >>sigcommentfile
1080 echo '####' >>sigcommentfile
1081 get_tag_header commentfile-signed-tag
$commit commit
$time >expect
1082 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1083 test_expect_success GPG \
1084 'creating a signed tag with #commented -F messagefile should succeed' '
1085 git tag -s -F sigcommentfile commentfile-signed-tag &&
1086 get_tag_msg commentfile-signed-tag >actual &&
1087 test_cmp expect actual &&
1088 git tag -v commentfile-signed-tag
1091 printf '#comment' >sigcommentnonlfile
1092 get_tag_header commentnonlfile-signed-tag
$commit commit
$time >expect
1093 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1094 test_expect_success GPG \
1095 'creating a signed tag with a #comment and no newline should succeed' '
1096 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1097 get_tag_msg commentnonlfile-signed-tag >actual &&
1098 test_cmp expect actual &&
1099 git tag -v commentnonlfile-signed-tag
1102 # listing messages for signed tags:
1104 test_expect_success GPG \
1105 'listing the one-line message of a signed tag should succeed' '
1106 git tag -s -m "A message line signed" stag-one-line &&
1108 echo "stag-one-line" >expect &&
1109 git tag -l | grep "^stag-one-line" >actual &&
1110 test_cmp expect actual &&
1111 git tag -n0 -l | grep "^stag-one-line" >actual &&
1112 test_cmp expect actual &&
1113 git tag -n0 -l stag-one-line >actual &&
1114 test_cmp expect actual &&
1116 echo "stag-one-line A message line signed" >expect &&
1117 git tag -n1 -l | grep "^stag-one-line" >actual &&
1118 test_cmp expect actual &&
1119 git tag -n -l | grep "^stag-one-line" >actual &&
1120 test_cmp expect actual &&
1121 git tag -n1 -l stag-one-line >actual &&
1122 test_cmp expect actual &&
1123 git tag -n2 -l stag-one-line >actual &&
1124 test_cmp expect actual &&
1125 git tag -n999 -l stag-one-line >actual &&
1126 test_cmp expect actual
1129 test_expect_success GPG \
1130 'listing the zero-lines message of a signed tag should succeed' '
1131 git tag -s -m "" stag-zero-lines &&
1133 echo "stag-zero-lines" >expect &&
1134 git tag -l | grep "^stag-zero-lines" >actual &&
1135 test_cmp expect actual &&
1136 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1137 test_cmp expect actual &&
1138 git tag -n0 -l stag-zero-lines >actual &&
1139 test_cmp expect actual &&
1141 echo "stag-zero-lines " >expect &&
1142 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1143 test_cmp expect actual &&
1144 git tag -n -l | grep "^stag-zero-lines" >actual &&
1145 test_cmp expect actual &&
1146 git tag -n1 -l stag-zero-lines >actual &&
1147 test_cmp expect actual &&
1148 git tag -n2 -l stag-zero-lines >actual &&
1149 test_cmp expect actual &&
1150 git tag -n999 -l stag-zero-lines >actual &&
1151 test_cmp expect actual
1154 echo 'stag line one' >sigtagmsg
1155 echo 'stag line two' >>sigtagmsg
1156 echo 'stag line three' >>sigtagmsg
1157 test_expect_success GPG \
1158 'listing many message lines of a signed tag should succeed' '
1159 git tag -s -F sigtagmsg stag-lines &&
1161 echo "stag-lines" >expect &&
1162 git tag -l | grep "^stag-lines" >actual &&
1163 test_cmp expect actual &&
1164 git tag -n0 -l | grep "^stag-lines" >actual &&
1165 test_cmp expect actual &&
1166 git tag -n0 -l stag-lines >actual &&
1167 test_cmp expect actual &&
1169 echo "stag-lines stag line one" >expect &&
1170 git tag -n1 -l | grep "^stag-lines" >actual &&
1171 test_cmp expect actual &&
1172 git tag -n -l | grep "^stag-lines" >actual &&
1173 test_cmp expect actual &&
1174 git tag -n1 -l stag-lines >actual &&
1175 test_cmp expect actual &&
1177 echo " stag line two" >>expect &&
1178 git tag -n2 -l | grep "^ *stag.line" >actual &&
1179 test_cmp expect actual &&
1180 git tag -n2 -l stag-lines >actual &&
1181 test_cmp expect actual &&
1183 echo " stag line three" >>expect &&
1184 git tag -n3 -l | grep "^ *stag.line" >actual &&
1185 test_cmp expect actual &&
1186 git tag -n3 -l stag-lines >actual &&
1187 test_cmp expect actual &&
1188 git tag -n4 -l | grep "^ *stag.line" >actual &&
1189 test_cmp expect actual &&
1190 git tag -n4 -l stag-lines >actual &&
1191 test_cmp expect actual &&
1192 git tag -n99 -l | grep "^ *stag.line" >actual &&
1193 test_cmp expect actual &&
1194 git tag -n99 -l stag-lines >actual &&
1195 test_cmp expect actual
1198 # tags pointing to objects different from commits:
1200 tree
=$
(git rev-parse HEAD^
{tree
})
1201 blob
=$
(git rev-parse HEAD
:foo
)
1202 tag
=$
(git rev-parse signed-tag
2>/dev
/null
)
1204 get_tag_header tree-signed-tag
$tree tree
$time >expect
1205 echo "A message for a tree" >>expect
1206 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1207 test_expect_success GPG \
1208 'creating a signed tag pointing to a tree should succeed' '
1209 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1210 get_tag_msg tree-signed-tag >actual &&
1211 test_cmp expect actual
1214 get_tag_header blob-signed-tag
$blob blob
$time >expect
1215 echo "A message for a blob" >>expect
1216 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1217 test_expect_success GPG \
1218 'creating a signed tag pointing to a blob should succeed' '
1219 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1220 get_tag_msg blob-signed-tag >actual &&
1221 test_cmp expect actual
1224 get_tag_header tag-signed-tag
$tag tag
$time >expect
1225 echo "A message for another tag" >>expect
1226 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1227 test_expect_success GPG \
1228 'creating a signed tag pointing to another tag should succeed' '
1229 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1230 get_tag_msg tag-signed-tag >actual &&
1231 test_cmp expect actual
1234 # usage with rfc1991 signatures
1235 get_tag_header rfc1991-signed-tag
$commit commit
$time >expect
1236 echo "RFC1991 signed tag" >>expect
1237 echo '-----BEGIN PGP MESSAGE-----' >>expect
1238 test_expect_success GPG
,RFC1991 \
1239 'creating a signed tag with rfc1991' '
1240 echo "rfc1991" >gpghome/gpg.conf &&
1241 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1242 get_tag_msg rfc1991-signed-tag >actual &&
1243 test_cmp expect actual
1246 cat >fakeeditor
<<'EOF'
1252 test_expect_success GPG
,RFC1991 \
1253 'reediting a signed tag body omits signature' '
1254 echo "rfc1991" >gpghome/gpg.conf &&
1255 echo "RFC1991 signed tag" >expect &&
1256 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1257 test_cmp expect actual
1260 test_expect_success GPG
,RFC1991 \
1261 'verifying rfc1991 signature' '
1262 echo "rfc1991" >gpghome/gpg.conf &&
1263 git tag -v rfc1991-signed-tag
1266 test_expect_success GPG
,RFC1991 \
1267 'list tag with rfc1991 signature' '
1268 echo "rfc1991" >gpghome/gpg.conf &&
1269 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1270 git tag -l -n1 rfc1991-signed-tag >actual &&
1271 test_cmp expect actual &&
1272 git tag -l -n2 rfc1991-signed-tag >actual &&
1273 test_cmp expect actual &&
1274 git tag -l -n999 rfc1991-signed-tag >actual &&
1275 test_cmp expect actual
1278 rm -f gpghome
/gpg.conf
1280 test_expect_success GPG
,RFC1991 \
1281 'verifying rfc1991 signature without --rfc1991' '
1282 git tag -v rfc1991-signed-tag
1285 test_expect_success GPG
,RFC1991 \
1286 'list tag with rfc1991 signature without --rfc1991' '
1287 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1288 git tag -l -n1 rfc1991-signed-tag >actual &&
1289 test_cmp expect actual &&
1290 git tag -l -n2 rfc1991-signed-tag >actual &&
1291 test_cmp expect actual &&
1292 git tag -l -n999 rfc1991-signed-tag >actual &&
1293 test_cmp expect actual
1296 test_expect_success GPG
,RFC1991 \
1297 'reediting a signed tag body omits signature' '
1298 echo "RFC1991 signed tag" >expect &&
1299 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1300 test_cmp expect actual
1303 # try to sign with bad user.signingkey
1304 test_expect_success GPG \
1305 'git tag -s fails if gpg is misconfigured (bad key)' \
1306 'test_config user.signingkey BobTheMouse &&
1307 test_must_fail git tag -s -m tail tag-gpg-failure'
1309 # try to produce invalid signature
1310 test_expect_success GPG \
1311 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1312 'test_config gpg.program echo &&
1313 test_must_fail git tag -s -m tail tag-gpg-failure'
1316 # try to verify without gpg:
1319 test_expect_success GPG \
1320 'verify signed tag fails when public key is not present' \
1321 'test_must_fail git tag -v signed-tag'
1323 test_expect_success \
1324 'git tag -a fails if tag annotation is empty' '
1325 ! (GIT_EDITOR=cat git tag -a initial-comment)
1328 test_expect_success \
1329 'message in editor has initial comment' '
1330 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1333 test_expect_success
'message in editor has initial comment: first line' '
1334 # check the first line --- should be empty
1335 echo >first.expect &&
1336 sed -e 1q <actual >first.actual &&
1337 test_i18ncmp first.expect first.actual
1340 test_expect_success \
1341 'message in editor has initial comment: remainder' '
1342 # remove commented lines from the remainder -- should be empty
1344 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1345 test_cmp rest.expect rest.actual
1348 get_tag_header reuse
$commit commit
$time >expect
1349 echo "An annotation to be reused" >> expect
1350 test_expect_success \
1351 'overwriting an annoted tag should use its previous body' '
1352 git tag -a -m "An annotation to be reused" reuse &&
1353 GIT_EDITOR=true git tag -f -a reuse &&
1354 get_tag_msg reuse >actual &&
1355 test_cmp expect actual
1358 test_expect_success
'filename for the message is relative to cwd' '
1360 echo "Tag message in top directory" >msgfile-5 &&
1361 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1364 git tag -a -F msgfile-5 tag-from-subdir
1366 git cat-file tag tag-from-subdir | grep "in sub directory"
1369 test_expect_success
'filename for the message is relative to cwd' '
1370 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1373 git tag -a -F msgfile-6 tag-from-subdir-2
1375 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1378 # create a few more commits to test --contains
1380 hash1
=$
(git rev-parse HEAD
)
1382 test_expect_success
'creating second commit and tag' '
1383 echo foo-2.0 >foo &&
1385 git commit -m second &&
1389 hash2
=$
(git rev-parse HEAD
)
1391 test_expect_success
'creating third commit without tag' '
1392 echo foo-dev >foo &&
1397 hash3
=$
(git rev-parse HEAD
)
1399 # simple linear checks of --continue
1401 cat > expected
<<EOF
1409 test_expect_success
'checking that first commit is in all tags (hash)' "
1410 git tag -l --contains $hash1 v* >actual &&
1411 test_cmp expected actual
1414 # other ways of specifying the commit
1415 test_expect_success
'checking that first commit is in all tags (tag)' "
1416 git tag -l --contains v1.0 v* >actual &&
1417 test_cmp expected actual
1420 test_expect_success
'checking that first commit is in all tags (relative)' "
1421 git tag -l --contains HEAD~2 v* >actual &&
1422 test_cmp expected actual
1425 # All the --contains tests above, but with --no-contains
1426 test_expect_success
'checking that first commit is not listed in any tag with --no-contains (hash)' "
1428 git tag -l --no-contains $hash1 v* >actual &&
1429 test_cmp expected actual
1432 test_expect_success
'checking that first commit is in all tags (tag)' "
1433 git tag -l --no-contains v1.0 v* >actual &&
1434 test_cmp expected actual
1437 test_expect_success
'checking that first commit is in all tags (relative)' "
1438 git tag -l --no-contains HEAD~2 v* >actual &&
1439 test_cmp expected actual
1442 cat > expected
<<EOF
1446 test_expect_success
'checking that second commit only has one tag' "
1447 git tag -l --contains $hash2 v* >actual &&
1448 test_cmp expected actual
1451 cat > expected
<<EOF
1458 test_expect_success
'inverse of the last test, with --no-contains' "
1459 git tag -l --no-contains $hash2 v* >actual &&
1460 test_cmp expected actual
1463 cat > expected
<<EOF
1466 test_expect_success
'checking that third commit has no tags' "
1467 git tag -l --contains $hash3 v* >actual &&
1468 test_cmp expected actual
1471 cat > expected
<<EOF
1479 test_expect_success
'conversely --no-contains on the third commit lists all tags' "
1480 git tag -l --no-contains $hash3 v* >actual &&
1481 test_cmp expected actual
1484 # how about a simple merge?
1486 test_expect_success
'creating simple branch' '
1487 git branch stable v2.0 &&
1488 git checkout stable &&
1489 echo foo-3.0 > foo &&
1490 git commit foo -m fourth &&
1494 hash4
=$
(git rev-parse HEAD
)
1496 cat > expected
<<EOF
1500 test_expect_success
'checking that branch head only has one tag' "
1501 git tag -l --contains $hash4 v* >actual &&
1502 test_cmp expected actual
1505 cat > expected
<<EOF
1513 test_expect_success
'checking that branch head with --no-contains lists all but one tag' "
1514 git tag -l --no-contains $hash4 v* >actual &&
1515 test_cmp expected actual
1518 test_expect_success
'merging original branch into this branch' '
1519 git merge --strategy=ours master &&
1523 cat > expected
<<EOF
1527 test_expect_success
'checking that original branch head has one tag now' "
1528 git tag -l --contains $hash3 v* >actual &&
1529 test_cmp expected actual
1532 cat > expected
<<EOF
1541 test_expect_success
'checking that original branch head with --no-contains lists all but one tag now' "
1542 git tag -l --no-contains $hash3 v* >actual &&
1543 test_cmp expected actual
1546 cat > expected
<<EOF
1556 test_expect_success
'checking that initial commit is in all tags' "
1557 git tag -l --contains $hash1 v* >actual &&
1558 test_cmp expected actual
1561 test_expect_success
'checking that --contains can be used in non-list mode' '
1562 git tag --contains $hash1 v* >actual &&
1563 test_cmp expected actual
1566 test_expect_success
'checking that initial commit is in all tags with --no-contains' "
1568 git tag -l --no-contains $hash1 v* >actual &&
1569 test_cmp expected actual
1572 # mixing modes and options:
1574 test_expect_success
'mixing incompatibles modes and options is forbidden' '
1575 test_must_fail git tag -a &&
1576 test_must_fail git tag -a -l &&
1577 test_must_fail git tag -s &&
1578 test_must_fail git tag -s -l &&
1579 test_must_fail git tag -m &&
1580 test_must_fail git tag -m -l &&
1581 test_must_fail git tag -m "hlagh" &&
1582 test_must_fail git tag -m "hlagh" -l &&
1583 test_must_fail git tag -F &&
1584 test_must_fail git tag -F -l &&
1585 test_must_fail git tag -f &&
1586 test_must_fail git tag -f -l &&
1587 test_must_fail git tag -a -s -m -F &&
1588 test_must_fail git tag -a -s -m -F -l &&
1589 test_must_fail git tag -l -v &&
1590 test_must_fail git tag -l -d &&
1591 test_must_fail git tag -l -v -d &&
1592 test_must_fail git tag -n 100 -v &&
1593 test_must_fail git tag -l -m msg &&
1594 test_must_fail git tag -l -F some file &&
1595 test_must_fail git tag -v -s &&
1596 test_must_fail git tag --contains tag-tree &&
1597 test_must_fail git tag --contains tag-blob &&
1598 test_must_fail git tag --no-contains tag-tree &&
1599 test_must_fail git tag --no-contains tag-blob &&
1600 test_must_fail git tag --contains --no-contains &&
1601 test_must_fail git tag --no-with HEAD &&
1602 test_must_fail git tag --no-without HEAD
1605 for option
in --contains --with --no-contains --without --merged --no-merged --points-at
1607 test_expect_success
"mixing incompatible modes with $option is forbidden" "
1608 test_must_fail git tag -d $option HEAD &&
1609 test_must_fail git tag -d $option HEAD some-tag &&
1610 test_must_fail git tag -v $option HEAD
1612 test_expect_success
"Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1613 git tag -n $option HEAD HEAD &&
1614 git tag $option HEAD HEAD &&
1621 test_expect_success
'--points-at can be used in non-list mode' '
1622 echo v4.0 >expect &&
1623 git tag --points-at=v4.0 "v*" >actual &&
1624 test_cmp expect actual
1627 test_expect_success
'--points-at is a synonym for --points-at HEAD' '
1628 echo v4.0 >expect &&
1629 git tag --points-at >actual &&
1630 test_cmp expect actual
1633 test_expect_success
'--points-at finds lightweight tags' '
1634 echo v4.0 >expect &&
1635 git tag --points-at v4.0 >actual &&
1636 test_cmp expect actual
1639 test_expect_success
'--points-at finds annotated tags of commits' '
1640 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1641 echo annotated-v4.0 >expect &&
1642 git tag -l --points-at v4.0 "annotated*" >actual &&
1643 test_cmp expect actual
1646 test_expect_success
'--points-at finds annotated tags of tags' '
1647 git tag -m "describing the v4.0 tag object" \
1648 annotated-again-v4.0 annotated-v4.0 &&
1649 cat >expect <<-\EOF &&
1650 annotated-again-v4.0
1653 git tag --points-at=annotated-v4.0 >actual &&
1654 test_cmp expect actual
1657 test_expect_success
'multiple --points-at are OR-ed together' '
1658 cat >expect <<-\EOF &&
1662 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1663 test_cmp expect actual
1666 test_expect_success
'lexical sort' '
1670 git tag -l --sort=refname "foo*" >actual &&
1671 cat >expect <<-\EOF &&
1676 test_cmp expect actual
1679 test_expect_success
'version sort' '
1680 git tag -l --sort=version:refname "foo*" >actual &&
1681 cat >expect <<-\EOF &&
1686 test_cmp expect actual
1689 test_expect_success
'reverse version sort' '
1690 git tag -l --sort=-version:refname "foo*" >actual &&
1691 cat >expect <<-\EOF &&
1696 test_cmp expect actual
1699 test_expect_success
'reverse lexical sort' '
1700 git tag -l --sort=-refname "foo*" >actual &&
1701 cat >expect <<-\EOF &&
1706 test_cmp expect actual
1709 test_expect_success
'configured lexical sort' '
1710 test_config tag.sort "v:refname" &&
1711 git tag -l "foo*" >actual &&
1712 cat >expect <<-\EOF &&
1717 test_cmp expect actual
1720 test_expect_success
'option override configured sort' '
1721 test_config tag.sort "v:refname" &&
1722 git tag -l --sort=-refname "foo*" >actual &&
1723 cat >expect <<-\EOF &&
1728 test_cmp expect actual
1731 test_expect_success
'invalid sort parameter on command line' '
1732 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1735 test_expect_success
'invalid sort parameter in configuratoin' '
1736 test_config tag.sort "v:notvalid" &&
1737 test_must_fail git tag -l "foo*"
1740 test_expect_success
'version sort with prerelease reordering' '
1741 test_config versionsort.prereleaseSuffix -rc &&
1742 git tag foo1.6-rc1 &&
1743 git tag foo1.6-rc2 &&
1744 git tag -l --sort=version:refname "foo*" >actual &&
1745 cat >expect <<-\EOF &&
1752 test_cmp expect actual
1755 test_expect_success
'reverse version sort with prerelease reordering' '
1756 test_config versionsort.prereleaseSuffix -rc &&
1757 git tag -l --sort=-version:refname "foo*" >actual &&
1758 cat >expect <<-\EOF &&
1765 test_cmp expect actual
1768 test_expect_success
'version sort with prerelease reordering and common leading character' '
1769 test_config versionsort.prereleaseSuffix -before &&
1770 git tag foo1.7-before1 &&
1772 git tag foo1.7-after1 &&
1773 git tag -l --sort=version:refname "foo1.7*" >actual &&
1774 cat >expect <<-\EOF &&
1779 test_cmp expect actual
1782 test_expect_success
'version sort with prerelease reordering, multiple suffixes and common leading character' '
1783 test_config versionsort.prereleaseSuffix -before &&
1784 git config --add versionsort.prereleaseSuffix -after &&
1785 git tag -l --sort=version:refname "foo1.7*" >actual &&
1786 cat >expect <<-\EOF &&
1791 test_cmp expect actual
1794 test_expect_success
'version sort with prerelease reordering, multiple suffixes match the same tag' '
1795 test_config versionsort.prereleaseSuffix -bar &&
1796 git config --add versionsort.prereleaseSuffix -foo-baz &&
1797 git config --add versionsort.prereleaseSuffix -foo-bar &&
1798 git tag foo1.8-foo-bar &&
1799 git tag foo1.8-foo-baz &&
1801 git tag -l --sort=version:refname "foo1.8*" >actual &&
1802 cat >expect <<-\EOF &&
1807 test_cmp expect actual
1810 test_expect_success
'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1811 test_config versionsort.prereleaseSuffix -pre &&
1812 git config --add versionsort.prereleaseSuffix -prerelease &&
1813 git tag foo1.9-pre1 &&
1814 git tag foo1.9-pre2 &&
1815 git tag foo1.9-prerelease1 &&
1816 git tag -l --sort=version:refname "foo1.9*" >actual &&
1817 cat >expect <<-\EOF &&
1822 test_cmp expect actual
1825 test_expect_success
'version sort with general suffix reordering' '
1826 test_config versionsort.suffix -alpha &&
1827 git config --add versionsort.suffix -beta &&
1828 git config --add versionsort.suffix "" &&
1829 git config --add versionsort.suffix -gamma &&
1830 git config --add versionsort.suffix -delta &&
1831 git tag foo1.10-alpha &&
1832 git tag foo1.10-beta &&
1833 git tag foo1.10-gamma &&
1834 git tag foo1.10-delta &&
1835 git tag foo1.10-unlisted-suffix &&
1836 git tag -l --sort=version:refname "foo1.10*" >actual &&
1837 cat >expect <<-\EOF &&
1841 foo1.10-unlisted-suffix
1845 test_cmp expect actual
1848 test_expect_success
'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1849 test_config versionsort.suffix -before &&
1850 test_config versionsort.prereleaseSuffix -after &&
1851 git tag -l --sort=version:refname "foo1.7*" >actual &&
1852 cat >expect <<-\EOF &&
1857 test_cmp expect actual
1860 test_expect_success
'version sort with very long prerelease suffix' '
1861 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1862 git tag -l --sort=version:refname
1865 run_with_limited_stack
() {
1866 (ulimit -s 128 && "$@")
1869 test_lazy_prereq ULIMIT_STACK_SIZE
'run_with_limited_stack true'
1871 # we require ulimit, this excludes Windows
1872 test_expect_success ULIMIT_STACK_SIZE
'--contains and --no-contains work in a deep repo' '
1875 while test $i -lt 8000
1877 echo "commit refs/heads/master
1878 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1882 test $i = 1 && echo "from refs/heads/master^0"
1884 done | git fast-import &&
1885 git checkout master &&
1886 git tag far-far-away HEAD^ &&
1887 run_with_limited_stack git tag --contains HEAD >actual &&
1888 test_cmp expect actual &&
1889 run_with_limited_stack git tag --no-contains HEAD >actual &&
1890 test_line_count ">" 10 actual
1893 test_expect_success
'--format should list tags as per format given' '
1894 cat >expect <<-\EOF &&
1895 refname : refs/tags/v1.0
1896 refname : refs/tags/v1.0.1
1897 refname : refs/tags/v1.1.3
1899 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1900 test_cmp expect actual
1903 test_expect_success
'setup --merged test tags' '
1904 git tag mergetest-1 HEAD~2 &&
1905 git tag mergetest-2 HEAD~1 &&
1906 git tag mergetest-3 HEAD
1909 test_expect_success
'--merged can be used in non-list mode' '
1910 cat >expect <<-\EOF &&
1914 git tag --merged=mergetest-2 "mergetest*" >actual &&
1915 test_cmp expect actual
1918 test_expect_success
'--merged is incompatible with --no-merged' '
1919 test_must_fail git tag --merged HEAD --no-merged HEAD
1922 test_expect_success
'--merged shows merged tags' '
1923 cat >expect <<-\EOF &&
1927 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1928 test_cmp expect actual
1931 test_expect_success
'--no-merged show unmerged tags' '
1932 cat >expect <<-\EOF &&
1935 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1936 test_cmp expect actual
1939 test_expect_success
'--no-merged can be used in non-list mode' '
1940 git tag --no-merged=mergetest-2 mergetest-* >actual &&
1941 test_cmp expect actual
1944 test_expect_success
'ambiguous branch/tags not marked' '
1945 git tag ambiguous &&
1946 git branch ambiguous &&
1947 echo ambiguous >expect &&
1948 git tag -l ambiguous >actual &&
1949 test_cmp expect actual
1952 test_expect_success
'--contains combined with --no-contains' '
1954 git init no-contains &&
1961 cat >expected <<-\EOF &&
1966 git tag --contains v0.2 --no-contains v0.5 >actual &&
1967 test_cmp expected actual
1971 # As the docs say, list tags which contain a specified *commit*. We
1972 # don't recurse down to tags for trees or blobs pointed to by *those*
1974 test_expect_success
'Does --[no-]contains stop at commits? Yes!' '
1976 blob=$(git rev-parse v0.3:v0.3.t) &&
1977 tree=$(git rev-parse v0.3^{tree}) &&
1978 git tag tag-blob $blob &&
1979 git tag tag-tree $tree &&
1980 git tag --contains v0.3 >actual &&
1981 cat >expected <<-\EOF &&
1986 test_cmp expected actual &&
1987 git tag --no-contains v0.3 >actual &&
1988 cat >expected <<-\EOF &&
1992 test_cmp expected actual