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' '
37 test_expect_success
'creating a tag for HEAD in an empty tree should fail' '
38 ! git-tag mytaghead HEAD &&
39 ! tag_exists mytaghead
42 test_expect_success
'creating a tag for an unknown revision should fail' '
43 ! 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' \
91 'trying to create a tag with a non-valid name should fail' '
92 test `git-tag -l | wc -l` -eq 1 &&
94 ! git tag .othertag &&
95 ! git tag "other tag" &&
96 ! git tag "othertag^" &&
97 ! 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 ! 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 && git diff expect actual &&
121 git tag -l > actual && git diff 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 ! git-tag -d mytag anothertag &&
145 ! tag_exists mytag &&
149 test_expect_success
'trying to delete an already deleted tag should fail' \
152 # listing various tags with pattern matching:
165 test_expect_success
'listing all tags should print them ordered' '
175 git tag -l > actual &&
176 git diff expect actual &&
178 git diff expect actual
186 test_expect_success \
187 'listing tags with substring as pattern must print those matching' '
188 git-tag -l "*a*" > actual &&
189 git diff expect actual
196 test_expect_success \
197 'listing tags with a suffix as pattern must print those matching' '
198 git-tag -l "*.1" > actual &&
199 git diff expect actual
206 test_expect_success \
207 'listing tags with a prefix as pattern must print those matching' '
208 git-tag -l "t21*" > actual &&
209 git diff expect actual
215 test_expect_success \
216 'listing tags using a name as pattern must print that one matching' '
217 git-tag -l a1 > actual &&
218 git diff expect actual
224 test_expect_success \
225 'listing tags using a name as pattern must print that one matching' '
226 git-tag -l v1.0 > actual &&
227 git diff expect actual
234 test_expect_success \
235 'listing tags with ? in the pattern should print those matching' '
236 git-tag -l "v1.?.?" > actual &&
237 git diff expect actual
241 test_expect_success \
242 'listing tags using v.* should print nothing because none have v.' '
243 git-tag -l "v.*" > actual &&
244 git diff expect actual
253 test_expect_success \
254 'listing tags using v* should print only those having v' '
255 git-tag -l "v*" > actual &&
256 git diff expect actual
259 # creating and verifying lightweight tags:
261 test_expect_success \
262 'a non-annotated tag created without parameters should point to HEAD' '
263 git-tag non-annotated-tag &&
264 test $(git cat-file -t non-annotated-tag) = commit &&
265 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
268 test_expect_success
'trying to verify an unknown tag should fail' \
269 '! git-tag -v unknown-tag'
271 test_expect_success \
272 'trying to verify a non-annotated and non-signed tag should fail' \
273 '! git-tag -v non-annotated-tag'
275 test_expect_success \
276 'trying to verify many non-annotated or unknown tags, should fail' \
277 '! git-tag -v unknown-tag1 non-annotated-tag unknown-tag2'
279 # creating annotated tags:
282 git cat-file tag
"$1" |
sed -e "/BEGIN PGP/q"
285 # run test_tick before committing always gives the time in that timezone
291 tagger C O Mitter <committer@example.com> $4 -0700
296 commit
=$
(git rev-parse HEAD
)
299 get_tag_header annotated-tag
$commit commit
$time >expect
300 echo "A message" >>expect
301 test_expect_success \
302 'creating an annotated tag with -m message should succeed' '
303 git-tag -m "A message" annotated-tag &&
304 get_tag_msg annotated-tag >actual &&
305 git diff expect actual
312 get_tag_header file-annotated-tag
$commit commit
$time >expect
314 test_expect_success \
315 'creating an annotated tag with -F messagefile should succeed' '
316 git-tag -F msgfile file-annotated-tag &&
317 get_tag_msg file-annotated-tag >actual &&
318 git diff expect actual
325 get_tag_header stdin-annotated-tag
$commit commit
$time >expect
326 cat inputmsg
>>expect
327 test_expect_success
'creating an annotated tag with -F - should succeed' '
328 git-tag -F - stdin-annotated-tag <inputmsg &&
329 get_tag_msg stdin-annotated-tag >actual &&
330 git diff expect actual
333 test_expect_success \
334 'trying to create a tag with a non-existing -F file should fail' '
335 ! test -f nonexistingfile &&
336 ! tag_exists notag &&
337 ! git-tag -F nonexistingfile notag &&
341 test_expect_success \
342 'trying to create tags giving both -m or -F options should fail' '
343 echo "message file 1" >msgfile1 &&
344 echo "message file 2" >msgfile2 &&
345 ! tag_exists msgtag &&
346 ! git-tag -m "message 1" -F msgfile1 msgtag &&
347 ! tag_exists msgtag &&
348 ! git-tag -F msgfile1 -m "message 1" msgtag &&
349 ! tag_exists msgtag &&
350 ! git-tag -m "message 1" -F msgfile1 -m "message 2" msgtag &&
354 # blank and empty messages:
356 get_tag_header empty-annotated-tag
$commit commit
$time >expect
357 test_expect_success \
358 'creating a tag with an empty -m message should succeed' '
359 git-tag -m "" empty-annotated-tag &&
360 get_tag_msg empty-annotated-tag >actual &&
361 git diff expect actual
365 get_tag_header emptyfile-annotated-tag
$commit commit
$time >expect
366 test_expect_success \
367 'creating a tag with an empty -F messagefile should succeed' '
368 git-tag -F emptyfile emptyfile-annotated-tag &&
369 get_tag_msg emptyfile-annotated-tag >actual &&
370 git diff expect actual
373 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
374 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
375 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
376 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
377 get_tag_header blanks-annotated-tag
$commit commit
$time >expect
387 test_expect_success \
388 'extra blanks in the message for an annotated tag should be removed' '
389 git-tag -F blanksfile blanks-annotated-tag &&
390 get_tag_msg blanks-annotated-tag >actual &&
391 git diff expect actual
394 get_tag_header blank-annotated-tag
$commit commit
$time >expect
395 test_expect_success \
396 'creating a tag with blank -m message with spaces should succeed' '
397 git-tag -m " " blank-annotated-tag &&
398 get_tag_msg blank-annotated-tag >actual &&
399 git diff expect actual
405 get_tag_header blankfile-annotated-tag
$commit commit
$time >expect
406 test_expect_success \
407 'creating a tag with blank -F messagefile with spaces should succeed' '
408 git-tag -F blankfile blankfile-annotated-tag &&
409 get_tag_msg blankfile-annotated-tag >actual &&
410 git diff expect actual
413 printf ' ' >blanknonlfile
414 get_tag_header blanknonlfile-annotated-tag
$commit commit
$time >expect
415 test_expect_success \
416 'creating a tag with -F file of spaces and no newline should succeed' '
417 git-tag -F blanknonlfile blanknonlfile-annotated-tag &&
418 get_tag_msg blanknonlfile-annotated-tag >actual &&
419 git diff expect actual
422 # messages with commented lines:
424 cat >commentsfile
<<EOF
441 get_tag_header comments-annotated-tag
$commit commit
$time >expect
450 test_expect_success \
451 'creating a tag using a -F messagefile with #comments should succeed' '
452 git-tag -F commentsfile comments-annotated-tag &&
453 get_tag_msg comments-annotated-tag >actual &&
454 git diff expect actual
457 get_tag_header comment-annotated-tag
$commit commit
$time >expect
458 test_expect_success \
459 'creating a tag with a #comment in the -m message should succeed' '
460 git-tag -m "#comment" comment-annotated-tag &&
461 get_tag_msg comment-annotated-tag >actual &&
462 git diff expect actual
465 echo '#comment' >commentfile
466 echo '' >>commentfile
467 echo '####' >>commentfile
468 get_tag_header commentfile-annotated-tag
$commit commit
$time >expect
469 test_expect_success \
470 'creating a tag with #comments in the -F messagefile should succeed' '
471 git-tag -F commentfile commentfile-annotated-tag &&
472 get_tag_msg commentfile-annotated-tag >actual &&
473 git diff expect actual
476 printf '#comment' >commentnonlfile
477 get_tag_header commentnonlfile-annotated-tag
$commit commit
$time >expect
478 test_expect_success \
479 'creating a tag with a file of #comment and no newline should succeed' '
480 git-tag -F commentnonlfile commentnonlfile-annotated-tag &&
481 get_tag_msg commentnonlfile-annotated-tag >actual &&
482 git diff expect actual
485 # listing messages for annotated non-signed tags:
487 test_expect_success \
488 'listing the one-line message of a non-signed tag should succeed' '
489 git-tag -m "A msg" tag-one-line &&
491 echo "tag-one-line" >expect &&
492 git-tag -l | grep "^tag-one-line" >actual &&
493 git diff expect actual &&
494 git-tag -n0 -l | grep "^tag-one-line" >actual &&
495 git diff expect actual &&
496 git-tag -n0 -l tag-one-line >actual &&
497 git diff expect actual &&
499 echo "tag-one-line A msg" >expect &&
500 git-tag -n1 -l | grep "^tag-one-line" >actual &&
501 git diff expect actual &&
502 git-tag -n -l | grep "^tag-one-line" >actual &&
503 git diff expect actual &&
504 git-tag -n1 -l tag-one-line >actual &&
505 git diff expect actual &&
506 git-tag -n2 -l tag-one-line >actual &&
507 git diff expect actual &&
508 git-tag -n999 -l tag-one-line >actual &&
509 git diff expect actual
512 test_expect_success \
513 'listing the zero-lines message of a non-signed tag should succeed' '
514 git-tag -m "" tag-zero-lines &&
516 echo "tag-zero-lines" >expect &&
517 git-tag -l | grep "^tag-zero-lines" >actual &&
518 git diff expect actual &&
519 git-tag -n0 -l | grep "^tag-zero-lines" >actual &&
520 git diff expect actual &&
521 git-tag -n0 -l tag-zero-lines >actual &&
522 git diff expect actual &&
524 echo "tag-zero-lines " >expect &&
525 git-tag -n1 -l | grep "^tag-zero-lines" >actual &&
526 git diff expect actual &&
527 git-tag -n -l | grep "^tag-zero-lines" >actual &&
528 git diff expect actual &&
529 git-tag -n1 -l tag-zero-lines >actual &&
530 git diff expect actual &&
531 git-tag -n2 -l tag-zero-lines >actual &&
532 git diff expect actual &&
533 git-tag -n999 -l tag-zero-lines >actual &&
534 git diff expect actual
537 echo 'tag line one' >annotagmsg
538 echo 'tag line two' >>annotagmsg
539 echo 'tag line three' >>annotagmsg
540 test_expect_success \
541 'listing many message lines of a non-signed tag should succeed' '
542 git-tag -F annotagmsg tag-lines &&
544 echo "tag-lines" >expect &&
545 git-tag -l | grep "^tag-lines" >actual &&
546 git diff expect actual &&
547 git-tag -n0 -l | grep "^tag-lines" >actual &&
548 git diff expect actual &&
549 git-tag -n0 -l tag-lines >actual &&
550 git diff expect actual &&
552 echo "tag-lines tag line one" >expect &&
553 git-tag -n1 -l | grep "^tag-lines" >actual &&
554 git diff expect actual &&
555 git-tag -n -l | grep "^tag-lines" >actual &&
556 git diff expect actual &&
557 git-tag -n1 -l tag-lines >actual &&
558 git diff expect actual &&
560 echo " tag line two" >>expect &&
561 git-tag -n2 -l | grep "^ *tag.line" >actual &&
562 git diff expect actual &&
563 git-tag -n2 -l tag-lines >actual &&
564 git diff expect actual &&
566 echo " tag line three" >>expect &&
567 git-tag -n3 -l | grep "^ *tag.line" >actual &&
568 git diff expect actual &&
569 git-tag -n3 -l tag-lines >actual &&
570 git diff expect actual &&
571 git-tag -n4 -l | grep "^ *tag.line" >actual &&
572 git diff expect actual &&
573 git-tag -n4 -l tag-lines >actual &&
574 git diff expect actual &&
575 git-tag -n99 -l | grep "^ *tag.line" >actual &&
576 git diff expect actual &&
577 git-tag -n99 -l tag-lines >actual &&
578 git diff expect actual
581 # subsequent tests require gpg; check if it is available
582 gpg
--version >/dev
/null
583 if [ $?
-eq 127 ]; then
584 echo "gpg not found - skipping tag signing and verification tests"
589 # trying to verify annotated non-signed tags:
591 test_expect_success \
592 'trying to verify an annotated non-signed tag should fail' '
593 tag_exists annotated-tag &&
594 ! git-tag -v annotated-tag
597 test_expect_success \
598 'trying to verify a file-annotated non-signed tag should fail' '
599 tag_exists file-annotated-tag &&
600 ! git-tag -v file-annotated-tag
603 test_expect_success \
604 'trying to verify two annotated non-signed tags should fail' '
605 tag_exists annotated-tag file-annotated-tag &&
606 ! git-tag -v annotated-tag file-annotated-tag
609 # creating and verifying signed tags:
611 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
612 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
613 # that version, creation of signed tags using the generated key fails.
614 case "$(gpg --version)" in
615 'gpg (GnuPG) 1.0.6'*)
616 echo "Skipping signed tag tests, because a bug in 1.0.6 version"
622 # key generation info: gpg --homedir t/t7004 --gen-key
623 # Type DSA and Elgamal, size 2048 bits, no expiration date.
624 # Name and email: C O Mitter <committer@example.com>
625 # No password given, to enable non-interactive operation.
627 cp -R ..
/t7004 .
/gpghome
629 export GNUPGHOME
="$(pwd)/gpghome"
631 get_tag_header signed-tag
$commit commit
$time >expect
632 echo 'A signed tag message' >>expect
633 echo '-----BEGIN PGP SIGNATURE-----' >>expect
634 test_expect_success
'creating a signed tag with -m message should succeed' '
635 git-tag -s -m "A signed tag message" signed-tag &&
636 get_tag_msg signed-tag >actual &&
637 git diff expect actual
640 get_tag_header u-signed-tag
$commit commit
$time >expect
641 echo 'Another message' >>expect
642 echo '-----BEGIN PGP SIGNATURE-----' >>expect
643 test_expect_success
'sign with a given key id' '
645 git tag -u committer@example.com -m "Another message" u-signed-tag &&
646 get_tag_msg u-signed-tag >actual &&
647 git diff expect actual
651 test_expect_success
'sign with an unknown id (1)' '
653 ! git tag -u author@example.com -m "Another message" o-signed-tag
657 test_expect_success
'sign with an unknown id (2)' '
659 ! git tag -u DEADBEEF -m "Another message" o-signed-tag
663 cat >fakeeditor
<<'EOF'
665 test -n "$1" && exec >"$1"
666 echo A signed tag message
667 echo from a fake editor.
671 get_tag_header implied-sign
$commit commit
$time >expect
672 .
/fakeeditor
>>expect
673 echo '-----BEGIN PGP SIGNATURE-----' >>expect
674 test_expect_success
'-u implies signed tag' '
675 GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
676 get_tag_msg implied-sign >actual &&
677 git diff expect actual
680 cat >sigmsgfile
<<EOF
684 get_tag_header file-signed-tag
$commit commit
$time >expect
685 cat sigmsgfile
>>expect
686 echo '-----BEGIN PGP SIGNATURE-----' >>expect
687 test_expect_success \
688 'creating a signed tag with -F messagefile should succeed' '
689 git-tag -s -F sigmsgfile file-signed-tag &&
690 get_tag_msg file-signed-tag >actual &&
691 git diff expect actual
694 cat >siginputmsg
<<EOF
695 A signed tag message from
698 get_tag_header stdin-signed-tag
$commit commit
$time >expect
699 cat siginputmsg
>>expect
700 echo '-----BEGIN PGP SIGNATURE-----' >>expect
701 test_expect_success
'creating a signed tag with -F - should succeed' '
702 git-tag -s -F - stdin-signed-tag <siginputmsg &&
703 get_tag_msg stdin-signed-tag >actual &&
704 git diff expect actual
707 get_tag_header implied-annotate
$commit commit
$time >expect
708 .
/fakeeditor
>>expect
709 echo '-----BEGIN PGP SIGNATURE-----' >>expect
710 test_expect_success
'-s implies annotated tag' '
711 GIT_EDITOR=./fakeeditor git-tag -s implied-annotate &&
712 get_tag_msg implied-annotate >actual &&
713 git diff expect actual
716 test_expect_success \
717 'trying to create a signed tag with non-existing -F file should fail' '
718 ! test -f nonexistingfile &&
719 ! tag_exists nosigtag &&
720 ! git-tag -s -F nonexistingfile nosigtag &&
721 ! tag_exists nosigtag
724 test_expect_success
'verifying a signed tag should succeed' \
725 'git-tag -v signed-tag'
727 test_expect_success
'verifying two signed tags in one command should succeed' \
728 'git-tag -v signed-tag file-signed-tag'
730 test_expect_success \
731 'verifying many signed and non-signed tags should fail' '
732 ! git-tag -v signed-tag annotated-tag &&
733 ! git-tag -v file-annotated-tag file-signed-tag &&
734 ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
735 ! git-tag -v signed-tag annotated-tag file-signed-tag
738 test_expect_success
'verifying a forged tag should fail' '
739 forged=$(git cat-file tag signed-tag |
740 sed -e "s/signed-tag/forged-tag/" |
742 git tag forged-tag $forged &&
743 ! git-tag -v forged-tag
746 # blank and empty messages for signed tags:
748 get_tag_header empty-signed-tag
$commit commit
$time >expect
749 echo '-----BEGIN PGP SIGNATURE-----' >>expect
750 test_expect_success \
751 'creating a signed tag with an empty -m message should succeed' '
752 git-tag -s -m "" empty-signed-tag &&
753 get_tag_msg empty-signed-tag >actual &&
754 git diff expect actual &&
755 git-tag -v empty-signed-tag
759 get_tag_header emptyfile-signed-tag
$commit commit
$time >expect
760 echo '-----BEGIN PGP SIGNATURE-----' >>expect
761 test_expect_success \
762 'creating a signed tag with an empty -F messagefile should succeed' '
763 git-tag -s -F sigemptyfile emptyfile-signed-tag &&
764 get_tag_msg emptyfile-signed-tag >actual &&
765 git diff expect actual &&
766 git-tag -v emptyfile-signed-tag
769 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
770 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
771 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
772 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
773 get_tag_header blanks-signed-tag
$commit commit
$time >expect
783 echo '-----BEGIN PGP SIGNATURE-----' >>expect
784 test_expect_success \
785 'extra blanks in the message for a signed tag should be removed' '
786 git-tag -s -F sigblanksfile blanks-signed-tag &&
787 get_tag_msg blanks-signed-tag >actual &&
788 git diff expect actual &&
789 git-tag -v blanks-signed-tag
792 get_tag_header blank-signed-tag
$commit commit
$time >expect
793 echo '-----BEGIN PGP SIGNATURE-----' >>expect
794 test_expect_success \
795 'creating a signed tag with a blank -m message should succeed' '
796 git-tag -s -m " " blank-signed-tag &&
797 get_tag_msg blank-signed-tag >actual &&
798 git diff expect actual &&
799 git-tag -v blank-signed-tag
802 echo ' ' >sigblankfile
803 echo '' >>sigblankfile
804 echo ' ' >>sigblankfile
805 get_tag_header blankfile-signed-tag
$commit commit
$time >expect
806 echo '-----BEGIN PGP SIGNATURE-----' >>expect
807 test_expect_success \
808 'creating a signed tag with blank -F file with spaces should succeed' '
809 git-tag -s -F sigblankfile blankfile-signed-tag &&
810 get_tag_msg blankfile-signed-tag >actual &&
811 git diff expect actual &&
812 git-tag -v blankfile-signed-tag
815 printf ' ' >sigblanknonlfile
816 get_tag_header blanknonlfile-signed-tag
$commit commit
$time >expect
817 echo '-----BEGIN PGP SIGNATURE-----' >>expect
818 test_expect_success \
819 'creating a signed tag with spaces and no newline should succeed' '
820 git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
821 get_tag_msg blanknonlfile-signed-tag >actual &&
822 git diff expect actual &&
823 git-tag -v signed-tag
826 # messages with commented lines for signed tags:
828 cat >sigcommentsfile
<<EOF
845 get_tag_header comments-signed-tag
$commit commit
$time >expect
854 echo '-----BEGIN PGP SIGNATURE-----' >>expect
855 test_expect_success \
856 'creating a signed tag with a -F file with #comments should succeed' '
857 git-tag -s -F sigcommentsfile comments-signed-tag &&
858 get_tag_msg comments-signed-tag >actual &&
859 git diff expect actual &&
860 git-tag -v comments-signed-tag
863 get_tag_header comment-signed-tag
$commit commit
$time >expect
864 echo '-----BEGIN PGP SIGNATURE-----' >>expect
865 test_expect_success \
866 'creating a signed tag with #commented -m message should succeed' '
867 git-tag -s -m "#comment" comment-signed-tag &&
868 get_tag_msg comment-signed-tag >actual &&
869 git diff expect actual &&
870 git-tag -v comment-signed-tag
873 echo '#comment' >sigcommentfile
874 echo '' >>sigcommentfile
875 echo '####' >>sigcommentfile
876 get_tag_header commentfile-signed-tag
$commit commit
$time >expect
877 echo '-----BEGIN PGP SIGNATURE-----' >>expect
878 test_expect_success \
879 'creating a signed tag with #commented -F messagefile should succeed' '
880 git-tag -s -F sigcommentfile commentfile-signed-tag &&
881 get_tag_msg commentfile-signed-tag >actual &&
882 git diff expect actual &&
883 git-tag -v commentfile-signed-tag
886 printf '#comment' >sigcommentnonlfile
887 get_tag_header commentnonlfile-signed-tag
$commit commit
$time >expect
888 echo '-----BEGIN PGP SIGNATURE-----' >>expect
889 test_expect_success \
890 'creating a signed tag with a #comment and no newline should succeed' '
891 git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
892 get_tag_msg commentnonlfile-signed-tag >actual &&
893 git diff expect actual &&
894 git-tag -v commentnonlfile-signed-tag
897 # listing messages for signed tags:
899 test_expect_success \
900 'listing the one-line message of a signed tag should succeed' '
901 git-tag -s -m "A message line signed" stag-one-line &&
903 echo "stag-one-line" >expect &&
904 git-tag -l | grep "^stag-one-line" >actual &&
905 git diff expect actual &&
906 git-tag -n0 -l | grep "^stag-one-line" >actual &&
907 git diff expect actual &&
908 git-tag -n0 -l stag-one-line >actual &&
909 git diff expect actual &&
911 echo "stag-one-line A message line signed" >expect &&
912 git-tag -n1 -l | grep "^stag-one-line" >actual &&
913 git diff expect actual &&
914 git-tag -n -l | grep "^stag-one-line" >actual &&
915 git diff expect actual &&
916 git-tag -n1 -l stag-one-line >actual &&
917 git diff expect actual &&
918 git-tag -n2 -l stag-one-line >actual &&
919 git diff expect actual &&
920 git-tag -n999 -l stag-one-line >actual &&
921 git diff expect actual
924 test_expect_success \
925 'listing the zero-lines message of a signed tag should succeed' '
926 git-tag -s -m "" stag-zero-lines &&
928 echo "stag-zero-lines" >expect &&
929 git-tag -l | grep "^stag-zero-lines" >actual &&
930 git diff expect actual &&
931 git-tag -n0 -l | grep "^stag-zero-lines" >actual &&
932 git diff expect actual &&
933 git-tag -n0 -l stag-zero-lines >actual &&
934 git diff expect actual &&
936 echo "stag-zero-lines " >expect &&
937 git-tag -n1 -l | grep "^stag-zero-lines" >actual &&
938 git diff expect actual &&
939 git-tag -n -l | grep "^stag-zero-lines" >actual &&
940 git diff expect actual &&
941 git-tag -n1 -l stag-zero-lines >actual &&
942 git diff expect actual &&
943 git-tag -n2 -l stag-zero-lines >actual &&
944 git diff expect actual &&
945 git-tag -n999 -l stag-zero-lines >actual &&
946 git diff expect actual
949 echo 'stag line one' >sigtagmsg
950 echo 'stag line two' >>sigtagmsg
951 echo 'stag line three' >>sigtagmsg
952 test_expect_success \
953 'listing many message lines of a signed tag should succeed' '
954 git-tag -s -F sigtagmsg stag-lines &&
956 echo "stag-lines" >expect &&
957 git-tag -l | grep "^stag-lines" >actual &&
958 git diff expect actual &&
959 git-tag -n0 -l | grep "^stag-lines" >actual &&
960 git diff expect actual &&
961 git-tag -n0 -l stag-lines >actual &&
962 git diff expect actual &&
964 echo "stag-lines stag line one" >expect &&
965 git-tag -n1 -l | grep "^stag-lines" >actual &&
966 git diff expect actual &&
967 git-tag -n -l | grep "^stag-lines" >actual &&
968 git diff expect actual &&
969 git-tag -n1 -l stag-lines >actual &&
970 git diff expect actual &&
972 echo " stag line two" >>expect &&
973 git-tag -n2 -l | grep "^ *stag.line" >actual &&
974 git diff expect actual &&
975 git-tag -n2 -l stag-lines >actual &&
976 git diff expect actual &&
978 echo " stag line three" >>expect &&
979 git-tag -n3 -l | grep "^ *stag.line" >actual &&
980 git diff expect actual &&
981 git-tag -n3 -l stag-lines >actual &&
982 git diff expect actual &&
983 git-tag -n4 -l | grep "^ *stag.line" >actual &&
984 git diff expect actual &&
985 git-tag -n4 -l stag-lines >actual &&
986 git diff expect actual &&
987 git-tag -n99 -l | grep "^ *stag.line" >actual &&
988 git diff expect actual &&
989 git-tag -n99 -l stag-lines >actual &&
990 git diff expect actual
993 # tags pointing to objects different from commits:
995 tree
=$
(git rev-parse HEAD^
{tree
})
996 blob
=$
(git rev-parse HEAD
:foo
)
997 tag
=$
(git rev-parse signed-tag
)
999 get_tag_header tree-signed-tag
$tree tree
$time >expect
1000 echo "A message for a tree" >>expect
1001 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1002 test_expect_success \
1003 'creating a signed tag pointing to a tree should succeed' '
1004 git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1005 get_tag_msg tree-signed-tag >actual &&
1006 git diff expect actual
1009 get_tag_header blob-signed-tag
$blob blob
$time >expect
1010 echo "A message for a blob" >>expect
1011 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1012 test_expect_success \
1013 'creating a signed tag pointing to a blob should succeed' '
1014 git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1015 get_tag_msg blob-signed-tag >actual &&
1016 git diff expect actual
1019 get_tag_header tag-signed-tag
$tag tag
$time >expect
1020 echo "A message for another tag" >>expect
1021 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1022 test_expect_success \
1023 'creating a signed tag pointing to another tag should succeed' '
1024 git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1025 get_tag_msg tag-signed-tag >actual &&
1026 git diff expect actual
1029 # try to sign with bad user.signingkey
1030 git config user.signingkey BobTheMouse
1031 test_expect_success \
1032 'git-tag -s fails if gpg is misconfigured' \
1033 '! git tag -s -m tail tag-gpg-failure'
1034 git config
--unset user.signingkey
1036 # try to verify without gpg:
1039 test_expect_success \
1040 'verify signed tag fails when public key is not present' \
1041 '! git-tag -v signed-tag'
1043 test_expect_success \
1044 'git-tag -a fails if tag annotation is empty' '
1045 ! (GIT_EDITOR=cat git tag -a initial-comment)
1048 test_expect_success \
1049 'message in editor has initial comment' '
1050 GIT_EDITOR=cat git tag -a initial-comment > actual
1051 # check the first line --- should be empty
1052 first=$(sed -e 1q <actual) &&
1054 # remove commented lines from the remainder -- should be empty
1055 rest=$(sed -e 1d -e '/^
#/d' <actual) &&
1059 get_tag_header reuse $commit commit $time >expect
1060 echo "An annotation to be reused" >> expect
1061 test_expect_success \
1062 'overwriting an annoted tag should use its previous body
' '
1063 git tag
-a -m "An annotation to be reused" reuse
&&
1064 GIT_EDITOR
=true git tag
-f -a reuse
&&
1065 get_tag_msg reuse
>actual
&&
1066 git
diff expect actual