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 && 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 ! 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 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 '! git-tag -v unknown-tag'
272 test_expect_success \
273 'trying to verify a non-annotated and non-signed tag should fail' \
274 '! git-tag -v non-annotated-tag'
276 test_expect_success \
277 'trying to verify many non-annotated or unknown tags, should fail' \
278 '! 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 ! 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 ! git-tag -m "message 1" -F msgfile1 msgtag &&
348 ! tag_exists msgtag &&
349 ! git-tag -F msgfile1 -m "message 1" msgtag &&
350 ! tag_exists msgtag &&
351 ! git-tag -m "message 1" -F msgfile1 -m "message 2" msgtag &&
355 # blank and empty messages:
357 get_tag_header empty-annotated-tag
$commit commit
$time >expect
358 test_expect_success \
359 'creating a tag with an empty -m message should succeed' '
360 git-tag -m "" empty-annotated-tag &&
361 get_tag_msg empty-annotated-tag >actual &&
362 test_cmp expect actual
366 get_tag_header emptyfile-annotated-tag
$commit commit
$time >expect
367 test_expect_success \
368 'creating a tag with an empty -F messagefile should succeed' '
369 git-tag -F emptyfile emptyfile-annotated-tag &&
370 get_tag_msg emptyfile-annotated-tag >actual &&
371 test_cmp expect actual
374 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
375 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
376 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
377 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
378 get_tag_header blanks-annotated-tag
$commit commit
$time >expect
388 test_expect_success \
389 'extra blanks in the message for an annotated tag should be removed' '
390 git-tag -F blanksfile blanks-annotated-tag &&
391 get_tag_msg blanks-annotated-tag >actual &&
392 test_cmp expect actual
395 get_tag_header blank-annotated-tag
$commit commit
$time >expect
396 test_expect_success \
397 'creating a tag with blank -m message with spaces should succeed' '
398 git-tag -m " " blank-annotated-tag &&
399 get_tag_msg blank-annotated-tag >actual &&
400 test_cmp expect actual
406 get_tag_header blankfile-annotated-tag
$commit commit
$time >expect
407 test_expect_success \
408 'creating a tag with blank -F messagefile with spaces should succeed' '
409 git-tag -F blankfile blankfile-annotated-tag &&
410 get_tag_msg blankfile-annotated-tag >actual &&
411 test_cmp expect actual
414 printf ' ' >blanknonlfile
415 get_tag_header blanknonlfile-annotated-tag
$commit commit
$time >expect
416 test_expect_success \
417 'creating a tag with -F file of spaces and no newline should succeed' '
418 git-tag -F blanknonlfile blanknonlfile-annotated-tag &&
419 get_tag_msg blanknonlfile-annotated-tag >actual &&
420 test_cmp expect actual
423 # messages with commented lines:
425 cat >commentsfile
<<EOF
442 get_tag_header comments-annotated-tag
$commit commit
$time >expect
451 test_expect_success \
452 'creating a tag using a -F messagefile with #comments should succeed' '
453 git-tag -F commentsfile comments-annotated-tag &&
454 get_tag_msg comments-annotated-tag >actual &&
455 test_cmp expect actual
458 get_tag_header comment-annotated-tag
$commit commit
$time >expect
459 test_expect_success \
460 'creating a tag with a #comment in the -m message should succeed' '
461 git-tag -m "#comment" comment-annotated-tag &&
462 get_tag_msg comment-annotated-tag >actual &&
463 test_cmp expect actual
466 echo '#comment' >commentfile
467 echo '' >>commentfile
468 echo '####' >>commentfile
469 get_tag_header commentfile-annotated-tag
$commit commit
$time >expect
470 test_expect_success \
471 'creating a tag with #comments in the -F messagefile should succeed' '
472 git-tag -F commentfile commentfile-annotated-tag &&
473 get_tag_msg commentfile-annotated-tag >actual &&
474 test_cmp expect actual
477 printf '#comment' >commentnonlfile
478 get_tag_header commentnonlfile-annotated-tag
$commit commit
$time >expect
479 test_expect_success \
480 'creating a tag with a file of #comment and no newline should succeed' '
481 git-tag -F commentnonlfile commentnonlfile-annotated-tag &&
482 get_tag_msg commentnonlfile-annotated-tag >actual &&
483 test_cmp expect actual
486 # listing messages for annotated non-signed tags:
488 test_expect_success \
489 'listing the one-line message of a non-signed tag should succeed' '
490 git-tag -m "A msg" tag-one-line &&
492 echo "tag-one-line" >expect &&
493 git-tag -l | grep "^tag-one-line" >actual &&
494 test_cmp expect actual &&
495 git-tag -n0 -l | grep "^tag-one-line" >actual &&
496 test_cmp expect actual &&
497 git-tag -n0 -l tag-one-line >actual &&
498 test_cmp expect actual &&
500 echo "tag-one-line A msg" >expect &&
501 git-tag -n1 -l | grep "^tag-one-line" >actual &&
502 test_cmp expect actual &&
503 git-tag -n -l | grep "^tag-one-line" >actual &&
504 test_cmp expect actual &&
505 git-tag -n1 -l tag-one-line >actual &&
506 test_cmp expect actual &&
507 git-tag -n2 -l tag-one-line >actual &&
508 test_cmp expect actual &&
509 git-tag -n999 -l tag-one-line >actual &&
510 test_cmp expect actual
513 test_expect_success \
514 'listing the zero-lines message of a non-signed tag should succeed' '
515 git-tag -m "" tag-zero-lines &&
517 echo "tag-zero-lines" >expect &&
518 git-tag -l | grep "^tag-zero-lines" >actual &&
519 test_cmp expect actual &&
520 git-tag -n0 -l | grep "^tag-zero-lines" >actual &&
521 test_cmp expect actual &&
522 git-tag -n0 -l tag-zero-lines >actual &&
523 test_cmp expect actual &&
525 echo "tag-zero-lines " >expect &&
526 git-tag -n1 -l | grep "^tag-zero-lines" >actual &&
527 test_cmp expect actual &&
528 git-tag -n -l | grep "^tag-zero-lines" >actual &&
529 test_cmp expect actual &&
530 git-tag -n1 -l tag-zero-lines >actual &&
531 test_cmp expect actual &&
532 git-tag -n2 -l tag-zero-lines >actual &&
533 test_cmp expect actual &&
534 git-tag -n999 -l tag-zero-lines >actual &&
535 test_cmp expect actual
538 echo 'tag line one' >annotagmsg
539 echo 'tag line two' >>annotagmsg
540 echo 'tag line three' >>annotagmsg
541 test_expect_success \
542 'listing many message lines of a non-signed tag should succeed' '
543 git-tag -F annotagmsg tag-lines &&
545 echo "tag-lines" >expect &&
546 git-tag -l | grep "^tag-lines" >actual &&
547 test_cmp expect actual &&
548 git-tag -n0 -l | grep "^tag-lines" >actual &&
549 test_cmp expect actual &&
550 git-tag -n0 -l tag-lines >actual &&
551 test_cmp expect actual &&
553 echo "tag-lines tag line one" >expect &&
554 git-tag -n1 -l | grep "^tag-lines" >actual &&
555 test_cmp expect actual &&
556 git-tag -n -l | grep "^tag-lines" >actual &&
557 test_cmp expect actual &&
558 git-tag -n1 -l tag-lines >actual &&
559 test_cmp expect actual &&
561 echo " tag line two" >>expect &&
562 git-tag -n2 -l | grep "^ *tag.line" >actual &&
563 test_cmp expect actual &&
564 git-tag -n2 -l tag-lines >actual &&
565 test_cmp expect actual &&
567 echo " tag line three" >>expect &&
568 git-tag -n3 -l | grep "^ *tag.line" >actual &&
569 test_cmp expect actual &&
570 git-tag -n3 -l tag-lines >actual &&
571 test_cmp expect actual &&
572 git-tag -n4 -l | grep "^ *tag.line" >actual &&
573 test_cmp expect actual &&
574 git-tag -n4 -l tag-lines >actual &&
575 test_cmp expect actual &&
576 git-tag -n99 -l | grep "^ *tag.line" >actual &&
577 test_cmp expect actual &&
578 git-tag -n99 -l tag-lines >actual &&
579 test_cmp expect actual
582 # subsequent tests require gpg; check if it is available
583 gpg
--version >/dev
/null
584 if [ $?
-eq 127 ]; then
585 echo "gpg not found - skipping tag signing and verification tests"
590 # trying to verify annotated non-signed tags:
592 test_expect_success \
593 'trying to verify an annotated non-signed tag should fail' '
594 tag_exists annotated-tag &&
595 ! git-tag -v annotated-tag
598 test_expect_success \
599 'trying to verify a file-annotated non-signed tag should fail' '
600 tag_exists file-annotated-tag &&
601 ! git-tag -v file-annotated-tag
604 test_expect_success \
605 'trying to verify two annotated non-signed tags should fail' '
606 tag_exists annotated-tag file-annotated-tag &&
607 ! git-tag -v annotated-tag file-annotated-tag
610 # creating and verifying signed tags:
612 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
613 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
614 # that version, creation of signed tags using the generated key fails.
615 case "$(gpg --version)" in
616 'gpg (GnuPG) 1.0.6'*)
617 echo "Skipping signed tag tests, because a bug in 1.0.6 version"
623 # key generation info: gpg --homedir t/t7004 --gen-key
624 # Type DSA and Elgamal, size 2048 bits, no expiration date.
625 # Name and email: C O Mitter <committer@example.com>
626 # No password given, to enable non-interactive operation.
628 cp -R ..
/t7004 .
/gpghome
630 GNUPGHOME
="$(pwd)/gpghome"
633 get_tag_header signed-tag
$commit commit
$time >expect
634 echo 'A signed tag message' >>expect
635 echo '-----BEGIN PGP SIGNATURE-----' >>expect
636 test_expect_success
'creating a signed tag with -m message should succeed' '
637 git-tag -s -m "A signed tag message" signed-tag &&
638 get_tag_msg signed-tag >actual &&
639 test_cmp expect actual
642 get_tag_header u-signed-tag
$commit commit
$time >expect
643 echo 'Another message' >>expect
644 echo '-----BEGIN PGP SIGNATURE-----' >>expect
645 test_expect_success
'sign with a given key id' '
647 git tag -u committer@example.com -m "Another message" u-signed-tag &&
648 get_tag_msg u-signed-tag >actual &&
649 test_cmp expect actual
653 test_expect_success
'sign with an unknown id (1)' '
655 ! git tag -u author@example.com -m "Another message" o-signed-tag
659 test_expect_success
'sign with an unknown id (2)' '
661 ! git tag -u DEADBEEF -m "Another message" o-signed-tag
665 cat >fakeeditor
<<'EOF'
667 test -n "$1" && exec >"$1"
668 echo A signed tag message
669 echo from a fake editor.
673 get_tag_header implied-sign
$commit commit
$time >expect
674 .
/fakeeditor
>>expect
675 echo '-----BEGIN PGP SIGNATURE-----' >>expect
676 test_expect_success
'-u implies signed tag' '
677 GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
678 get_tag_msg implied-sign >actual &&
679 test_cmp expect actual
682 cat >sigmsgfile
<<EOF
686 get_tag_header file-signed-tag
$commit commit
$time >expect
687 cat sigmsgfile
>>expect
688 echo '-----BEGIN PGP SIGNATURE-----' >>expect
689 test_expect_success \
690 'creating a signed tag with -F messagefile should succeed' '
691 git-tag -s -F sigmsgfile file-signed-tag &&
692 get_tag_msg file-signed-tag >actual &&
693 test_cmp expect actual
696 cat >siginputmsg
<<EOF
697 A signed tag message from
700 get_tag_header stdin-signed-tag
$commit commit
$time >expect
701 cat siginputmsg
>>expect
702 echo '-----BEGIN PGP SIGNATURE-----' >>expect
703 test_expect_success
'creating a signed tag with -F - should succeed' '
704 git-tag -s -F - stdin-signed-tag <siginputmsg &&
705 get_tag_msg stdin-signed-tag >actual &&
706 test_cmp expect actual
709 get_tag_header implied-annotate
$commit commit
$time >expect
710 .
/fakeeditor
>>expect
711 echo '-----BEGIN PGP SIGNATURE-----' >>expect
712 test_expect_success
'-s implies annotated tag' '
713 GIT_EDITOR=./fakeeditor git-tag -s implied-annotate &&
714 get_tag_msg implied-annotate >actual &&
715 test_cmp expect actual
718 test_expect_success \
719 'trying to create a signed tag with non-existing -F file should fail' '
720 ! test -f nonexistingfile &&
721 ! tag_exists nosigtag &&
722 ! git-tag -s -F nonexistingfile nosigtag &&
723 ! tag_exists nosigtag
726 test_expect_success
'verifying a signed tag should succeed' \
727 'git-tag -v signed-tag'
729 test_expect_success
'verifying two signed tags in one command should succeed' \
730 'git-tag -v signed-tag file-signed-tag'
732 test_expect_success \
733 'verifying many signed and non-signed tags should fail' '
734 ! git-tag -v signed-tag annotated-tag &&
735 ! git-tag -v file-annotated-tag file-signed-tag &&
736 ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
737 ! git-tag -v signed-tag annotated-tag file-signed-tag
740 test_expect_success
'verifying a forged tag should fail' '
741 forged=$(git cat-file tag signed-tag |
742 sed -e "s/signed-tag/forged-tag/" |
744 git tag forged-tag $forged &&
745 ! git-tag -v forged-tag
748 # blank and empty messages for signed tags:
750 get_tag_header empty-signed-tag
$commit commit
$time >expect
751 echo '-----BEGIN PGP SIGNATURE-----' >>expect
752 test_expect_success \
753 'creating a signed tag with an empty -m message should succeed' '
754 git-tag -s -m "" empty-signed-tag &&
755 get_tag_msg empty-signed-tag >actual &&
756 test_cmp expect actual &&
757 git-tag -v empty-signed-tag
761 get_tag_header emptyfile-signed-tag
$commit commit
$time >expect
762 echo '-----BEGIN PGP SIGNATURE-----' >>expect
763 test_expect_success \
764 'creating a signed tag with an empty -F messagefile should succeed' '
765 git-tag -s -F sigemptyfile emptyfile-signed-tag &&
766 get_tag_msg emptyfile-signed-tag >actual &&
767 test_cmp expect actual &&
768 git-tag -v emptyfile-signed-tag
771 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
772 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
773 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
774 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
775 get_tag_header blanks-signed-tag
$commit commit
$time >expect
785 echo '-----BEGIN PGP SIGNATURE-----' >>expect
786 test_expect_success \
787 'extra blanks in the message for a signed tag should be removed' '
788 git-tag -s -F sigblanksfile blanks-signed-tag &&
789 get_tag_msg blanks-signed-tag >actual &&
790 test_cmp expect actual &&
791 git-tag -v blanks-signed-tag
794 get_tag_header blank-signed-tag
$commit commit
$time >expect
795 echo '-----BEGIN PGP SIGNATURE-----' >>expect
796 test_expect_success \
797 'creating a signed tag with a blank -m message should succeed' '
798 git-tag -s -m " " blank-signed-tag &&
799 get_tag_msg blank-signed-tag >actual &&
800 test_cmp expect actual &&
801 git-tag -v blank-signed-tag
804 echo ' ' >sigblankfile
805 echo '' >>sigblankfile
806 echo ' ' >>sigblankfile
807 get_tag_header blankfile-signed-tag
$commit commit
$time >expect
808 echo '-----BEGIN PGP SIGNATURE-----' >>expect
809 test_expect_success \
810 'creating a signed tag with blank -F file with spaces should succeed' '
811 git-tag -s -F sigblankfile blankfile-signed-tag &&
812 get_tag_msg blankfile-signed-tag >actual &&
813 test_cmp expect actual &&
814 git-tag -v blankfile-signed-tag
817 printf ' ' >sigblanknonlfile
818 get_tag_header blanknonlfile-signed-tag
$commit commit
$time >expect
819 echo '-----BEGIN PGP SIGNATURE-----' >>expect
820 test_expect_success \
821 'creating a signed tag with spaces and no newline should succeed' '
822 git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
823 get_tag_msg blanknonlfile-signed-tag >actual &&
824 test_cmp expect actual &&
825 git-tag -v signed-tag
828 # messages with commented lines for signed tags:
830 cat >sigcommentsfile
<<EOF
847 get_tag_header comments-signed-tag
$commit commit
$time >expect
856 echo '-----BEGIN PGP SIGNATURE-----' >>expect
857 test_expect_success \
858 'creating a signed tag with a -F file with #comments should succeed' '
859 git-tag -s -F sigcommentsfile comments-signed-tag &&
860 get_tag_msg comments-signed-tag >actual &&
861 test_cmp expect actual &&
862 git-tag -v comments-signed-tag
865 get_tag_header comment-signed-tag
$commit commit
$time >expect
866 echo '-----BEGIN PGP SIGNATURE-----' >>expect
867 test_expect_success \
868 'creating a signed tag with #commented -m message should succeed' '
869 git-tag -s -m "#comment" comment-signed-tag &&
870 get_tag_msg comment-signed-tag >actual &&
871 test_cmp expect actual &&
872 git-tag -v comment-signed-tag
875 echo '#comment' >sigcommentfile
876 echo '' >>sigcommentfile
877 echo '####' >>sigcommentfile
878 get_tag_header commentfile-signed-tag
$commit commit
$time >expect
879 echo '-----BEGIN PGP SIGNATURE-----' >>expect
880 test_expect_success \
881 'creating a signed tag with #commented -F messagefile should succeed' '
882 git-tag -s -F sigcommentfile commentfile-signed-tag &&
883 get_tag_msg commentfile-signed-tag >actual &&
884 test_cmp expect actual &&
885 git-tag -v commentfile-signed-tag
888 printf '#comment' >sigcommentnonlfile
889 get_tag_header commentnonlfile-signed-tag
$commit commit
$time >expect
890 echo '-----BEGIN PGP SIGNATURE-----' >>expect
891 test_expect_success \
892 'creating a signed tag with a #comment and no newline should succeed' '
893 git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
894 get_tag_msg commentnonlfile-signed-tag >actual &&
895 test_cmp expect actual &&
896 git-tag -v commentnonlfile-signed-tag
899 # listing messages for signed tags:
901 test_expect_success \
902 'listing the one-line message of a signed tag should succeed' '
903 git-tag -s -m "A message line signed" stag-one-line &&
905 echo "stag-one-line" >expect &&
906 git-tag -l | grep "^stag-one-line" >actual &&
907 test_cmp expect actual &&
908 git-tag -n0 -l | grep "^stag-one-line" >actual &&
909 test_cmp expect actual &&
910 git-tag -n0 -l stag-one-line >actual &&
911 test_cmp expect actual &&
913 echo "stag-one-line A message line signed" >expect &&
914 git-tag -n1 -l | grep "^stag-one-line" >actual &&
915 test_cmp expect actual &&
916 git-tag -n -l | grep "^stag-one-line" >actual &&
917 test_cmp expect actual &&
918 git-tag -n1 -l stag-one-line >actual &&
919 test_cmp expect actual &&
920 git-tag -n2 -l stag-one-line >actual &&
921 test_cmp expect actual &&
922 git-tag -n999 -l stag-one-line >actual &&
923 test_cmp expect actual
926 test_expect_success \
927 'listing the zero-lines message of a signed tag should succeed' '
928 git-tag -s -m "" stag-zero-lines &&
930 echo "stag-zero-lines" >expect &&
931 git-tag -l | grep "^stag-zero-lines" >actual &&
932 test_cmp expect actual &&
933 git-tag -n0 -l | grep "^stag-zero-lines" >actual &&
934 test_cmp expect actual &&
935 git-tag -n0 -l stag-zero-lines >actual &&
936 test_cmp expect actual &&
938 echo "stag-zero-lines " >expect &&
939 git-tag -n1 -l | grep "^stag-zero-lines" >actual &&
940 test_cmp expect actual &&
941 git-tag -n -l | grep "^stag-zero-lines" >actual &&
942 test_cmp expect actual &&
943 git-tag -n1 -l stag-zero-lines >actual &&
944 test_cmp expect actual &&
945 git-tag -n2 -l stag-zero-lines >actual &&
946 test_cmp expect actual &&
947 git-tag -n999 -l stag-zero-lines >actual &&
948 test_cmp expect actual
951 echo 'stag line one' >sigtagmsg
952 echo 'stag line two' >>sigtagmsg
953 echo 'stag line three' >>sigtagmsg
954 test_expect_success \
955 'listing many message lines of a signed tag should succeed' '
956 git-tag -s -F sigtagmsg stag-lines &&
958 echo "stag-lines" >expect &&
959 git-tag -l | grep "^stag-lines" >actual &&
960 test_cmp expect actual &&
961 git-tag -n0 -l | grep "^stag-lines" >actual &&
962 test_cmp expect actual &&
963 git-tag -n0 -l stag-lines >actual &&
964 test_cmp expect actual &&
966 echo "stag-lines stag line one" >expect &&
967 git-tag -n1 -l | grep "^stag-lines" >actual &&
968 test_cmp expect actual &&
969 git-tag -n -l | grep "^stag-lines" >actual &&
970 test_cmp expect actual &&
971 git-tag -n1 -l stag-lines >actual &&
972 test_cmp expect actual &&
974 echo " stag line two" >>expect &&
975 git-tag -n2 -l | grep "^ *stag.line" >actual &&
976 test_cmp expect actual &&
977 git-tag -n2 -l stag-lines >actual &&
978 test_cmp expect actual &&
980 echo " stag line three" >>expect &&
981 git-tag -n3 -l | grep "^ *stag.line" >actual &&
982 test_cmp expect actual &&
983 git-tag -n3 -l stag-lines >actual &&
984 test_cmp expect actual &&
985 git-tag -n4 -l | grep "^ *stag.line" >actual &&
986 test_cmp expect actual &&
987 git-tag -n4 -l stag-lines >actual &&
988 test_cmp expect actual &&
989 git-tag -n99 -l | grep "^ *stag.line" >actual &&
990 test_cmp expect actual &&
991 git-tag -n99 -l stag-lines >actual &&
992 test_cmp expect actual
995 # tags pointing to objects different from commits:
997 tree
=$
(git rev-parse HEAD^
{tree
})
998 blob
=$
(git rev-parse HEAD
:foo
)
999 tag
=$
(git rev-parse signed-tag
)
1001 get_tag_header tree-signed-tag
$tree tree
$time >expect
1002 echo "A message for a tree" >>expect
1003 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1004 test_expect_success \
1005 'creating a signed tag pointing to a tree should succeed' '
1006 git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1007 get_tag_msg tree-signed-tag >actual &&
1008 test_cmp expect actual
1011 get_tag_header blob-signed-tag
$blob blob
$time >expect
1012 echo "A message for a blob" >>expect
1013 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1014 test_expect_success \
1015 'creating a signed tag pointing to a blob should succeed' '
1016 git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1017 get_tag_msg blob-signed-tag >actual &&
1018 test_cmp expect actual
1021 get_tag_header tag-signed-tag
$tag tag
$time >expect
1022 echo "A message for another tag" >>expect
1023 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1024 test_expect_success \
1025 'creating a signed tag pointing to another tag should succeed' '
1026 git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1027 get_tag_msg tag-signed-tag >actual &&
1028 test_cmp expect actual
1031 # try to sign with bad user.signingkey
1032 git config user.signingkey BobTheMouse
1033 test_expect_success \
1034 'git-tag -s fails if gpg is misconfigured' \
1035 '! git tag -s -m tail tag-gpg-failure'
1036 git config
--unset user.signingkey
1038 # try to verify without gpg:
1041 test_expect_success \
1042 'verify signed tag fails when public key is not present' \
1043 '! git-tag -v signed-tag'
1045 test_expect_success \
1046 'git-tag -a fails if tag annotation is empty' '
1047 ! (GIT_EDITOR=cat git tag -a initial-comment)
1050 test_expect_success \
1051 'message in editor has initial comment' '
1052 GIT_EDITOR=cat git tag -a initial-comment > actual
1053 # check the first line --- should be empty
1054 first=$(sed -e 1q <actual) &&
1056 # remove commented lines from the remainder -- should be empty
1057 rest=$(sed -e 1d -e '/^
#/d' <actual) &&
1061 get_tag_header reuse $commit commit $time >expect
1062 echo "An annotation to be reused" >> expect
1063 test_expect_success \
1064 'overwriting an annoted tag should use its previous body
' '
1065 git tag
-a -m "An annotation to be reused" reuse
&&
1066 GIT_EDITOR
=true git tag
-f -a reuse
&&
1067 get_tag_msg reuse
>actual
&&
1068 test_cmp expect actual