3 # Copyright (c) 2007 Carlos Rica
6 test_description
='git tag
8 Tests for operations with tags.'
12 # creating and listing lightweight tags:
15 git show-ref
--quiet --verify refs
/tags
/"$1"
18 # todo: git tag -l now returns always zero, when fixed, change this test
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
'looking for a tag in an empty tree should fail' \
30 '! (tag_exists mytag)'
32 test_expect_success
'creating a tag in an empty tree should fail' '
33 test_must_fail git tag mynotag &&
37 test_expect_success
'creating a tag for HEAD in an empty tree should fail' '
38 test_must_fail git tag mytaghead HEAD &&
39 ! tag_exists mytaghead
42 test_expect_success
'creating a tag for an unknown revision should fail' '
43 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
44 ! tag_exists mytagnorev
47 # commit used in the tests, test_tick is also called here to freeze the date:
48 test_expect_success
'creating a tag using default HEAD should succeed' '
56 test_expect_success
'listing all tags if one exists should succeed' '
61 test_expect_success
'listing all tags if one exists should output that tag' '
62 test `git tag -l` = mytag &&
63 test `git tag` = mytag
68 test_expect_success
'listing a tag using a matching pattern should succeed' \
72 'listing a tag using a matching pattern should output that tag' \
73 'test `git tag -l mytag` = mytag'
75 # todo: git tag -l now returns always zero, when fixed, change this test
77 'listing tags using a non-matching pattern should suceed' \
81 'listing tags using a non-matching pattern should output nothing' \
82 'test `git tag -l xxx | wc -l` -eq 0'
84 # special cases for creating tags:
87 'trying to create a tag with the name of one existing should fail' \
88 'test_must_fail git tag mytag'
91 'trying to create a tag with a non-valid name should fail' '
92 test `git tag -l | wc -l` -eq 1 &&
93 test_must_fail git tag "" &&
94 test_must_fail git tag .othertag &&
95 test_must_fail git tag "other tag" &&
96 test_must_fail git tag "othertag^" &&
97 test_must_fail git tag "other~tag" &&
98 test `git tag -l | wc -l` -eq 1
101 test_expect_success
'creating a tag using HEAD directly should succeed' '
102 git tag myhead HEAD &&
108 test_expect_success
'trying to delete an unknown tag should fail' '
109 ! tag_exists unknown-tag &&
110 test_must_fail git tag -d unknown-tag
117 test_expect_success \
118 'trying to delete tags without params should succeed and do nothing' '
119 git tag -l > actual && test_cmp expect actual &&
121 git tag -l > actual && test_cmp expect actual
124 test_expect_success \
125 'deleting two existing tags in one command should succeed' '
128 git tag -d mytag myhead &&
129 ! tag_exists mytag &&
133 test_expect_success \
134 'creating a tag with the name of another deleted one should succeed' '
135 ! tag_exists mytag &&
140 test_expect_success \
141 'trying to delete two tags, existing and not, should fail in the 2nd' '
143 ! tag_exists myhead &&
144 test_must_fail git tag -d mytag anothertag &&
145 ! tag_exists mytag &&
149 test_expect_success
'trying to delete an already deleted tag should fail' \
150 'test_must_fail git tag -d mytag'
152 # listing various tags with pattern matching:
165 test_expect_success
'listing all tags should print them ordered' '
175 git tag -l > actual &&
176 test_cmp expect actual &&
178 test_cmp expect actual
186 test_expect_success \
187 'listing tags with substring as pattern must print those matching' '
189 git tag -l "*a*" > current &&
190 test_cmp expect current
197 test_expect_success \
198 'listing tags with a suffix as pattern must print those matching' '
199 git tag -l "*.1" > actual &&
200 test_cmp expect actual
207 test_expect_success \
208 'listing tags with a prefix as pattern must print those matching' '
209 git tag -l "t21*" > actual &&
210 test_cmp expect actual
216 test_expect_success \
217 'listing tags using a name as pattern must print that one matching' '
218 git tag -l a1 > actual &&
219 test_cmp expect actual
225 test_expect_success \
226 'listing tags using a name as pattern must print that one matching' '
227 git tag -l v1.0 > actual &&
228 test_cmp expect actual
235 test_expect_success \
236 'listing tags with ? in the pattern should print those matching' '
237 git tag -l "v1.?.?" > actual &&
238 test_cmp expect actual
242 test_expect_success \
243 'listing tags using v.* should print nothing because none have v.' '
244 git tag -l "v.*" > actual &&
245 test_cmp expect actual
254 test_expect_success \
255 'listing tags using v* should print only those having v' '
256 git tag -l "v*" > actual &&
257 test_cmp expect actual
260 # creating and verifying lightweight tags:
262 test_expect_success \
263 'a non-annotated tag created without parameters should point to HEAD' '
264 git tag non-annotated-tag &&
265 test $(git cat-file -t non-annotated-tag) = commit &&
266 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
269 test_expect_success
'trying to verify an unknown tag should fail' \
270 'test_must_fail git tag -v unknown-tag'
272 test_expect_success \
273 'trying to verify a non-annotated and non-signed tag should fail' \
274 'test_must_fail git tag -v non-annotated-tag'
276 test_expect_success \
277 'trying to verify many non-annotated or unknown tags, should fail' \
278 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
280 # creating annotated tags:
283 git cat-file tag
"$1" |
sed -e "/BEGIN PGP/q"
286 # run test_tick before committing always gives the time in that timezone
292 tagger C O Mitter <committer@example.com> $4 -0700
297 commit
=$
(git rev-parse HEAD
)
300 get_tag_header annotated-tag
$commit commit
$time >expect
301 echo "A message" >>expect
302 test_expect_success \
303 'creating an annotated tag with -m message should succeed' '
304 git tag -m "A message" annotated-tag &&
305 get_tag_msg annotated-tag >actual &&
306 test_cmp expect actual
313 get_tag_header file-annotated-tag
$commit commit
$time >expect
315 test_expect_success \
316 'creating an annotated tag with -F messagefile should succeed' '
317 git tag -F msgfile file-annotated-tag &&
318 get_tag_msg file-annotated-tag >actual &&
319 test_cmp expect actual
326 get_tag_header stdin-annotated-tag
$commit commit
$time >expect
327 cat inputmsg
>>expect
328 test_expect_success
'creating an annotated tag with -F - should succeed' '
329 git tag -F - stdin-annotated-tag <inputmsg &&
330 get_tag_msg stdin-annotated-tag >actual &&
331 test_cmp expect actual
334 test_expect_success \
335 'trying to create a tag with a non-existing -F file should fail' '
336 ! test -f nonexistingfile &&
337 ! tag_exists notag &&
338 test_must_fail git tag -F nonexistingfile notag &&
342 test_expect_success \
343 'trying to create tags giving both -m or -F options should fail' '
344 echo "message file 1" >msgfile1 &&
345 echo "message file 2" >msgfile2 &&
346 ! tag_exists msgtag &&
347 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
348 ! tag_exists msgtag &&
349 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
350 ! tag_exists msgtag &&
351 test_must_fail git tag -m "message 1" -F msgfile1 \
352 -m "message 2" msgtag &&
356 # blank and empty messages:
358 get_tag_header empty-annotated-tag
$commit commit
$time >expect
359 test_expect_success \
360 'creating a tag with an empty -m message should succeed' '
361 git tag -m "" empty-annotated-tag &&
362 get_tag_msg empty-annotated-tag >actual &&
363 test_cmp expect actual
367 get_tag_header emptyfile-annotated-tag
$commit commit
$time >expect
368 test_expect_success \
369 'creating a tag with an empty -F messagefile should succeed' '
370 git tag -F emptyfile emptyfile-annotated-tag &&
371 get_tag_msg emptyfile-annotated-tag >actual &&
372 test_cmp expect actual
375 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
376 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
377 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
378 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
379 get_tag_header blanks-annotated-tag
$commit commit
$time >expect
389 test_expect_success \
390 'extra blanks in the message for an annotated tag should be removed' '
391 git tag -F blanksfile blanks-annotated-tag &&
392 get_tag_msg blanks-annotated-tag >actual &&
393 test_cmp expect actual
396 get_tag_header blank-annotated-tag
$commit commit
$time >expect
397 test_expect_success \
398 'creating a tag with blank -m message with spaces should succeed' '
399 git tag -m " " blank-annotated-tag &&
400 get_tag_msg blank-annotated-tag >actual &&
401 test_cmp expect actual
407 get_tag_header blankfile-annotated-tag
$commit commit
$time >expect
408 test_expect_success \
409 'creating a tag with blank -F messagefile with spaces should succeed' '
410 git tag -F blankfile blankfile-annotated-tag &&
411 get_tag_msg blankfile-annotated-tag >actual &&
412 test_cmp expect actual
415 printf ' ' >blanknonlfile
416 get_tag_header blanknonlfile-annotated-tag
$commit commit
$time >expect
417 test_expect_success \
418 'creating a tag with -F file of spaces and no newline should succeed' '
419 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
420 get_tag_msg blanknonlfile-annotated-tag >actual &&
421 test_cmp expect actual
424 # messages with commented lines:
426 cat >commentsfile
<<EOF
443 get_tag_header comments-annotated-tag
$commit commit
$time >expect
452 test_expect_success \
453 'creating a tag using a -F messagefile with #comments should succeed' '
454 git tag -F commentsfile comments-annotated-tag &&
455 get_tag_msg comments-annotated-tag >actual &&
456 test_cmp expect actual
459 get_tag_header comment-annotated-tag
$commit commit
$time >expect
460 test_expect_success \
461 'creating a tag with a #comment in the -m message should succeed' '
462 git tag -m "#comment" comment-annotated-tag &&
463 get_tag_msg comment-annotated-tag >actual &&
464 test_cmp expect actual
467 echo '#comment' >commentfile
468 echo '' >>commentfile
469 echo '####' >>commentfile
470 get_tag_header commentfile-annotated-tag
$commit commit
$time >expect
471 test_expect_success \
472 'creating a tag with #comments in the -F messagefile should succeed' '
473 git tag -F commentfile commentfile-annotated-tag &&
474 get_tag_msg commentfile-annotated-tag >actual &&
475 test_cmp expect actual
478 printf '#comment' >commentnonlfile
479 get_tag_header commentnonlfile-annotated-tag
$commit commit
$time >expect
480 test_expect_success \
481 'creating a tag with a file of #comment and no newline should succeed' '
482 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
483 get_tag_msg commentnonlfile-annotated-tag >actual &&
484 test_cmp expect actual
487 # listing messages for annotated non-signed tags:
489 test_expect_success \
490 'listing the one-line message of a non-signed tag should succeed' '
491 git tag -m "A msg" tag-one-line &&
493 echo "tag-one-line" >expect &&
494 git tag -l | grep "^tag-one-line" >actual &&
495 test_cmp expect actual &&
496 git tag -n0 -l | grep "^tag-one-line" >actual &&
497 test_cmp expect actual &&
498 git tag -n0 -l tag-one-line >actual &&
499 test_cmp expect actual &&
501 echo "tag-one-line A msg" >expect &&
502 git tag -n1 -l | grep "^tag-one-line" >actual &&
503 test_cmp expect actual &&
504 git tag -n -l | grep "^tag-one-line" >actual &&
505 test_cmp expect actual &&
506 git tag -n1 -l tag-one-line >actual &&
507 test_cmp expect actual &&
508 git tag -n2 -l tag-one-line >actual &&
509 test_cmp expect actual &&
510 git tag -n999 -l tag-one-line >actual &&
511 test_cmp expect actual
514 test_expect_success \
515 'listing the zero-lines message of a non-signed tag should succeed' '
516 git tag -m "" tag-zero-lines &&
518 echo "tag-zero-lines" >expect &&
519 git tag -l | grep "^tag-zero-lines" >actual &&
520 test_cmp expect actual &&
521 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
522 test_cmp expect actual &&
523 git tag -n0 -l tag-zero-lines >actual &&
524 test_cmp expect actual &&
526 echo "tag-zero-lines " >expect &&
527 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
528 test_cmp expect actual &&
529 git tag -n -l | grep "^tag-zero-lines" >actual &&
530 test_cmp expect actual &&
531 git tag -n1 -l tag-zero-lines >actual &&
532 test_cmp expect actual &&
533 git tag -n2 -l tag-zero-lines >actual &&
534 test_cmp expect actual &&
535 git tag -n999 -l tag-zero-lines >actual &&
536 test_cmp expect actual
539 echo 'tag line one' >annotagmsg
540 echo 'tag line two' >>annotagmsg
541 echo 'tag line three' >>annotagmsg
542 test_expect_success \
543 'listing many message lines of a non-signed tag should succeed' '
544 git tag -F annotagmsg tag-lines &&
546 echo "tag-lines" >expect &&
547 git tag -l | grep "^tag-lines" >actual &&
548 test_cmp expect actual &&
549 git tag -n0 -l | grep "^tag-lines" >actual &&
550 test_cmp expect actual &&
551 git tag -n0 -l tag-lines >actual &&
552 test_cmp expect actual &&
554 echo "tag-lines tag line one" >expect &&
555 git tag -n1 -l | grep "^tag-lines" >actual &&
556 test_cmp expect actual &&
557 git tag -n -l | grep "^tag-lines" >actual &&
558 test_cmp expect actual &&
559 git tag -n1 -l tag-lines >actual &&
560 test_cmp expect actual &&
562 echo " tag line two" >>expect &&
563 git tag -n2 -l | grep "^ *tag.line" >actual &&
564 test_cmp expect actual &&
565 git tag -n2 -l tag-lines >actual &&
566 test_cmp expect actual &&
568 echo " tag line three" >>expect &&
569 git tag -n3 -l | grep "^ *tag.line" >actual &&
570 test_cmp expect actual &&
571 git tag -n3 -l tag-lines >actual &&
572 test_cmp expect actual &&
573 git tag -n4 -l | grep "^ *tag.line" >actual &&
574 test_cmp expect actual &&
575 git tag -n4 -l tag-lines >actual &&
576 test_cmp expect actual &&
577 git tag -n99 -l | grep "^ *tag.line" >actual &&
578 test_cmp expect actual &&
579 git tag -n99 -l tag-lines >actual &&
580 test_cmp expect actual
583 # subsequent tests require gpg; check if it is available
584 gpg
--version >/dev
/null
585 if [ $?
-eq 127 ]; then
586 say
"gpg not found - skipping tag signing and verification tests"
591 # trying to verify annotated non-signed tags:
593 test_expect_success \
594 'trying to verify an annotated non-signed tag should fail' '
595 tag_exists annotated-tag &&
596 test_must_fail git tag -v annotated-tag
599 test_expect_success \
600 'trying to verify a file-annotated non-signed tag should fail' '
601 tag_exists file-annotated-tag &&
602 test_must_fail git tag -v file-annotated-tag
605 test_expect_success \
606 'trying to verify two annotated non-signed tags should fail' '
607 tag_exists annotated-tag file-annotated-tag &&
608 test_must_fail git tag -v annotated-tag file-annotated-tag
611 # creating and verifying signed tags:
613 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
614 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
615 # that version, creation of signed tags using the generated key fails.
616 case "$(gpg --version)" in
617 'gpg (GnuPG) 1.0.6'*)
618 say
"Skipping signed tag tests, because a bug in 1.0.6 version"
624 # key generation info: gpg --homedir t/t7004 --gen-key
625 # Type DSA and Elgamal, size 2048 bits, no expiration date.
626 # Name and email: C O Mitter <committer@example.com>
627 # No password given, to enable non-interactive operation.
629 cp -R "$TEST_DIRECTORY"/t7004 .
/gpghome
631 GNUPGHOME
="$(pwd)/gpghome"
634 get_tag_header signed-tag
$commit commit
$time >expect
635 echo 'A signed tag message' >>expect
636 echo '-----BEGIN PGP SIGNATURE-----' >>expect
637 test_expect_success
'creating a signed tag with -m message should succeed' '
638 git tag -s -m "A signed tag message" signed-tag &&
639 get_tag_msg signed-tag >actual &&
640 test_cmp expect actual
643 get_tag_header u-signed-tag
$commit commit
$time >expect
644 echo 'Another message' >>expect
645 echo '-----BEGIN PGP SIGNATURE-----' >>expect
646 test_expect_success
'sign with a given key id' '
648 git tag -u committer@example.com -m "Another message" u-signed-tag &&
649 get_tag_msg u-signed-tag >actual &&
650 test_cmp expect actual
654 test_expect_success
'sign with an unknown id (1)' '
656 test_must_fail git tag -u author@example.com \
657 -m "Another message" o-signed-tag
661 test_expect_success
'sign with an unknown id (2)' '
663 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
667 cat >fakeeditor
<<'EOF'
669 test -n "$1" && exec >"$1"
670 echo A signed tag message
671 echo from a fake editor.
675 get_tag_header implied-sign
$commit commit
$time >expect
676 .
/fakeeditor
>>expect
677 echo '-----BEGIN PGP SIGNATURE-----' >>expect
678 test_expect_success
'-u implies signed tag' '
679 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
680 get_tag_msg implied-sign >actual &&
681 test_cmp expect actual
684 cat >sigmsgfile
<<EOF
688 get_tag_header file-signed-tag
$commit commit
$time >expect
689 cat sigmsgfile
>>expect
690 echo '-----BEGIN PGP SIGNATURE-----' >>expect
691 test_expect_success \
692 'creating a signed tag with -F messagefile should succeed' '
693 git tag -s -F sigmsgfile file-signed-tag &&
694 get_tag_msg file-signed-tag >actual &&
695 test_cmp expect actual
698 cat >siginputmsg
<<EOF
699 A signed tag message from
702 get_tag_header stdin-signed-tag
$commit commit
$time >expect
703 cat siginputmsg
>>expect
704 echo '-----BEGIN PGP SIGNATURE-----' >>expect
705 test_expect_success
'creating a signed tag with -F - should succeed' '
706 git tag -s -F - stdin-signed-tag <siginputmsg &&
707 get_tag_msg stdin-signed-tag >actual &&
708 test_cmp expect actual
711 get_tag_header implied-annotate
$commit commit
$time >expect
712 .
/fakeeditor
>>expect
713 echo '-----BEGIN PGP SIGNATURE-----' >>expect
714 test_expect_success
'-s implies annotated tag' '
715 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
716 get_tag_msg implied-annotate >actual &&
717 test_cmp expect actual
720 test_expect_success \
721 'trying to create a signed tag with non-existing -F file should fail' '
722 ! test -f nonexistingfile &&
723 ! tag_exists nosigtag &&
724 test_must_fail git tag -s -F nonexistingfile nosigtag &&
725 ! tag_exists nosigtag
728 test_expect_success
'verifying a signed tag should succeed' \
729 'git tag -v signed-tag'
731 test_expect_success
'verifying two signed tags in one command should succeed' \
732 'git tag -v signed-tag file-signed-tag'
734 test_expect_success \
735 'verifying many signed and non-signed tags should fail' '
736 test_must_fail git tag -v signed-tag annotated-tag &&
737 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
738 test_must_fail git tag -v annotated-tag \
739 file-signed-tag file-annotated-tag &&
740 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
743 test_expect_success
'verifying a forged tag should fail' '
744 forged=$(git cat-file tag signed-tag |
745 sed -e "s/signed-tag/forged-tag/" |
747 git tag forged-tag $forged &&
748 test_must_fail git tag -v forged-tag
751 # blank and empty messages for signed tags:
753 get_tag_header empty-signed-tag
$commit commit
$time >expect
754 echo '-----BEGIN PGP SIGNATURE-----' >>expect
755 test_expect_success \
756 'creating a signed tag with an empty -m message should succeed' '
757 git tag -s -m "" empty-signed-tag &&
758 get_tag_msg empty-signed-tag >actual &&
759 test_cmp expect actual &&
760 git tag -v empty-signed-tag
764 get_tag_header emptyfile-signed-tag
$commit commit
$time >expect
765 echo '-----BEGIN PGP SIGNATURE-----' >>expect
766 test_expect_success \
767 'creating a signed tag with an empty -F messagefile should succeed' '
768 git tag -s -F sigemptyfile emptyfile-signed-tag &&
769 get_tag_msg emptyfile-signed-tag >actual &&
770 test_cmp expect actual &&
771 git tag -v emptyfile-signed-tag
774 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
775 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
776 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
777 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
778 get_tag_header blanks-signed-tag
$commit commit
$time >expect
788 echo '-----BEGIN PGP SIGNATURE-----' >>expect
789 test_expect_success \
790 'extra blanks in the message for a signed tag should be removed' '
791 git tag -s -F sigblanksfile blanks-signed-tag &&
792 get_tag_msg blanks-signed-tag >actual &&
793 test_cmp expect actual &&
794 git tag -v blanks-signed-tag
797 get_tag_header blank-signed-tag
$commit commit
$time >expect
798 echo '-----BEGIN PGP SIGNATURE-----' >>expect
799 test_expect_success \
800 'creating a signed tag with a blank -m message should succeed' '
801 git tag -s -m " " blank-signed-tag &&
802 get_tag_msg blank-signed-tag >actual &&
803 test_cmp expect actual &&
804 git tag -v blank-signed-tag
807 echo ' ' >sigblankfile
808 echo '' >>sigblankfile
809 echo ' ' >>sigblankfile
810 get_tag_header blankfile-signed-tag
$commit commit
$time >expect
811 echo '-----BEGIN PGP SIGNATURE-----' >>expect
812 test_expect_success \
813 'creating a signed tag with blank -F file with spaces should succeed' '
814 git tag -s -F sigblankfile blankfile-signed-tag &&
815 get_tag_msg blankfile-signed-tag >actual &&
816 test_cmp expect actual &&
817 git tag -v blankfile-signed-tag
820 printf ' ' >sigblanknonlfile
821 get_tag_header blanknonlfile-signed-tag
$commit commit
$time >expect
822 echo '-----BEGIN PGP SIGNATURE-----' >>expect
823 test_expect_success \
824 'creating a signed tag with spaces and no newline should succeed' '
825 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
826 get_tag_msg blanknonlfile-signed-tag >actual &&
827 test_cmp expect actual &&
828 git tag -v signed-tag
831 # messages with commented lines for signed tags:
833 cat >sigcommentsfile
<<EOF
850 get_tag_header comments-signed-tag
$commit commit
$time >expect
859 echo '-----BEGIN PGP SIGNATURE-----' >>expect
860 test_expect_success \
861 'creating a signed tag with a -F file with #comments should succeed' '
862 git tag -s -F sigcommentsfile comments-signed-tag &&
863 get_tag_msg comments-signed-tag >actual &&
864 test_cmp expect actual &&
865 git tag -v comments-signed-tag
868 get_tag_header comment-signed-tag
$commit commit
$time >expect
869 echo '-----BEGIN PGP SIGNATURE-----' >>expect
870 test_expect_success \
871 'creating a signed tag with #commented -m message should succeed' '
872 git tag -s -m "#comment" comment-signed-tag &&
873 get_tag_msg comment-signed-tag >actual &&
874 test_cmp expect actual &&
875 git tag -v comment-signed-tag
878 echo '#comment' >sigcommentfile
879 echo '' >>sigcommentfile
880 echo '####' >>sigcommentfile
881 get_tag_header commentfile-signed-tag
$commit commit
$time >expect
882 echo '-----BEGIN PGP SIGNATURE-----' >>expect
883 test_expect_success \
884 'creating a signed tag with #commented -F messagefile should succeed' '
885 git tag -s -F sigcommentfile commentfile-signed-tag &&
886 get_tag_msg commentfile-signed-tag >actual &&
887 test_cmp expect actual &&
888 git tag -v commentfile-signed-tag
891 printf '#comment' >sigcommentnonlfile
892 get_tag_header commentnonlfile-signed-tag
$commit commit
$time >expect
893 echo '-----BEGIN PGP SIGNATURE-----' >>expect
894 test_expect_success \
895 'creating a signed tag with a #comment and no newline should succeed' '
896 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
897 get_tag_msg commentnonlfile-signed-tag >actual &&
898 test_cmp expect actual &&
899 git tag -v commentnonlfile-signed-tag
902 # listing messages for signed tags:
904 test_expect_success \
905 'listing the one-line message of a signed tag should succeed' '
906 git tag -s -m "A message line signed" stag-one-line &&
908 echo "stag-one-line" >expect &&
909 git tag -l | grep "^stag-one-line" >actual &&
910 test_cmp expect actual &&
911 git tag -n0 -l | grep "^stag-one-line" >actual &&
912 test_cmp expect actual &&
913 git tag -n0 -l stag-one-line >actual &&
914 test_cmp expect actual &&
916 echo "stag-one-line A message line signed" >expect &&
917 git tag -n1 -l | grep "^stag-one-line" >actual &&
918 test_cmp expect actual &&
919 git tag -n -l | grep "^stag-one-line" >actual &&
920 test_cmp expect actual &&
921 git tag -n1 -l stag-one-line >actual &&
922 test_cmp expect actual &&
923 git tag -n2 -l stag-one-line >actual &&
924 test_cmp expect actual &&
925 git tag -n999 -l stag-one-line >actual &&
926 test_cmp expect actual
929 test_expect_success \
930 'listing the zero-lines message of a signed tag should succeed' '
931 git tag -s -m "" stag-zero-lines &&
933 echo "stag-zero-lines" >expect &&
934 git tag -l | grep "^stag-zero-lines" >actual &&
935 test_cmp expect actual &&
936 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
937 test_cmp expect actual &&
938 git tag -n0 -l stag-zero-lines >actual &&
939 test_cmp expect actual &&
941 echo "stag-zero-lines " >expect &&
942 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
943 test_cmp expect actual &&
944 git tag -n -l | grep "^stag-zero-lines" >actual &&
945 test_cmp expect actual &&
946 git tag -n1 -l stag-zero-lines >actual &&
947 test_cmp expect actual &&
948 git tag -n2 -l stag-zero-lines >actual &&
949 test_cmp expect actual &&
950 git tag -n999 -l stag-zero-lines >actual &&
951 test_cmp expect actual
954 echo 'stag line one' >sigtagmsg
955 echo 'stag line two' >>sigtagmsg
956 echo 'stag line three' >>sigtagmsg
957 test_expect_success \
958 'listing many message lines of a signed tag should succeed' '
959 git tag -s -F sigtagmsg stag-lines &&
961 echo "stag-lines" >expect &&
962 git tag -l | grep "^stag-lines" >actual &&
963 test_cmp expect actual &&
964 git tag -n0 -l | grep "^stag-lines" >actual &&
965 test_cmp expect actual &&
966 git tag -n0 -l stag-lines >actual &&
967 test_cmp expect actual &&
969 echo "stag-lines stag line one" >expect &&
970 git tag -n1 -l | grep "^stag-lines" >actual &&
971 test_cmp expect actual &&
972 git tag -n -l | grep "^stag-lines" >actual &&
973 test_cmp expect actual &&
974 git tag -n1 -l stag-lines >actual &&
975 test_cmp expect actual &&
977 echo " stag line two" >>expect &&
978 git tag -n2 -l | grep "^ *stag.line" >actual &&
979 test_cmp expect actual &&
980 git tag -n2 -l stag-lines >actual &&
981 test_cmp expect actual &&
983 echo " stag line three" >>expect &&
984 git tag -n3 -l | grep "^ *stag.line" >actual &&
985 test_cmp expect actual &&
986 git tag -n3 -l stag-lines >actual &&
987 test_cmp expect actual &&
988 git tag -n4 -l | grep "^ *stag.line" >actual &&
989 test_cmp expect actual &&
990 git tag -n4 -l stag-lines >actual &&
991 test_cmp expect actual &&
992 git tag -n99 -l | grep "^ *stag.line" >actual &&
993 test_cmp expect actual &&
994 git tag -n99 -l stag-lines >actual &&
995 test_cmp expect actual
998 # tags pointing to objects different from commits:
1000 tree
=$
(git rev-parse HEAD^
{tree
})
1001 blob
=$
(git rev-parse HEAD
:foo
)
1002 tag
=$
(git rev-parse signed-tag
)
1004 get_tag_header tree-signed-tag
$tree tree
$time >expect
1005 echo "A message for a tree" >>expect
1006 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1007 test_expect_success \
1008 'creating a signed tag pointing to a tree should succeed' '
1009 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1010 get_tag_msg tree-signed-tag >actual &&
1011 test_cmp expect actual
1014 get_tag_header blob-signed-tag
$blob blob
$time >expect
1015 echo "A message for a blob" >>expect
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success \
1018 'creating a signed tag pointing to a blob should succeed' '
1019 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1020 get_tag_msg blob-signed-tag >actual &&
1021 test_cmp expect actual
1024 get_tag_header tag-signed-tag
$tag tag
$time >expect
1025 echo "A message for another tag" >>expect
1026 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1027 test_expect_success \
1028 'creating a signed tag pointing to another tag should succeed' '
1029 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1030 get_tag_msg tag-signed-tag >actual &&
1031 test_cmp expect actual
1034 # try to sign with bad user.signingkey
1035 git config user.signingkey BobTheMouse
1036 test_expect_success \
1037 'git tag -s fails if gpg is misconfigured' \
1038 'test_must_fail git tag -s -m tail tag-gpg-failure'
1039 git config
--unset user.signingkey
1041 # try to verify without gpg:
1044 test_expect_success \
1045 'verify signed tag fails when public key is not present' \
1046 'test_must_fail git tag -v signed-tag'
1048 test_expect_success \
1049 'git tag -a fails if tag annotation is empty' '
1050 ! (GIT_EDITOR=cat git tag -a initial-comment)
1053 test_expect_success \
1054 'message in editor has initial comment' '
1055 GIT_EDITOR=cat git tag -a initial-comment > actual
1056 # check the first line --- should be empty
1057 first=$(sed -e 1q <actual) &&
1059 # remove commented lines from the remainder -- should be empty
1060 rest=$(sed -e 1d -e '/^
#/d' <actual) &&
1064 get_tag_header reuse $commit commit $time >expect
1065 echo "An annotation to be reused" >> expect
1066 test_expect_success \
1067 'overwriting an annoted tag should use its previous body
' '
1068 git tag
-a -m "An annotation to be reused" reuse
&&
1069 GIT_EDITOR
=true git tag
-f -a reuse
&&
1070 get_tag_msg reuse
>actual
&&
1071 test_cmp expect actual
1074 test_expect_success 'filename
for the message is relative to cwd
' '
1076 echo "Tag message in top directory" >msgfile-5
&&
1077 echo "Tag message in sub directory" >subdir
/msgfile-5
&&
1080 git tag
-a -F msgfile-5 tag-from-subdir
1082 git cat-file tag tag-from-subdir |
grep "in sub directory"
1085 test_expect_success 'filename
for the message is relative to cwd
' '
1086 echo "Tag message in sub directory" >subdir
/msgfile-6
&&
1089 git tag
-a -F msgfile-6 tag-from-subdir-2
1091 git cat-file tag tag-from-subdir-2 |
grep "in sub directory"
1094 # create a few more commits to test --contains
1096 hash1=$(git rev-parse HEAD)
1098 test_expect_success 'creating second commit and tag
' '
1099 echo foo-2.0
>foo
&&
1101 git commit
-m second
1105 hash2=$(git rev-parse HEAD)
1107 test_expect_success 'creating third commit without tag
' '
1108 echo foo-dev
>foo
&&
1113 hash3=$(git rev-parse HEAD)
1115 # simple linear checks of --continue
1117 cat > expected <<EOF
1125 test_expect_success 'checking that first commit is
in all tags
(hash)' "
1126 git tag -l --contains $hash1 v* >actual
1127 test_cmp expected actual
1130 # other ways of specifying the commit
1131 test_expect_success 'checking that first commit is
in all tags
(tag
)' "
1132 git tag -l --contains v1.0 v* >actual
1133 test_cmp expected actual
1136 test_expect_success 'checking that first commit is
in all tags
(relative
)' "
1137 git tag -l --contains HEAD~2 v* >actual
1138 test_cmp expected actual
1141 cat > expected <<EOF
1145 test_expect_success 'checking that second commit only has one tag
' "
1146 git tag -l --contains $hash2 v* >actual
1147 test_cmp expected actual
1151 cat > expected <<EOF
1154 test_expect_success 'checking that third commit has no tags
' "
1155 git tag -l --contains $hash3 v* >actual
1156 test_cmp expected actual
1159 # how about a simple merge?
1161 test_expect_success 'creating simple branch
' '
1162 git branch stable v2.0
&&
1163 git checkout stable
&&
1164 echo foo-3.0
> foo
&&
1165 git commit foo
-m fourth
1169 hash4=$(git rev-parse HEAD)
1171 cat > expected <<EOF
1175 test_expect_success 'checking that branch
head only has one tag
' "
1176 git tag -l --contains $hash4 v* >actual
1177 test_cmp expected actual
1180 test_expect_success 'merging original branch into this branch
' '
1181 git merge
--strategy=ours master
&&
1185 cat > expected <<EOF
1189 test_expect_success 'checking that original branch
head has one tag now
' "
1190 git tag -l --contains $hash3 v* >actual
1191 test_cmp expected actual
1194 cat > expected <<EOF
1204 test_expect_success 'checking that initial commit is
in all tags
' "
1205 git tag -l --contains $hash1 v* >actual
1206 test_cmp expected actual
1209 # mixing modes and options:
1211 test_expect_success 'mixing incompatibles modes and options is forbidden
' '
1212 test_must_fail git tag
-a
1213 test_must_fail git tag
-l -v
1214 test_must_fail git tag
-n 100
1215 test_must_fail git tag
-l -m msg
1216 test_must_fail git tag
-l -F some
file
1217 test_must_fail git tag
-v -s