3 # Copyright (c) 2007 Carlos Rica
6 test_description
='git tag
8 Tests for operations with tags.'
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 .
"$TEST_DIRECTORY"/lib-gpg.sh
15 .
"$TEST_DIRECTORY"/lib-terminal.sh
17 # creating and listing lightweight tags:
20 git show-ref
--quiet --verify refs
/tags
/"$1"
23 test_expect_success
'setup' '
25 othersigheader sha1:gpgsig-sha256
26 othersigheader sha256:gpgsig
30 test_expect_success
'listing all tags in an empty tree should succeed' '
35 test_expect_success
'listing all tags in an empty tree should output nothing' '
36 test $(git tag -l | wc -l) -eq 0 &&
37 test $(git tag | wc -l) -eq 0
40 test_expect_success
'sort tags, ignore case' '
44 test_commit initial &&
48 cat >expected <<-\EOF &&
53 test_cmp expected actual &&
54 git tag -l -i >actual &&
55 cat >expected <<-\EOF &&
60 test_cmp expected actual
64 test_expect_success
'looking for a tag in an empty tree should fail' \
65 '! (tag_exists mytag)'
67 test_expect_success
'creating a tag in an empty tree should fail' '
68 test_must_fail git tag mynotag &&
72 test_expect_success
'creating a tag for HEAD in an empty tree should fail' '
73 test_must_fail git tag mytaghead HEAD &&
74 ! tag_exists mytaghead
77 test_expect_success
'creating a tag for an unknown revision should fail' '
78 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
79 ! tag_exists mytagnorev
82 # commit used in the tests, test_tick is also called here to freeze the date:
83 test_expect_success
'creating a tag using default HEAD should succeed' '
84 test_config core.logAllRefUpdates true &&
90 test_must_fail git reflog exists refs/tags/mytag
93 test_expect_success
'creating a tag with --create-reflog should create reflog' '
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_reflog1" &&
98 git tag --create-reflog tag_with_reflog1 &&
99 git reflog exists refs/tags/tag_with_reflog1 &&
100 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual &&
101 test_cmp expected actual
104 test_expect_success
'annotated tag with --create-reflog has correct message' '
106 --format="format:tag: tagging %h (%s, %cd)%n" \
107 --date=format:%Y-%m-%d >expected &&
108 test_when_finished "git tag -d tag_with_reflog2" &&
109 git tag -m "annotated tag" --create-reflog tag_with_reflog2 &&
110 git reflog exists refs/tags/tag_with_reflog2 &&
111 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 | sed -e "s/^.* //" >actual &&
112 test_cmp expected actual
115 test_expect_success
'--create-reflog does not create reflog on failure' '
116 test_must_fail git tag --create-reflog mytag &&
117 test_must_fail git reflog exists refs/tags/mytag
120 test_expect_success
'option core.logAllRefUpdates=always creates reflog' '
121 test_when_finished "git tag -d tag_with_reflog3" &&
122 test_config core.logAllRefUpdates always &&
123 git tag tag_with_reflog3 &&
124 git reflog exists refs/tags/tag_with_reflog3
127 test_expect_success
'listing all tags if one exists should succeed' '
135 test_expect_success
'Multiple -l or --list options are equivalent to one -l option' '
136 git tag -l -l >actual &&
137 test_cmp expect actual &&
138 git tag --list --list >actual &&
139 test_cmp expect actual &&
140 git tag --list -l --list >actual &&
141 test_cmp expect actual
144 test_expect_success
'listing all tags if one exists should output that tag' '
145 test $(git tag -l) = mytag &&
146 test $(git tag) = mytag
151 test_expect_success
'listing a tag using a matching pattern should succeed' \
154 test_expect_success
'listing a tag with --ignore-case' \
155 'test $(git tag -l --ignore-case MYTAG) = mytag'
157 test_expect_success \
158 'listing a tag using a matching pattern should output that tag' \
159 'test $(git tag -l mytag) = mytag'
161 test_expect_success \
162 'listing tags using a non-matching pattern should succeed' \
165 test_expect_success \
166 'listing tags using a non-matching pattern should output nothing' \
167 'test $(git tag -l xxx | wc -l) -eq 0'
169 # special cases for creating tags:
171 test_expect_success \
172 'trying to create a tag with the name of one existing should fail' \
173 'test_must_fail git tag mytag'
175 test_expect_success \
176 'trying to create a tag with a non-valid name should fail' '
177 test $(git tag -l | wc -l) -eq 1 &&
178 test_must_fail git tag "" &&
179 test_must_fail git tag .othertag &&
180 test_must_fail git tag "other tag" &&
181 test_must_fail git tag "othertag^" &&
182 test_must_fail git tag "other~tag" &&
183 test $(git tag -l | wc -l) -eq 1
186 test_expect_success
'creating a tag using HEAD directly should succeed' '
187 git tag myhead HEAD &&
191 test_expect_success
'--force can create a tag with the name of one existing' '
193 git tag --force mytag &&
196 test_expect_success
'--force is moot with a non-existing tag name' '
197 test_when_finished git tag -d newtag forcetag &&
198 git tag newtag >expect &&
199 git tag --force forcetag >actual &&
200 test_cmp expect actual
205 test_expect_success
'trying to delete an unknown tag should fail' '
206 ! tag_exists unknown-tag &&
207 test_must_fail git tag -d unknown-tag
214 test_expect_success \
215 'trying to delete tags without params should succeed and do nothing' '
216 git tag -l > actual && test_cmp expect actual &&
218 git tag -l > actual && test_cmp expect actual
221 test_expect_success \
222 'deleting two existing tags in one command should succeed' '
225 git tag -d mytag myhead &&
226 ! tag_exists mytag &&
230 test_expect_success \
231 'creating a tag with the name of another deleted one should succeed' '
232 ! tag_exists mytag &&
237 test_expect_success \
238 'trying to delete two tags, existing and not, should fail in the 2nd' '
240 ! tag_exists nonexistingtag &&
241 test_must_fail git tag -d mytag nonexistingtag &&
242 ! tag_exists mytag &&
243 ! tag_exists nonexistingtag
246 test_expect_success
'trying to delete an already deleted tag should fail' \
247 'test_must_fail git tag -d mytag'
249 # listing various tags with pattern matching:
262 test_expect_success
'listing all tags should print them ordered' '
272 git tag -l > actual &&
273 test_cmp expect actual &&
275 test_cmp expect actual
283 test_expect_success \
284 'listing tags with substring as pattern must print those matching' '
286 git tag -l "*a*" > current &&
287 test_cmp expect current
294 test_expect_success \
295 'listing tags with a suffix as pattern must print those matching' '
296 git tag -l "*.1" > actual &&
297 test_cmp expect actual
304 test_expect_success \
305 'listing tags with a prefix as pattern must print those matching' '
306 git tag -l "t21*" > actual &&
307 test_cmp expect actual
313 test_expect_success \
314 'listing tags using a name as pattern must print that one matching' '
315 git tag -l a1 > actual &&
316 test_cmp expect actual
322 test_expect_success \
323 'listing tags using a name as pattern must print that one matching' '
324 git tag -l v1.0 > actual &&
325 test_cmp expect actual
332 test_expect_success \
333 'listing tags with ? in the pattern should print those matching' '
334 git tag -l "v1.?.?" > actual &&
335 test_cmp expect actual
338 test_expect_success \
339 'listing tags using v.* should print nothing because none have v.' '
340 git tag -l "v.*" > actual &&
341 test_must_be_empty actual
350 test_expect_success \
351 'listing tags using v* should print only those having v' '
352 git tag -l "v*" > actual &&
353 test_cmp expect actual
356 test_expect_success
'tag -l can accept multiple patterns' '
357 git tag -l "v1*" "v0*" >actual &&
358 test_cmp expect actual
361 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
362 # could leave you with the impression that "-l <pattern> -l <pattern>"
363 # was how we wanted to accept multiple patterns.
365 # This test should not imply that this is a sane thing to support. but
366 # since the documentation was worded like it was let's at least find
367 # out if we're going to break this long-documented form of taking
369 test_expect_success
'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
370 git tag -l "v1*" -l "v0*" >actual &&
371 test_cmp expect actual
374 test_expect_success
'listing tags in column' '
375 COLUMNS=41 git tag -l --column=row >actual &&
376 cat >expected <<\EOF &&
378 v0.2.1 v1.0 v1.0.1 v1.1.3
380 test_cmp expected actual
383 test_expect_success
'listing tags in column with column.*' '
384 test_config column.tag row &&
385 test_config column.ui dense &&
386 COLUMNS=40 git tag -l >actual &&
387 cat >expected <<\EOF &&
389 v0.2.1 v1.0 v1.0.1 v1.1.3
391 test_cmp expected actual
394 test_expect_success
'listing tag with -n --column should fail' '
395 test_must_fail git tag --column -n
398 test_expect_success
'listing tags -n in column with column.ui ignored' '
399 test_config column.ui "row dense" &&
400 COLUMNS=40 git tag -l -n >actual &&
401 cat >expected <<\EOF &&
412 test_cmp expected actual
415 # creating and verifying lightweight tags:
417 test_expect_success \
418 'a non-annotated tag created without parameters should point to HEAD' '
419 git tag non-annotated-tag &&
420 test $(git cat-file -t non-annotated-tag) = commit &&
421 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
424 test_expect_success
'trying to verify an unknown tag should fail' \
425 'test_must_fail git tag -v unknown-tag'
427 test_expect_success \
428 'trying to verify a non-annotated and non-signed tag should fail' \
429 'test_must_fail git tag -v non-annotated-tag'
431 test_expect_success \
432 'trying to verify many non-annotated or unknown tags, should fail' \
433 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
435 # creating annotated tags:
438 git cat-file tag
"$1" |
sed -e "/BEGIN PGP/q"
441 # run test_tick before committing always gives the time in that timezone
447 tagger C O Mitter <committer@example.com> $4 -0700
452 commit
=$
(git rev-parse HEAD
)
455 get_tag_header annotated-tag
$commit commit
$time >expect
456 echo "A message" >>expect
457 test_expect_success \
458 'creating an annotated tag with -m message should succeed' '
459 git tag -m "A message" annotated-tag &&
460 get_tag_msg annotated-tag >actual &&
461 test_cmp expect actual
464 get_tag_header annotated-tag-edit
$commit commit
$time >expect
465 echo "An edited message" >>expect
466 test_expect_success
'set up editor' '
467 write_script fakeeditor <<-\EOF
468 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
472 test_expect_success \
473 'creating an annotated tag with -m message --edit should succeed' '
474 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
475 get_tag_msg annotated-tag-edit >actual &&
476 test_cmp expect actual
483 get_tag_header file-annotated-tag
$commit commit
$time >expect
485 test_expect_success \
486 'creating an annotated tag with -F messagefile should succeed' '
487 git tag -F msgfile file-annotated-tag &&
488 get_tag_msg file-annotated-tag >actual &&
489 test_cmp expect actual
492 get_tag_header file-annotated-tag-edit
$commit commit
$time >expect
493 sed -e "s/Another message/Another edited message/g" msgfile
>>expect
494 test_expect_success
'set up editor' '
495 write_script fakeeditor <<-\EOF
496 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
500 test_expect_success \
501 'creating an annotated tag with -F messagefile --edit should succeed' '
502 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
503 get_tag_msg file-annotated-tag-edit >actual &&
504 test_cmp expect actual
511 get_tag_header stdin-annotated-tag
$commit commit
$time >expect
512 cat inputmsg
>>expect
513 test_expect_success
'creating an annotated tag with -F - should succeed' '
514 git tag -F - stdin-annotated-tag <inputmsg &&
515 get_tag_msg stdin-annotated-tag >actual &&
516 test_cmp expect actual
519 test_expect_success \
520 'trying to create a tag with a non-existing -F file should fail' '
521 ! test -f nonexistingfile &&
522 ! tag_exists notag &&
523 test_must_fail git tag -F nonexistingfile notag &&
527 test_expect_success \
528 'trying to create tags giving both -m or -F options should fail' '
529 echo "message file 1" >msgfile1 &&
530 ! tag_exists msgtag &&
531 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
532 ! tag_exists msgtag &&
533 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
534 ! tag_exists msgtag &&
535 test_must_fail git tag -m "message 1" -F msgfile1 \
536 -m "message 2" msgtag &&
540 # blank and empty messages:
542 get_tag_header empty-annotated-tag
$commit commit
$time >expect
543 test_expect_success \
544 'creating a tag with an empty -m message should succeed' '
545 git tag -m "" empty-annotated-tag &&
546 get_tag_msg empty-annotated-tag >actual &&
547 test_cmp expect actual
551 get_tag_header emptyfile-annotated-tag
$commit commit
$time >expect
552 test_expect_success \
553 'creating a tag with an empty -F messagefile should succeed' '
554 git tag -F emptyfile emptyfile-annotated-tag &&
555 get_tag_msg emptyfile-annotated-tag >actual &&
556 test_cmp expect actual
559 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
560 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
561 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
562 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
563 get_tag_header blanks-annotated-tag
$commit commit
$time >expect
573 test_expect_success \
574 'extra blanks in the message for an annotated tag should be removed' '
575 git tag -F blanksfile blanks-annotated-tag &&
576 get_tag_msg blanks-annotated-tag >actual &&
577 test_cmp expect actual
580 get_tag_header blank-annotated-tag
$commit commit
$time >expect
581 test_expect_success \
582 'creating a tag with blank -m message with spaces should succeed' '
583 git tag -m " " blank-annotated-tag &&
584 get_tag_msg blank-annotated-tag >actual &&
585 test_cmp expect actual
591 get_tag_header blankfile-annotated-tag
$commit commit
$time >expect
592 test_expect_success \
593 'creating a tag with blank -F messagefile with spaces should succeed' '
594 git tag -F blankfile blankfile-annotated-tag &&
595 get_tag_msg blankfile-annotated-tag >actual &&
596 test_cmp expect actual
599 printf ' ' >blanknonlfile
600 get_tag_header blanknonlfile-annotated-tag
$commit commit
$time >expect
601 test_expect_success \
602 'creating a tag with -F file of spaces and no newline should succeed' '
603 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
604 get_tag_msg blanknonlfile-annotated-tag >actual &&
605 test_cmp expect actual
608 # messages with commented lines:
610 cat >commentsfile
<<EOF
627 get_tag_header comments-annotated-tag
$commit commit
$time >expect
636 test_expect_success \
637 'creating a tag using a -F messagefile with #comments should succeed' '
638 git tag -F commentsfile comments-annotated-tag &&
639 get_tag_msg comments-annotated-tag >actual &&
640 test_cmp expect actual
643 get_tag_header comment-annotated-tag
$commit commit
$time >expect
644 test_expect_success \
645 'creating a tag with a #comment in the -m message should succeed' '
646 git tag -m "#comment" comment-annotated-tag &&
647 get_tag_msg comment-annotated-tag >actual &&
648 test_cmp expect actual
651 echo '#comment' >commentfile
652 echo '' >>commentfile
653 echo '####' >>commentfile
654 get_tag_header commentfile-annotated-tag
$commit commit
$time >expect
655 test_expect_success \
656 'creating a tag with #comments in the -F messagefile should succeed' '
657 git tag -F commentfile commentfile-annotated-tag &&
658 get_tag_msg commentfile-annotated-tag >actual &&
659 test_cmp expect actual
662 printf '#comment' >commentnonlfile
663 get_tag_header commentnonlfile-annotated-tag
$commit commit
$time >expect
664 test_expect_success \
665 'creating a tag with a file of #comment and no newline should succeed' '
666 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
667 get_tag_msg commentnonlfile-annotated-tag >actual &&
668 test_cmp expect actual
671 # listing messages for annotated non-signed tags:
673 test_expect_success \
674 'listing the one-line message of a non-signed tag should succeed' '
675 git tag -m "A msg" tag-one-line &&
677 echo "tag-one-line" >expect &&
678 git tag -l | grep "^tag-one-line" >actual &&
679 test_cmp expect actual &&
680 git tag -n0 -l | grep "^tag-one-line" >actual &&
681 test_cmp expect actual &&
682 git tag -n0 -l tag-one-line >actual &&
683 test_cmp expect actual &&
685 git tag -n0 | grep "^tag-one-line" >actual &&
686 test_cmp expect actual &&
687 git tag -n0 tag-one-line >actual &&
688 test_cmp expect actual &&
690 echo "tag-one-line A msg" >expect &&
691 git tag -n1 -l | grep "^tag-one-line" >actual &&
692 test_cmp expect actual &&
693 git tag -n -l | grep "^tag-one-line" >actual &&
694 test_cmp expect actual &&
695 git tag -n1 -l tag-one-line >actual &&
696 test_cmp expect actual &&
697 git tag -n2 -l tag-one-line >actual &&
698 test_cmp expect actual &&
699 git tag -n999 -l tag-one-line >actual &&
700 test_cmp expect actual
703 test_expect_success
'The -n 100 invocation means -n --list 100, not -n100' '
704 git tag -n 100 >actual &&
705 test_must_be_empty actual &&
707 git tag -m "A msg" 100 &&
708 echo "100 A msg" >expect &&
709 git tag -n 100 >actual &&
710 test_cmp expect actual
713 test_expect_success \
714 'listing the zero-lines message of a non-signed tag should succeed' '
715 git tag -m "" tag-zero-lines &&
717 echo "tag-zero-lines" >expect &&
718 git tag -l | grep "^tag-zero-lines" >actual &&
719 test_cmp expect actual &&
720 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
721 test_cmp expect actual &&
722 git tag -n0 -l tag-zero-lines >actual &&
723 test_cmp expect actual &&
725 echo "tag-zero-lines " >expect &&
726 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
727 test_cmp expect actual &&
728 git tag -n -l | grep "^tag-zero-lines" >actual &&
729 test_cmp expect actual &&
730 git tag -n1 -l tag-zero-lines >actual &&
731 test_cmp expect actual &&
732 git tag -n2 -l tag-zero-lines >actual &&
733 test_cmp expect actual &&
734 git tag -n999 -l tag-zero-lines >actual &&
735 test_cmp expect actual
738 echo 'tag line one' >annotagmsg
739 echo 'tag line two' >>annotagmsg
740 echo 'tag line three' >>annotagmsg
741 test_expect_success \
742 'listing many message lines of a non-signed tag should succeed' '
743 git tag -F annotagmsg tag-lines &&
745 echo "tag-lines" >expect &&
746 git tag -l | grep "^tag-lines" >actual &&
747 test_cmp expect actual &&
748 git tag -n0 -l | grep "^tag-lines" >actual &&
749 test_cmp expect actual &&
750 git tag -n0 -l tag-lines >actual &&
751 test_cmp expect actual &&
753 echo "tag-lines tag line one" >expect &&
754 git tag -n1 -l | grep "^tag-lines" >actual &&
755 test_cmp expect actual &&
756 git tag -n -l | grep "^tag-lines" >actual &&
757 test_cmp expect actual &&
758 git tag -n1 -l tag-lines >actual &&
759 test_cmp expect actual &&
761 echo " tag line two" >>expect &&
762 git tag -n2 -l | grep "^ *tag.line" >actual &&
763 test_cmp expect actual &&
764 git tag -n2 -l tag-lines >actual &&
765 test_cmp expect actual &&
767 echo " tag line three" >>expect &&
768 git tag -n3 -l | grep "^ *tag.line" >actual &&
769 test_cmp expect actual &&
770 git tag -n3 -l tag-lines >actual &&
771 test_cmp expect actual &&
772 git tag -n4 -l | grep "^ *tag.line" >actual &&
773 test_cmp expect actual &&
774 git tag -n4 -l tag-lines >actual &&
775 test_cmp expect actual &&
776 git tag -n99 -l | grep "^ *tag.line" >actual &&
777 test_cmp expect actual &&
778 git tag -n99 -l tag-lines >actual &&
779 test_cmp expect actual
782 test_expect_success
'annotations for blobs are empty' '
783 blob=$(git hash-object -w --stdin <<-\EOF
789 git tag tag-blob $blob &&
790 echo "tag-blob " >expect &&
791 git tag -n1 -l tag-blob >actual &&
792 test_cmp expect actual
795 # Run this before doing any signing, so the test has the same results
796 # regardless of the GPG prereq.
797 test_expect_success
'git tag --format with ahead-behind' '
798 test_when_finished git reset --hard tag-one-line &&
799 git commit --allow-empty -m "left" &&
800 git tag -a -m left tag-left &&
801 git reset --hard HEAD~1 &&
802 git commit --allow-empty -m "right" &&
803 git tag -a -m left tag-right &&
805 # Use " !" at the end to demonstrate whitespace
806 # around empty ahead-behind token for tag-blob.
807 cat >expect <<-EOF &&
809 refs/tags/tag-left 1 1 !
810 refs/tags/tag-lines 0 1 !
811 refs/tags/tag-one-line 0 1 !
812 refs/tags/tag-right 0 0 !
813 refs/tags/tag-zero-lines 0 1 !
815 git tag -l --format="%(refname) %(ahead-behind:HEAD) !" >actual 2>err &&
816 grep "refs/tags/tag" actual >actual.focus &&
817 test_cmp expect actual.focus &&
819 # Error reported for tags that point to non-commits.
820 grep "error: object [0-9a-f]* is a blob, not a commit" err
823 # trying to verify annotated non-signed tags:
825 test_expect_success GPG \
826 'trying to verify an annotated non-signed tag should fail' '
827 tag_exists annotated-tag &&
828 test_must_fail git tag -v annotated-tag
831 test_expect_success GPG \
832 'trying to verify a file-annotated non-signed tag should fail' '
833 tag_exists file-annotated-tag &&
834 test_must_fail git tag -v file-annotated-tag
837 test_expect_success GPG \
838 'trying to verify two annotated non-signed tags should fail' '
839 tag_exists annotated-tag file-annotated-tag &&
840 test_must_fail git tag -v annotated-tag file-annotated-tag
843 # creating and verifying signed tags:
845 get_tag_header signed-tag
$commit commit
$time >expect
846 echo 'A signed tag message' >>expect
847 echo '-----BEGIN PGP SIGNATURE-----' >>expect
848 test_expect_success GPG
'creating a signed tag with -m message should succeed' '
849 git tag -s -m "A signed tag message" signed-tag &&
850 get_tag_msg signed-tag >actual &&
851 test_cmp expect actual
854 get_tag_header u-signed-tag
$commit commit
$time >expect
855 echo 'Another message' >>expect
856 echo '-----BEGIN PGP SIGNATURE-----' >>expect
857 test_expect_success GPG
'sign with a given key id' '
859 git tag -u committer@example.com -m "Another message" u-signed-tag &&
860 get_tag_msg u-signed-tag >actual &&
861 test_cmp expect actual
865 test_expect_success GPG
'sign with an unknown id (1)' '
867 test_must_fail git tag -u author@example.com \
868 -m "Another message" o-signed-tag
872 test_expect_success GPG
'sign with an unknown id (2)' '
874 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
878 cat >fakeeditor
<<'EOF'
880 test -n "$1" && exec >"$1"
881 echo A signed tag message
882 echo from a fake editor.
886 get_tag_header implied-sign
$commit commit
$time >expect
887 .
/fakeeditor
>>expect
888 echo '-----BEGIN PGP SIGNATURE-----' >>expect
889 test_expect_success GPG
'-u implies signed tag' '
890 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
891 get_tag_msg implied-sign >actual &&
892 test_cmp expect actual
895 cat >sigmsgfile
<<EOF
899 get_tag_header file-signed-tag
$commit commit
$time >expect
900 cat sigmsgfile
>>expect
901 echo '-----BEGIN PGP SIGNATURE-----' >>expect
902 test_expect_success GPG \
903 'creating a signed tag with -F messagefile should succeed' '
904 git tag -s -F sigmsgfile file-signed-tag &&
905 get_tag_msg file-signed-tag >actual &&
906 test_cmp expect actual
909 cat >siginputmsg
<<EOF
910 A signed tag message from
913 get_tag_header stdin-signed-tag
$commit commit
$time >expect
914 cat siginputmsg
>>expect
915 echo '-----BEGIN PGP SIGNATURE-----' >>expect
916 test_expect_success GPG
'creating a signed tag with -F - should succeed' '
917 git tag -s -F - stdin-signed-tag <siginputmsg &&
918 get_tag_msg stdin-signed-tag >actual &&
919 test_cmp expect actual
922 get_tag_header implied-annotate
$commit commit
$time >expect
923 .
/fakeeditor
>>expect
924 echo '-----BEGIN PGP SIGNATURE-----' >>expect
925 test_expect_success GPG
'-s implies annotated tag' '
926 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
927 get_tag_msg implied-annotate >actual &&
928 test_cmp expect actual
931 get_tag_header forcesignannotated-implied-sign
$commit commit
$time >expect
932 echo "A message" >>expect
933 echo '-----BEGIN PGP SIGNATURE-----' >>expect
934 test_expect_success GPG \
935 'git tag -s implied if configured with tag.forcesignannotated' \
936 'test_config tag.forcesignannotated true &&
937 git tag -m "A message" forcesignannotated-implied-sign &&
938 get_tag_msg forcesignannotated-implied-sign >actual &&
939 test_cmp expect actual
942 test_expect_success GPG \
943 'lightweight with no message when configured with tag.forcesignannotated' \
944 'test_config tag.forcesignannotated true &&
945 git tag forcesignannotated-lightweight &&
946 tag_exists forcesignannotated-lightweight &&
947 test_must_fail git tag -v forcesignannotated-no-message
950 get_tag_header forcesignannotated-annotate
$commit commit
$time >expect
951 echo "A message" >>expect
952 test_expect_success GPG \
953 'git tag -a disable configured tag.forcesignannotated' \
954 'test_config tag.forcesignannotated true &&
955 git tag -a -m "A message" forcesignannotated-annotate &&
956 get_tag_msg forcesignannotated-annotate >actual &&
957 test_cmp expect actual &&
958 test_must_fail git tag -v forcesignannotated-annotate
961 get_tag_header forcesignannotated-disabled
$commit commit
$time >expect
962 echo "A message" >>expect
963 echo '-----BEGIN PGP SIGNATURE-----' >>expect
964 test_expect_success GPG \
965 'git tag --sign enable GPG sign' \
966 'test_config tag.forcesignannotated false &&
967 git tag --sign -m "A message" forcesignannotated-disabled &&
968 get_tag_msg forcesignannotated-disabled >actual &&
969 test_cmp expect actual
972 get_tag_header gpgsign-enabled
$commit commit
$time >expect
973 echo "A message" >>expect
974 echo '-----BEGIN PGP SIGNATURE-----' >>expect
975 test_expect_success GPG \
976 'git tag configured tag.gpgsign enables GPG sign' \
977 'test_config tag.gpgsign true &&
978 git tag -m "A message" gpgsign-enabled &&
979 get_tag_msg gpgsign-enabled>actual &&
980 test_cmp expect actual
983 get_tag_header no-sign
$commit commit
$time >expect
984 echo "A message" >>expect
985 test_expect_success GPG \
986 'git tag --no-sign configured tag.gpgsign skip GPG sign' \
987 'test_config tag.gpgsign true &&
988 git tag -a --no-sign -m "A message" no-sign &&
989 get_tag_msg no-sign>actual &&
990 test_cmp expect actual
993 test_expect_success GPG \
994 'trying to create a signed tag with non-existing -F file should fail' '
995 ! test -f nonexistingfile &&
996 ! tag_exists nosigtag &&
997 test_must_fail git tag -s -F nonexistingfile nosigtag &&
998 ! tag_exists nosigtag
1001 test_expect_success GPG
'verifying a signed tag should succeed' \
1002 'git tag -v signed-tag'
1004 test_expect_success GPG
'verifying two signed tags in one command should succeed' \
1005 'git tag -v signed-tag file-signed-tag'
1007 test_expect_success GPG \
1008 'verifying many signed and non-signed tags should fail' '
1009 test_must_fail git tag -v signed-tag annotated-tag &&
1010 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
1011 test_must_fail git tag -v annotated-tag \
1012 file-signed-tag file-annotated-tag &&
1013 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
1016 test_expect_success GPG
'verifying a forged tag should fail' '
1017 forged=$(git cat-file tag signed-tag |
1018 sed -e "s/signed-tag/forged-tag/" |
1020 git tag forged-tag $forged &&
1021 test_must_fail git tag -v forged-tag
1024 test_expect_success GPG
'verifying a proper tag with --format pass and format accordingly' '
1025 cat >expect <<-\EOF &&
1026 tagname : signed-tag
1028 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
1029 test_cmp expect actual
1032 test_expect_success GPG
'verifying a forged tag with --format should fail silently' '
1033 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
1034 test_must_be_empty actual
1037 # blank and empty messages for signed tags:
1039 get_tag_header empty-signed-tag
$commit commit
$time >expect
1040 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1041 test_expect_success GPG \
1042 'creating a signed tag with an empty -m message should succeed' '
1043 git tag -s -m "" empty-signed-tag &&
1044 get_tag_msg empty-signed-tag >actual &&
1045 test_cmp expect actual &&
1046 git tag -v empty-signed-tag
1050 get_tag_header emptyfile-signed-tag
$commit commit
$time >expect
1051 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1052 test_expect_success GPG \
1053 'creating a signed tag with an empty -F messagefile should succeed' '
1054 git tag -s -F sigemptyfile emptyfile-signed-tag &&
1055 get_tag_msg emptyfile-signed-tag >actual &&
1056 test_cmp expect actual &&
1057 git tag -v emptyfile-signed-tag
1060 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1061 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1062 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1063 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1064 get_tag_header blanks-signed-tag
$commit commit
$time >expect
1068 Repeated blank lines
1072 Trailing blank lines
1074 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1075 test_expect_success GPG \
1076 'extra blanks in the message for a signed tag should be removed' '
1077 git tag -s -F sigblanksfile blanks-signed-tag &&
1078 get_tag_msg blanks-signed-tag >actual &&
1079 test_cmp expect actual &&
1080 git tag -v blanks-signed-tag
1083 get_tag_header blank-signed-tag
$commit commit
$time >expect
1084 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1085 test_expect_success GPG \
1086 'creating a signed tag with a blank -m message should succeed' '
1087 git tag -s -m " " blank-signed-tag &&
1088 get_tag_msg blank-signed-tag >actual &&
1089 test_cmp expect actual &&
1090 git tag -v blank-signed-tag
1093 echo ' ' >sigblankfile
1094 echo '' >>sigblankfile
1095 echo ' ' >>sigblankfile
1096 get_tag_header blankfile-signed-tag
$commit commit
$time >expect
1097 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1098 test_expect_success GPG \
1099 'creating a signed tag with blank -F file with spaces should succeed' '
1100 git tag -s -F sigblankfile blankfile-signed-tag &&
1101 get_tag_msg blankfile-signed-tag >actual &&
1102 test_cmp expect actual &&
1103 git tag -v blankfile-signed-tag
1106 printf ' ' >sigblanknonlfile
1107 get_tag_header blanknonlfile-signed-tag
$commit commit
$time >expect
1108 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1109 test_expect_success GPG \
1110 'creating a signed tag with spaces and no newline should succeed' '
1111 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1112 get_tag_msg blanknonlfile-signed-tag >actual &&
1113 test_cmp expect actual &&
1114 git tag -v blanknonlfile-signed-tag
1117 test_expect_success GPG
'signed tag with embedded PGP message' '
1119 -----BEGIN PGP MESSAGE-----
1121 this is not a real PGP message
1122 -----END PGP MESSAGE-----
1124 git tag -s -F msg confusing-pgp-message &&
1125 git tag -v confusing-pgp-message
1128 # messages with commented lines for signed tags:
1130 cat >sigcommentsfile
<<EOF
1147 get_tag_header comments-signed-tag
$commit commit
$time >expect
1156 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1157 test_expect_success GPG \
1158 'creating a signed tag with a -F file with #comments should succeed' '
1159 git tag -s -F sigcommentsfile comments-signed-tag &&
1160 get_tag_msg comments-signed-tag >actual &&
1161 test_cmp expect actual &&
1162 git tag -v comments-signed-tag
1165 get_tag_header comment-signed-tag
$commit commit
$time >expect
1166 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1167 test_expect_success GPG \
1168 'creating a signed tag with #commented -m message should succeed' '
1169 git tag -s -m "#comment" comment-signed-tag &&
1170 get_tag_msg comment-signed-tag >actual &&
1171 test_cmp expect actual &&
1172 git tag -v comment-signed-tag
1175 echo '#comment' >sigcommentfile
1176 echo '' >>sigcommentfile
1177 echo '####' >>sigcommentfile
1178 get_tag_header commentfile-signed-tag
$commit commit
$time >expect
1179 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1180 test_expect_success GPG \
1181 'creating a signed tag with #commented -F messagefile should succeed' '
1182 git tag -s -F sigcommentfile commentfile-signed-tag &&
1183 get_tag_msg commentfile-signed-tag >actual &&
1184 test_cmp expect actual &&
1185 git tag -v commentfile-signed-tag
1188 printf '#comment' >sigcommentnonlfile
1189 get_tag_header commentnonlfile-signed-tag
$commit commit
$time >expect
1190 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1191 test_expect_success GPG \
1192 'creating a signed tag with a #comment and no newline should succeed' '
1193 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1194 get_tag_msg commentnonlfile-signed-tag >actual &&
1195 test_cmp expect actual &&
1196 git tag -v commentnonlfile-signed-tag
1199 # listing messages for signed tags:
1201 test_expect_success GPG \
1202 'listing the one-line message of a signed tag should succeed' '
1203 git tag -s -m "A message line signed" stag-one-line &&
1205 echo "stag-one-line" >expect &&
1206 git tag -l | grep "^stag-one-line" >actual &&
1207 test_cmp expect actual &&
1208 git tag -n0 -l | grep "^stag-one-line" >actual &&
1209 test_cmp expect actual &&
1210 git tag -n0 -l stag-one-line >actual &&
1211 test_cmp expect actual &&
1213 echo "stag-one-line A message line signed" >expect &&
1214 git tag -n1 -l | grep "^stag-one-line" >actual &&
1215 test_cmp expect actual &&
1216 git tag -n -l | grep "^stag-one-line" >actual &&
1217 test_cmp expect actual &&
1218 git tag -n1 -l stag-one-line >actual &&
1219 test_cmp expect actual &&
1220 git tag -n2 -l stag-one-line >actual &&
1221 test_cmp expect actual &&
1222 git tag -n999 -l stag-one-line >actual &&
1223 test_cmp expect actual
1226 test_expect_success GPG \
1227 'listing the zero-lines message of a signed tag should succeed' '
1228 git tag -s -m "" stag-zero-lines &&
1230 echo "stag-zero-lines" >expect &&
1231 git tag -l | grep "^stag-zero-lines" >actual &&
1232 test_cmp expect actual &&
1233 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1234 test_cmp expect actual &&
1235 git tag -n0 -l stag-zero-lines >actual &&
1236 test_cmp expect actual &&
1238 echo "stag-zero-lines " >expect &&
1239 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1240 test_cmp expect actual &&
1241 git tag -n -l | grep "^stag-zero-lines" >actual &&
1242 test_cmp expect actual &&
1243 git tag -n1 -l stag-zero-lines >actual &&
1244 test_cmp expect actual &&
1245 git tag -n2 -l stag-zero-lines >actual &&
1246 test_cmp expect actual &&
1247 git tag -n999 -l stag-zero-lines >actual &&
1248 test_cmp expect actual
1251 echo 'stag line one' >sigtagmsg
1252 echo 'stag line two' >>sigtagmsg
1253 echo 'stag line three' >>sigtagmsg
1254 test_expect_success GPG \
1255 'listing many message lines of a signed tag should succeed' '
1256 git tag -s -F sigtagmsg stag-lines &&
1258 echo "stag-lines" >expect &&
1259 git tag -l | grep "^stag-lines" >actual &&
1260 test_cmp expect actual &&
1261 git tag -n0 -l | grep "^stag-lines" >actual &&
1262 test_cmp expect actual &&
1263 git tag -n0 -l stag-lines >actual &&
1264 test_cmp expect actual &&
1266 echo "stag-lines stag line one" >expect &&
1267 git tag -n1 -l | grep "^stag-lines" >actual &&
1268 test_cmp expect actual &&
1269 git tag -n -l | grep "^stag-lines" >actual &&
1270 test_cmp expect actual &&
1271 git tag -n1 -l stag-lines >actual &&
1272 test_cmp expect actual &&
1274 echo " stag line two" >>expect &&
1275 git tag -n2 -l | grep "^ *stag.line" >actual &&
1276 test_cmp expect actual &&
1277 git tag -n2 -l stag-lines >actual &&
1278 test_cmp expect actual &&
1280 echo " stag line three" >>expect &&
1281 git tag -n3 -l | grep "^ *stag.line" >actual &&
1282 test_cmp expect actual &&
1283 git tag -n3 -l stag-lines >actual &&
1284 test_cmp expect actual &&
1285 git tag -n4 -l | grep "^ *stag.line" >actual &&
1286 test_cmp expect actual &&
1287 git tag -n4 -l stag-lines >actual &&
1288 test_cmp expect actual &&
1289 git tag -n99 -l | grep "^ *stag.line" >actual &&
1290 test_cmp expect actual &&
1291 git tag -n99 -l stag-lines >actual &&
1292 test_cmp expect actual
1295 # tags pointing to objects different from commits:
1297 tree
=$
(git rev-parse HEAD^
{tree
})
1298 blob
=$
(git rev-parse HEAD
:foo
)
1299 tag
=$
(git rev-parse signed-tag
2>/dev
/null
)
1301 get_tag_header tree-signed-tag
$tree tree
$time >expect
1302 echo "A message for a tree" >>expect
1303 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1304 test_expect_success GPG \
1305 'creating a signed tag pointing to a tree should succeed' '
1306 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1307 get_tag_msg tree-signed-tag >actual &&
1308 test_cmp expect actual
1311 get_tag_header blob-signed-tag
$blob blob
$time >expect
1312 echo "A message for a blob" >>expect
1313 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1314 test_expect_success GPG \
1315 'creating a signed tag pointing to a blob should succeed' '
1316 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1317 get_tag_msg blob-signed-tag >actual &&
1318 test_cmp expect actual
1321 get_tag_header tag-signed-tag
$tag tag
$time >expect
1322 echo "A message for another tag" >>expect
1323 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1324 test_expect_success GPG \
1325 'creating a signed tag pointing to another tag should succeed' '
1326 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1327 get_tag_msg tag-signed-tag >actual &&
1328 test_cmp expect actual
1331 # usage with rfc1991 signatures
1332 get_tag_header rfc1991-signed-tag
$commit commit
$time >expect
1333 echo "RFC1991 signed tag" >>expect
1334 echo '-----BEGIN PGP MESSAGE-----' >>expect
1335 test_expect_success GPG
,RFC1991 \
1336 'creating a signed tag with rfc1991' '
1337 echo "rfc1991" >gpghome/gpg.conf &&
1338 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1339 get_tag_msg rfc1991-signed-tag >actual &&
1340 test_cmp expect actual
1343 cat >fakeeditor
<<'EOF'
1349 test_expect_success GPG
,RFC1991 \
1350 'reediting a signed tag body omits signature' '
1351 echo "rfc1991" >gpghome/gpg.conf &&
1352 echo "RFC1991 signed tag" >expect &&
1353 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1354 test_cmp expect actual
1357 test_expect_success GPG
,RFC1991 \
1358 'verifying rfc1991 signature' '
1359 echo "rfc1991" >gpghome/gpg.conf &&
1360 git tag -v rfc1991-signed-tag
1363 test_expect_success GPG
,RFC1991 \
1364 'list tag with rfc1991 signature' '
1365 echo "rfc1991" >gpghome/gpg.conf &&
1366 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1367 git tag -l -n1 rfc1991-signed-tag >actual &&
1368 test_cmp expect actual &&
1369 git tag -l -n2 rfc1991-signed-tag >actual &&
1370 test_cmp expect actual &&
1371 git tag -l -n999 rfc1991-signed-tag >actual &&
1372 test_cmp expect actual
1375 rm -f gpghome
/gpg.conf
1377 test_expect_success GPG
,RFC1991 \
1378 'verifying rfc1991 signature without --rfc1991' '
1379 git tag -v rfc1991-signed-tag
1382 test_expect_success GPG
,RFC1991 \
1383 'list tag with rfc1991 signature without --rfc1991' '
1384 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1385 git tag -l -n1 rfc1991-signed-tag >actual &&
1386 test_cmp expect actual &&
1387 git tag -l -n2 rfc1991-signed-tag >actual &&
1388 test_cmp expect actual &&
1389 git tag -l -n999 rfc1991-signed-tag >actual &&
1390 test_cmp expect actual
1393 test_expect_success GPG
,RFC1991 \
1394 'reediting a signed tag body omits signature' '
1395 echo "RFC1991 signed tag" >expect &&
1396 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1397 test_cmp expect actual
1400 # try to sign with bad user.signingkey
1401 test_expect_success GPG \
1402 'git tag -s fails if gpg is misconfigured (bad key)' \
1403 'test_config user.signingkey BobTheMouse &&
1404 test_must_fail git tag -s -m tail tag-gpg-failure'
1406 # try to produce invalid signature
1407 test_expect_success GPG \
1408 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1409 'test_config gpg.program echo &&
1410 test_must_fail git tag -s -m tail tag-gpg-failure'
1412 # try to produce invalid signature
1413 test_expect_success GPG
'git verifies tag is valid with double signature' '
1414 git tag -s -m tail tag-gpg-double-sig &&
1415 git cat-file tag tag-gpg-double-sig >tag &&
1416 othersigheader=$(test_oid othersigheader) &&
1417 sed -ne "/^\$/q;p" tag >new-tag &&
1418 cat <<-EOM >>new-tag &&
1419 $othersigheader -----BEGIN PGP SIGNATURE-----
1421 -----END PGP SIGNATURE-----
1423 sed -e "1,/^tagger/d" tag >>new-tag &&
1424 new_tag=$(git hash-object -t tag -w new-tag) &&
1425 git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1426 git verify-tag tag-gpg-double-sig &&
1430 # try to sign with bad user.signingkey
1431 test_expect_success GPGSM \
1432 'git tag -s fails if gpgsm is misconfigured (bad key)' \
1433 'test_config user.signingkey BobTheMouse &&
1434 test_config gpg.format x509 &&
1435 test_must_fail git tag -s -m tail tag-gpg-failure'
1437 # try to produce invalid signature
1438 test_expect_success GPGSM \
1439 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1440 'test_config gpg.x509.program echo &&
1441 test_config gpg.format x509 &&
1442 test_must_fail git tag -s -m tail tag-gpg-failure'
1444 # try to verify without gpg:
1447 test_expect_success GPG \
1448 'verify signed tag fails when public key is not present' \
1449 'test_must_fail git tag -v signed-tag'
1451 test_expect_success \
1452 'git tag -a fails if tag annotation is empty' '
1453 ! (GIT_EDITOR=cat git tag -a initial-comment)
1456 test_expect_success \
1457 'message in editor has initial comment' '
1458 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1461 test_expect_success
'message in editor has initial comment: first line' '
1462 # check the first line --- should be empty
1463 echo >first.expect &&
1464 sed -e 1q <actual >first.actual &&
1465 test_cmp first.expect first.actual
1468 test_expect_success \
1469 'message in editor has initial comment: remainder' '
1470 # remove commented lines from the remainder -- should be empty
1471 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1472 test_must_be_empty rest.actual
1475 get_tag_header reuse
$commit commit
$time >expect
1476 echo "An annotation to be reused" >> expect
1477 test_expect_success \
1478 'overwriting an annotated tag should use its previous body' '
1479 git tag -a -m "An annotation to be reused" reuse &&
1480 GIT_EDITOR=true git tag -f -a reuse &&
1481 get_tag_msg reuse >actual &&
1482 test_cmp expect actual
1485 test_expect_success
'filename for the message is relative to cwd' '
1487 echo "Tag message in top directory" >msgfile-5 &&
1488 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1491 git tag -a -F msgfile-5 tag-from-subdir
1493 git cat-file tag tag-from-subdir | grep "in sub directory"
1496 test_expect_success
'filename for the message is relative to cwd' '
1497 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1500 git tag -a -F msgfile-6 tag-from-subdir-2
1502 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1505 # create a few more commits to test --contains
1507 hash1
=$
(git rev-parse HEAD
)
1509 test_expect_success
'creating second commit and tag' '
1510 echo foo-2.0 >foo &&
1512 git commit -m second &&
1516 hash2
=$
(git rev-parse HEAD
)
1518 test_expect_success
'creating third commit without tag' '
1519 echo foo-dev >foo &&
1524 hash3
=$
(git rev-parse HEAD
)
1526 # simple linear checks of --continue
1528 cat > expected
<<EOF
1536 test_expect_success
'checking that first commit is in all tags (hash)' "
1537 git tag -l --contains $hash1 v* >actual &&
1538 test_cmp expected actual
1541 # other ways of specifying the commit
1542 test_expect_success
'checking that first commit is in all tags (tag)' "
1543 git tag -l --contains v1.0 v* >actual &&
1544 test_cmp expected actual
1547 test_expect_success
'checking that first commit is in all tags (relative)' "
1548 git tag -l --contains HEAD~2 v* >actual &&
1549 test_cmp expected actual
1552 # All the --contains tests above, but with --no-contains
1553 test_expect_success
'checking that first commit is not listed in any tag with --no-contains (hash)' "
1554 git tag -l --no-contains $hash1 v* >actual &&
1555 test_must_be_empty actual
1558 test_expect_success
'checking that first commit is in all tags (tag)' "
1559 git tag -l --no-contains v1.0 v* >actual &&
1560 test_must_be_empty actual
1563 test_expect_success
'checking that first commit is in all tags (relative)' "
1564 git tag -l --no-contains HEAD~2 v* >actual &&
1565 test_must_be_empty actual
1568 cat > expected
<<EOF
1572 test_expect_success
'checking that second commit only has one tag' "
1573 git tag -l --contains $hash2 v* >actual &&
1574 test_cmp expected actual
1577 cat > expected
<<EOF
1584 test_expect_success
'inverse of the last test, with --no-contains' "
1585 git tag -l --no-contains $hash2 v* >actual &&
1586 test_cmp expected actual
1589 test_expect_success
'checking that third commit has no tags' "
1590 git tag -l --contains $hash3 v* >actual &&
1591 test_must_be_empty actual
1594 cat > expected
<<EOF
1602 test_expect_success
'conversely --no-contains on the third commit lists all tags' "
1603 git tag -l --no-contains $hash3 v* >actual &&
1604 test_cmp expected actual
1607 # how about a simple merge?
1609 test_expect_success
'creating simple branch' '
1610 git branch stable v2.0 &&
1611 git checkout stable &&
1612 echo foo-3.0 > foo &&
1613 git commit foo -m fourth &&
1617 hash4
=$
(git rev-parse HEAD
)
1619 cat > expected
<<EOF
1623 test_expect_success
'checking that branch head only has one tag' "
1624 git tag -l --contains $hash4 v* >actual &&
1625 test_cmp expected actual
1628 cat > expected
<<EOF
1636 test_expect_success
'checking that branch head with --no-contains lists all but one tag' "
1637 git tag -l --no-contains $hash4 v* >actual &&
1638 test_cmp expected actual
1641 test_expect_success
'merging original branch into this branch' '
1642 git merge --strategy=ours main &&
1646 cat > expected
<<EOF
1650 test_expect_success
'checking that original branch head has one tag now' "
1651 git tag -l --contains $hash3 v* >actual &&
1652 test_cmp expected actual
1655 cat > expected
<<EOF
1664 test_expect_success
'checking that original branch head with --no-contains lists all but one tag now' "
1665 git tag -l --no-contains $hash3 v* >actual &&
1666 test_cmp expected actual
1669 cat > expected
<<EOF
1679 test_expect_success
'checking that initial commit is in all tags' "
1680 git tag -l --contains $hash1 v* >actual &&
1681 test_cmp expected actual
1684 test_expect_success
'checking that --contains can be used in non-list mode' '
1685 git tag --contains $hash1 v* >actual &&
1686 test_cmp expected actual
1689 test_expect_success
'checking that initial commit is in all tags with --no-contains' "
1690 git tag -l --no-contains $hash1 v* >actual &&
1691 test_must_be_empty actual
1694 # mixing modes and options:
1696 test_expect_success
'mixing incompatibles modes and options is forbidden' '
1697 test_must_fail git tag -a &&
1698 test_must_fail git tag -a -l &&
1699 test_must_fail git tag -s &&
1700 test_must_fail git tag -s -l &&
1701 test_must_fail git tag -m &&
1702 test_must_fail git tag -m -l &&
1703 test_must_fail git tag -m "hlagh" &&
1704 test_must_fail git tag -m "hlagh" -l &&
1705 test_must_fail git tag -F &&
1706 test_must_fail git tag -F -l &&
1707 test_must_fail git tag -f &&
1708 test_must_fail git tag -f -l &&
1709 test_must_fail git tag -a -s -m -F &&
1710 test_must_fail git tag -a -s -m -F -l &&
1711 test_must_fail git tag -l -v &&
1712 test_must_fail git tag -l -d &&
1713 test_must_fail git tag -l -v -d &&
1714 test_must_fail git tag -n 100 -v &&
1715 test_must_fail git tag -l -m msg &&
1716 test_must_fail git tag -l -F some file &&
1717 test_must_fail git tag -v -s &&
1718 test_must_fail git tag --contains tag-tree &&
1719 test_must_fail git tag --contains tag-blob &&
1720 test_must_fail git tag --no-contains tag-tree &&
1721 test_must_fail git tag --no-contains tag-blob &&
1722 test_must_fail git tag --contains --no-contains &&
1723 test_must_fail git tag --no-with HEAD &&
1724 test_must_fail git tag --no-without HEAD
1727 for option
in --contains --with --no-contains --without --merged --no-merged --points-at
1729 test_expect_success
"mixing incompatible modes with $option is forbidden" "
1730 test_must_fail git tag -d $option HEAD &&
1731 test_must_fail git tag -d $option HEAD some-tag &&
1732 test_must_fail git tag -v $option HEAD
1734 test_expect_success
"Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1735 git tag -n $option HEAD HEAD &&
1736 git tag $option HEAD HEAD &&
1743 test_expect_success
'--points-at can be used in non-list mode' '
1744 echo v4.0 >expect &&
1745 git tag --points-at=v4.0 "v*" >actual &&
1746 test_cmp expect actual
1749 test_expect_success
'--points-at is a synonym for --points-at HEAD' '
1750 echo v4.0 >expect &&
1751 git tag --points-at >actual &&
1752 test_cmp expect actual
1755 test_expect_success
'--points-at finds lightweight tags' '
1756 echo v4.0 >expect &&
1757 git tag --points-at v4.0 >actual &&
1758 test_cmp expect actual
1761 test_expect_success
'--points-at finds annotated tags of commits' '
1762 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1763 echo annotated-v4.0 >expect &&
1764 git tag -l --points-at v4.0 "annotated*" >actual &&
1765 test_cmp expect actual
1768 test_expect_success
'--points-at finds annotated tags of tags' '
1769 git tag -m "describing the v4.0 tag object" \
1770 annotated-again-v4.0 annotated-v4.0 &&
1771 cat >expect <<-\EOF &&
1772 annotated-again-v4.0
1775 git tag --points-at=annotated-v4.0 >actual &&
1776 test_cmp expect actual
1779 test_expect_success
'recursive tagging should give advice' '
1780 sed -e "s/|$//" <<-EOF >expect &&
1781 hint: You have created a nested tag. The object referred to by your new tag is
1782 hint: already a tag. If you meant to tag the object that it points to, use:
1784 hint: git tag -f nested annotated-v4.0^{}
1785 hint: Disable this message with "git config advice.nestedTag false"
1787 git tag -m nested nested annotated-v4.0 2>actual &&
1788 test_cmp expect actual
1791 test_expect_success
'multiple --points-at are OR-ed together' '
1792 cat >expect <<-\EOF &&
1796 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1797 test_cmp expect actual
1800 test_expect_success
'lexical sort' '
1804 git tag -l --sort=refname "foo*" >actual &&
1805 cat >expect <<-\EOF &&
1810 test_cmp expect actual
1813 test_expect_success
'version sort' '
1814 git tag -l --sort=version:refname "foo*" >actual &&
1815 cat >expect <<-\EOF &&
1820 test_cmp expect actual
1823 test_expect_success
'reverse version sort' '
1824 git tag -l --sort=-version:refname "foo*" >actual &&
1825 cat >expect <<-\EOF &&
1830 test_cmp expect actual
1833 test_expect_success
'reverse lexical sort' '
1834 git tag -l --sort=-refname "foo*" >actual &&
1835 cat >expect <<-\EOF &&
1840 test_cmp expect actual
1843 test_expect_success
'configured lexical sort' '
1844 test_config tag.sort "v:refname" &&
1845 git tag -l "foo*" >actual &&
1846 cat >expect <<-\EOF &&
1851 test_cmp expect actual
1854 test_expect_success
'option override configured sort' '
1855 test_config tag.sort "v:refname" &&
1856 git tag -l --sort=-refname "foo*" >actual &&
1857 cat >expect <<-\EOF &&
1862 test_cmp expect actual
1865 test_expect_success
'invalid sort parameter on command line' '
1866 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1869 test_expect_success
'invalid sort parameter in configuratoin' '
1870 test_config tag.sort "v:notvalid" &&
1871 test_must_fail git tag -l "foo*"
1874 test_expect_success
'version sort handles empty value for versionsort.{prereleaseSuffix,suffix}' '
1875 cp .git/config .git/config.orig &&
1876 test_when_finished mv .git/config.orig .git/config &&
1878 cat >>.git/config <<-\EOF &&
1883 cat >expect <<-\EOF &&
1884 error: missing value for '\''versionsort.suffix'\''
1885 error: missing value for '\''versionsort.prereleasesuffix'\''
1887 git tag -l --sort=version:refname 2>actual &&
1888 test_cmp expect actual
1891 test_expect_success
'version sort with prerelease reordering' '
1892 test_config versionsort.prereleaseSuffix -rc &&
1893 git tag foo1.6-rc1 &&
1894 git tag foo1.6-rc2 &&
1895 git tag -l --sort=version:refname "foo*" >actual &&
1896 cat >expect <<-\EOF &&
1903 test_cmp expect actual
1906 test_expect_success
'reverse version sort with prerelease reordering' '
1907 test_config versionsort.prereleaseSuffix -rc &&
1908 git tag -l --sort=-version:refname "foo*" >actual &&
1909 cat >expect <<-\EOF &&
1916 test_cmp expect actual
1919 test_expect_success
'version sort with prerelease reordering and common leading character' '
1920 test_config versionsort.prereleaseSuffix -before &&
1921 git tag foo1.7-before1 &&
1923 git tag foo1.7-after1 &&
1924 git tag -l --sort=version:refname "foo1.7*" >actual &&
1925 cat >expect <<-\EOF &&
1930 test_cmp expect actual
1933 test_expect_success
'version sort with prerelease reordering, multiple suffixes and common leading character' '
1934 test_config versionsort.prereleaseSuffix -before &&
1935 git config --add versionsort.prereleaseSuffix -after &&
1936 git tag -l --sort=version:refname "foo1.7*" >actual &&
1937 cat >expect <<-\EOF &&
1942 test_cmp expect actual
1945 test_expect_success
'version sort with prerelease reordering, multiple suffixes match the same tag' '
1946 test_config versionsort.prereleaseSuffix -bar &&
1947 git config --add versionsort.prereleaseSuffix -foo-baz &&
1948 git config --add versionsort.prereleaseSuffix -foo-bar &&
1949 git tag foo1.8-foo-bar &&
1950 git tag foo1.8-foo-baz &&
1952 git tag -l --sort=version:refname "foo1.8*" >actual &&
1953 cat >expect <<-\EOF &&
1958 test_cmp expect actual
1961 test_expect_success
'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1962 test_config versionsort.prereleaseSuffix -pre &&
1963 git config --add versionsort.prereleaseSuffix -prerelease &&
1964 git tag foo1.9-pre1 &&
1965 git tag foo1.9-pre2 &&
1966 git tag foo1.9-prerelease1 &&
1967 git tag -l --sort=version:refname "foo1.9*" >actual &&
1968 cat >expect <<-\EOF &&
1973 test_cmp expect actual
1976 test_expect_success
'version sort with general suffix reordering' '
1977 test_config versionsort.suffix -alpha &&
1978 git config --add versionsort.suffix -beta &&
1979 git config --add versionsort.suffix "" &&
1980 git config --add versionsort.suffix -gamma &&
1981 git config --add versionsort.suffix -delta &&
1982 git tag foo1.10-alpha &&
1983 git tag foo1.10-beta &&
1984 git tag foo1.10-gamma &&
1985 git tag foo1.10-delta &&
1986 git tag foo1.10-unlisted-suffix &&
1987 git tag -l --sort=version:refname "foo1.10*" >actual &&
1988 cat >expect <<-\EOF &&
1992 foo1.10-unlisted-suffix
1996 test_cmp expect actual
1999 test_expect_success
'versionsort.suffix overrides versionsort.prereleaseSuffix' '
2000 test_config versionsort.suffix -before &&
2001 test_config versionsort.prereleaseSuffix -after &&
2002 git tag -l --sort=version:refname "foo1.7*" >actual &&
2003 cat >expect <<-\EOF &&
2008 test_cmp expect actual
2011 test_expect_success
'version sort with very long prerelease suffix' '
2012 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
2013 git tag -l --sort=version:refname
2016 test_expect_success ULIMIT_STACK_SIZE
'--contains and --no-contains work in a deep repo' '
2018 while test $i -lt 8000
2020 echo "commit refs/heads/main
2021 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
2027 echo "from refs/heads/main^0"
2029 i=$(($i + 1)) || return 1
2030 done | git fast-import &&
2031 git checkout main &&
2032 git tag far-far-away HEAD^ &&
2033 run_with_limited_stack git tag --contains HEAD >actual &&
2034 test_must_be_empty actual &&
2035 run_with_limited_stack git tag --no-contains HEAD >actual &&
2036 test_line_count "-gt" 10 actual
2039 test_expect_success
'--format should list tags as per format given' '
2040 cat >expect <<-\EOF &&
2041 refname : refs/tags/v1.0
2042 refname : refs/tags/v1.0.1
2043 refname : refs/tags/v1.1.3
2045 git tag -l --format="refname : %(refname)" "v1*" >actual &&
2046 test_cmp expect actual
2049 test_expect_success
'--format --omit-empty works' '
2050 cat >expect <<-\EOF &&
2051 refname : refs/tags/v1.0
2053 refname : refs/tags/v1.1.3
2055 git tag -l --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2056 test_cmp expect actual &&
2057 cat >expect <<-\EOF &&
2058 refname : refs/tags/v1.0
2059 refname : refs/tags/v1.1.3
2061 git tag -l --omit-empty --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2062 test_cmp expect actual
2065 test_expect_success
'git tag -l with --format="%(rest)" must fail' '
2066 test_must_fail git tag -l --format="%(rest)" "v1*"
2069 test_expect_success
"set up color tests" '
2070 echo "<RED>v1.0<RESET>" >expect.color &&
2071 echo "v1.0" >expect.bare &&
2072 color_args="--format=%(color:red)%(refname:short) --list v1.0"
2075 test_expect_success
'%(color) omitted without tty' '
2076 TERM=vt100 git tag $color_args >actual.raw &&
2077 test_decode_color <actual.raw >actual &&
2078 test_cmp expect.bare actual
2081 test_expect_success TTY
'%(color) present with tty' '
2082 test_terminal git tag $color_args >actual.raw &&
2083 test_decode_color <actual.raw >actual &&
2084 test_cmp expect.color actual
2087 test_expect_success
'--color overrides auto-color' '
2088 git tag --color $color_args >actual.raw &&
2089 test_decode_color <actual.raw >actual &&
2090 test_cmp expect.color actual
2093 test_expect_success
'color.ui=always overrides auto-color' '
2094 git -c color.ui=always tag $color_args >actual.raw &&
2095 test_decode_color <actual.raw >actual &&
2096 test_cmp expect.color actual
2099 test_expect_success
'setup --merged test tags' '
2100 git tag mergetest-1 HEAD~2 &&
2101 git tag mergetest-2 HEAD~1 &&
2102 git tag mergetest-3 HEAD
2105 test_expect_success
'--merged can be used in non-list mode' '
2106 cat >expect <<-\EOF &&
2110 git tag --merged=mergetest-2 "mergetest*" >actual &&
2111 test_cmp expect actual
2114 test_expect_success
'--merged is compatible with --no-merged' '
2115 git tag --merged HEAD --no-merged HEAD
2118 test_expect_success
'--merged shows merged tags' '
2119 cat >expect <<-\EOF &&
2123 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2124 test_cmp expect actual
2127 test_expect_success
'--no-merged show unmerged tags' '
2128 cat >expect <<-\EOF &&
2131 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2132 test_cmp expect actual
2135 test_expect_success
'--no-merged can be used in non-list mode' '
2136 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2137 test_cmp expect actual
2140 test_expect_success
'ambiguous branch/tags not marked' '
2141 git tag ambiguous &&
2142 git branch ambiguous &&
2143 echo ambiguous >expect &&
2144 git tag -l ambiguous >actual &&
2145 test_cmp expect actual
2148 test_expect_success
'--contains combined with --no-contains' '
2150 git init no-contains &&
2157 cat >expected <<-\EOF &&
2162 git tag --contains v0.2 --no-contains v0.5 >actual &&
2163 test_cmp expected actual
2167 # As the docs say, list tags which contain a specified *commit*. We
2168 # don't recurse down to tags for trees or blobs pointed to by *those*
2170 test_expect_success
'Does --[no-]contains stop at commits? Yes!' '
2172 blob=$(git rev-parse v0.3:v0.3.t) &&
2173 tree=$(git rev-parse v0.3^{tree}) &&
2174 git tag tag-blob $blob &&
2175 git tag tag-tree $tree &&
2176 git tag --contains v0.3 >actual &&
2177 cat >expected <<-\EOF &&
2182 test_cmp expected actual &&
2183 git tag --no-contains v0.3 >actual &&
2184 cat >expected <<-\EOF &&
2188 test_cmp expected actual
2191 test_expect_success
'If tag is created then tag message file is unlinked' '
2192 test_when_finished "git tag -d foo" &&
2193 write_script fakeeditor <<-\EOF &&
2194 echo Message >.git/TAG_EDITMSG
2196 GIT_EDITOR=./fakeeditor git tag -a foo &&
2197 test_path_is_missing .git/TAG_EDITMSG
2200 test_expect_success
'If tag cannot be created then tag message file is not unlinked' '
2201 test_when_finished "git tag -d foo/bar && rm .git/TAG_EDITMSG" &&
2202 write_script fakeeditor <<-\EOF &&
2203 echo Message >.git/TAG_EDITMSG
2206 test_must_fail env GIT_EDITOR=./fakeeditor git tag -a foo &&
2207 test_path_exists .git/TAG_EDITMSG