Fixup the clean-up of environment handling.
[git/mingw.git] / t / t7004-tag.sh
blobd5746532814b40408122d13439bc2c70f3fef5a5
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git-tag
8 Tests for operations with tags.'
10 . ./test-lib.sh
12 # creating and listing lightweight tags:
14 tag_exists () {
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' '
20 git tag -l &&
21 git tag
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_failure '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 ! git-tag mynotag &&
34 ! tag_exists mynotag
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' '
49 test_tick &&
50 echo foo >foo &&
51 git add foo &&
52 git commit -m Foo &&
53 git tag mytag
56 test_expect_success 'listing all tags if one exists should succeed' '
57 git-tag -l &&
58 git-tag
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
66 # pattern matching:
68 test_expect_success 'listing a tag using a matching pattern should succeed' \
69 'git-tag -l mytag'
71 test_expect_success \
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
76 test_expect_success \
77 'listing tags using a non-matching pattern should suceed' \
78 'git-tag -l xxx'
80 test_expect_success \
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:
86 test_expect_failure \
87 'trying to create a tag with the name of one existing should fail' \
88 'git tag mytag'
90 test_expect_success \
91 'trying to create a tag with a non-valid name should fail' '
92 test `git-tag -l | wc -l` -eq 1 &&
93 ! git tag "" &&
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 &&
103 tag_exists myhead
106 # deleting tags:
108 test_expect_success 'trying to delete an unknown tag should fail' '
109 ! tag_exists unknown-tag &&
110 ! git-tag -d unknown-tag
113 cat >expect <<EOF
114 myhead
115 mytag
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 &&
120 git-tag -d &&
121 git tag -l > actual && git diff expect actual
124 test_expect_success \
125 'deleting two existing tags in one command should succeed' '
126 tag_exists mytag &&
127 tag_exists myhead &&
128 git-tag -d mytag myhead &&
129 ! tag_exists mytag &&
130 ! tag_exists myhead
133 test_expect_success \
134 'creating a tag with the name of another deleted one should succeed' '
135 ! tag_exists mytag &&
136 git-tag mytag &&
137 tag_exists mytag
140 test_expect_success \
141 'trying to delete two tags, existing and not, should fail in the 2nd' '
142 tag_exists mytag &&
143 ! tag_exists myhead &&
144 ! git-tag -d mytag anothertag &&
145 ! tag_exists mytag &&
146 ! tag_exists myhead
149 test_expect_failure 'trying to delete an already deleted tag should fail' \
150 'git-tag -d mytag'
152 # listing various tags with pattern matching:
154 cat >expect <<EOF
158 t210
159 t211
160 v0.2.1
161 v1.0
162 v1.0.1
163 v1.1.3
165 test_expect_success 'listing all tags should print them ordered' '
166 git tag v1.0.1 &&
167 git tag t211 &&
168 git tag aa1 &&
169 git tag v0.2.1 &&
170 git tag v1.1.3 &&
171 git tag cba &&
172 git tag a1 &&
173 git tag v1.0 &&
174 git tag t210 &&
175 git tag -l > actual &&
176 git diff expect actual &&
177 git tag > actual &&
178 git diff expect actual
181 cat >expect <<EOF
186 test_expect_success \
187 'listing tags with substring as pattern must print those matching' '
188 rm *a* &&
189 git-tag -l "*a*" > current &&
190 git diff expect current
193 cat >expect <<EOF
194 v0.2.1
195 v1.0.1
197 test_expect_success \
198 'listing tags with a suffix as pattern must print those matching' '
199 git-tag -l "*.1" > actual &&
200 git diff expect actual
203 cat >expect <<EOF
204 t210
205 t211
207 test_expect_success \
208 'listing tags with a prefix as pattern must print those matching' '
209 git-tag -l "t21*" > actual &&
210 git diff expect actual
213 cat >expect <<EOF
216 test_expect_success \
217 'listing tags using a name as pattern must print that one matching' '
218 git-tag -l a1 > actual &&
219 git diff expect actual
222 cat >expect <<EOF
223 v1.0
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 git diff expect actual
231 cat >expect <<EOF
232 v1.0.1
233 v1.1.3
235 test_expect_success \
236 'listing tags with ? in the pattern should print those matching' '
237 git-tag -l "v1.?.?" > actual &&
238 git diff expect actual
241 >expect
242 test_expect_success \
243 'listing tags using v.* should print nothing because none have v.' '
244 git-tag -l "v.*" > actual &&
245 git diff expect actual
248 cat >expect <<EOF
249 v0.2.1
250 v1.0
251 v1.0.1
252 v1.1.3
254 test_expect_success \
255 'listing tags using v* should print only those having v' '
256 git-tag -l "v*" > actual &&
257 git diff 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_failure 'trying to verify an unknown tag should fail' \
270 'git-tag -v unknown-tag'
272 test_expect_failure \
273 'trying to verify a non-annotated and non-signed tag should fail' \
274 'git-tag -v non-annotated-tag'
276 test_expect_failure \
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:
282 get_tag_msg () {
283 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
286 # run test_tick before committing always gives the time in that timezone
287 get_tag_header () {
288 cat <<EOF
289 object $2
290 type $3
291 tag $1
292 tagger C O Mitter <committer@example.com> $4 -0700
297 commit=$(git rev-parse HEAD)
298 time=$test_tick
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 git diff expect actual
309 cat >msgfile <<EOF
310 Another message
311 in a file.
313 get_tag_header file-annotated-tag $commit commit $time >expect
314 cat msgfile >>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 git diff expect actual
322 cat >inputmsg <<EOF
323 A message from the
324 standard input
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 git diff 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 &&
339 ! tag_exists 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 &&
352 ! tag_exists 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 git diff expect actual
365 >emptyfile
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 git diff 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
379 cat >>expect <<EOF
380 Leading blank lines
382 Repeated blank lines
384 Trailing spaces
386 Trailing blank lines
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 git diff 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 git diff expect actual
403 echo ' ' >blankfile
404 echo '' >>blankfile
405 echo ' ' >>blankfile
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 git diff 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 git diff expect actual
423 # messages with commented lines:
425 cat >commentsfile <<EOF
426 # A comment
428 ############
429 The message.
430 ############
431 One line.
434 # commented lines
435 # commented lines
437 Another line.
438 # comments
440 Last line.
442 get_tag_header comments-annotated-tag $commit commit $time >expect
443 cat >>expect <<EOF
444 The message.
445 One line.
447 Another line.
449 Last line.
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 git diff 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 git diff 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 git diff 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 git diff 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 git diff expect actual &&
495 git-tag -n 0 -l | grep "^tag-one-line" >actual &&
496 git diff expect actual &&
497 git-tag -n 0 -l tag-one-line >actual &&
498 git diff expect actual &&
500 echo "tag-one-line A msg" >expect &&
501 git-tag -n xxx -l | grep "^tag-one-line" >actual &&
502 git diff expect actual &&
503 git-tag -n "" -l | grep "^tag-one-line" >actual &&
504 git diff expect actual &&
505 git-tag -n 1 -l | grep "^tag-one-line" >actual &&
506 git diff expect actual &&
507 git-tag -n -l | grep "^tag-one-line" >actual &&
508 git diff expect actual &&
509 git-tag -n 1 -l tag-one-line >actual &&
510 git diff expect actual &&
511 git-tag -n 2 -l tag-one-line >actual &&
512 git diff expect actual &&
513 git-tag -n 999 -l tag-one-line >actual &&
514 git diff expect actual
517 test_expect_success \
518 'listing the zero-lines message of a non-signed tag should succeed' '
519 git-tag -m "" tag-zero-lines &&
521 echo "tag-zero-lines" >expect &&
522 git-tag -l | grep "^tag-zero-lines" >actual &&
523 git diff expect actual &&
524 git-tag -n 0 -l | grep "^tag-zero-lines" >actual &&
525 git diff expect actual &&
526 git-tag -n 0 -l tag-zero-lines >actual &&
527 git diff expect actual &&
529 echo "tag-zero-lines " >expect &&
530 git-tag -n 1 -l | grep "^tag-zero-lines" >actual &&
531 git diff expect actual &&
532 git-tag -n -l | grep "^tag-zero-lines" >actual &&
533 git diff expect actual &&
534 git-tag -n 1 -l tag-zero-lines >actual &&
535 git diff expect actual &&
536 git-tag -n 2 -l tag-zero-lines >actual &&
537 git diff expect actual &&
538 git-tag -n 999 -l tag-zero-lines >actual &&
539 git diff expect actual
542 echo 'tag line one' >annotagmsg
543 echo 'tag line two' >>annotagmsg
544 echo 'tag line three' >>annotagmsg
545 test_expect_success \
546 'listing many message lines of a non-signed tag should succeed' '
547 git-tag -F annotagmsg tag-lines &&
549 echo "tag-lines" >expect &&
550 git-tag -l | grep "^tag-lines" >actual &&
551 git diff expect actual &&
552 git-tag -n 0 -l | grep "^tag-lines" >actual &&
553 git diff expect actual &&
554 git-tag -n 0 -l tag-lines >actual &&
555 git diff expect actual &&
557 echo "tag-lines tag line one" >expect &&
558 git-tag -n 1 -l | grep "^tag-lines" >actual &&
559 git diff expect actual &&
560 git-tag -n -l | grep "^tag-lines" >actual &&
561 git diff expect actual &&
562 git-tag -n 1 -l tag-lines >actual &&
563 git diff expect actual &&
565 echo " tag line two" >>expect &&
566 git-tag -n 2 -l | grep "^ *tag.line" >actual &&
567 git diff expect actual &&
568 git-tag -n 2 -l tag-lines >actual &&
569 git diff expect actual &&
571 echo " tag line three" >>expect &&
572 git-tag -n 3 -l | grep "^ *tag.line" >actual &&
573 git diff expect actual &&
574 git-tag -n 3 -l tag-lines >actual &&
575 git diff expect actual &&
576 git-tag -n 4 -l | grep "^ *tag.line" >actual &&
577 git diff expect actual &&
578 git-tag -n 4 -l tag-lines >actual &&
579 git diff expect actual &&
580 git-tag -n 99 -l | grep "^ *tag.line" >actual &&
581 git diff expect actual &&
582 git-tag -n 99 -l tag-lines >actual &&
583 git diff expect actual
586 # trying to verify annotated non-signed tags:
588 test_expect_success \
589 'trying to verify an annotated non-signed tag should fail' '
590 tag_exists annotated-tag &&
591 ! git-tag -v annotated-tag
594 test_expect_success \
595 'trying to verify a file-annotated non-signed tag should fail' '
596 tag_exists file-annotated-tag &&
597 ! git-tag -v file-annotated-tag
600 test_expect_success \
601 'trying to verify two annotated non-signed tags should fail' '
602 tag_exists annotated-tag file-annotated-tag &&
603 ! git-tag -v annotated-tag file-annotated-tag
606 # creating and verifying signed tags:
608 gpg --version >/dev/null
609 if [ $? -eq 127 ]; then
610 echo "Skipping signed tags tests, because gpg was not found"
611 test_done
612 exit
615 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
616 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
617 # that version, creation of signed tags using the generated key fails.
618 case "$(gpg --version)" in
619 'gpg (GnuPG) 1.0.6'*)
620 echo "Skipping signed tag tests, because a bug in 1.0.6 version"
621 test_done
622 exit
624 esac
626 # key generation info: gpg --homedir t/t7004 --gen-key
627 # Type DSA and Elgamal, size 2048 bits, no expiration date.
628 # Name and email: C O Mitter <committer@example.com>
629 # No password given, to enable non-interactive operation.
631 cp -R ../t7004 ./gpghome
632 chmod 0700 gpghome
633 export GNUPGHOME="$(pwd)/gpghome"
635 get_tag_header signed-tag $commit commit $time >expect
636 echo 'A signed tag message' >>expect
637 echo '-----BEGIN PGP SIGNATURE-----' >>expect
638 test_expect_success 'creating a signed tag with -m message should succeed' '
639 git-tag -s -m "A signed tag message" signed-tag &&
640 get_tag_msg signed-tag >actual &&
641 git diff expect actual
644 cat >sigmsgfile <<EOF
645 Another signed tag
646 message in a file.
648 get_tag_header file-signed-tag $commit commit $time >expect
649 cat sigmsgfile >>expect
650 echo '-----BEGIN PGP SIGNATURE-----' >>expect
651 test_expect_success \
652 'creating a signed tag with -F messagefile should succeed' '
653 git-tag -s -F sigmsgfile file-signed-tag &&
654 get_tag_msg file-signed-tag >actual &&
655 git diff expect actual
658 cat >siginputmsg <<EOF
659 A signed tag message from
660 the standard input
662 get_tag_header stdin-signed-tag $commit commit $time >expect
663 cat siginputmsg >>expect
664 echo '-----BEGIN PGP SIGNATURE-----' >>expect
665 test_expect_success 'creating a signed tag with -F - should succeed' '
666 git-tag -s -F - stdin-signed-tag <siginputmsg &&
667 get_tag_msg stdin-signed-tag >actual &&
668 git diff expect actual
671 cat >fakeeditor <<'EOF'
672 #!/bin/sh
673 test -n "$1" && exec >"$1"
674 echo A signed tag message
675 echo from a fake editor.
677 chmod +x fakeeditor
678 get_tag_header implied-annotate $commit commit $time >expect
679 ./fakeeditor >>expect
680 echo '-----BEGIN PGP SIGNATURE-----' >>expect
681 test_expect_success '-s implies annotated tag' '
682 GIT_EDITOR=./fakeeditor git-tag -s implied-annotate &&
683 get_tag_msg implied-annotate >actual &&
684 git diff expect actual
687 test_expect_success \
688 'trying to create a signed tag with non-existing -F file should fail' '
689 ! test -f nonexistingfile &&
690 ! tag_exists nosigtag &&
691 ! git-tag -s -F nonexistingfile nosigtag &&
692 ! tag_exists nosigtag
695 test_expect_success 'verifying a signed tag should succeed' \
696 'git-tag -v signed-tag'
698 test_expect_success 'verifying two signed tags in one command should succeed' \
699 'git-tag -v signed-tag file-signed-tag'
701 test_expect_success \
702 'verifying many signed and non-signed tags should fail' '
703 ! git-tag -v signed-tag annotated-tag &&
704 ! git-tag -v file-annotated-tag file-signed-tag &&
705 ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
706 ! git-tag -v signed-tag annotated-tag file-signed-tag
709 test_expect_success 'verifying a forged tag should fail' '
710 forged=$(git cat-file tag signed-tag |
711 sed -e "s/signed-tag/forged-tag/" |
712 git mktag) &&
713 git tag forged-tag $forged &&
714 ! git-tag -v forged-tag
717 # blank and empty messages for signed tags:
719 get_tag_header empty-signed-tag $commit commit $time >expect
720 echo '-----BEGIN PGP SIGNATURE-----' >>expect
721 test_expect_success \
722 'creating a signed tag with an empty -m message should succeed' '
723 git-tag -s -m "" empty-signed-tag &&
724 get_tag_msg empty-signed-tag >actual &&
725 git diff expect actual &&
726 git-tag -v empty-signed-tag
729 >sigemptyfile
730 get_tag_header emptyfile-signed-tag $commit commit $time >expect
731 echo '-----BEGIN PGP SIGNATURE-----' >>expect
732 test_expect_success \
733 'creating a signed tag with an empty -F messagefile should succeed' '
734 git-tag -s -F sigemptyfile emptyfile-signed-tag &&
735 get_tag_msg emptyfile-signed-tag >actual &&
736 git diff expect actual &&
737 git-tag -v emptyfile-signed-tag
740 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
741 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
742 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
743 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
744 get_tag_header blanks-signed-tag $commit commit $time >expect
745 cat >>expect <<EOF
746 Leading blank lines
748 Repeated blank lines
750 Trailing spaces
752 Trailing blank lines
754 echo '-----BEGIN PGP SIGNATURE-----' >>expect
755 test_expect_success \
756 'extra blanks in the message for a signed tag should be removed' '
757 git-tag -s -F sigblanksfile blanks-signed-tag &&
758 get_tag_msg blanks-signed-tag >actual &&
759 git diff expect actual &&
760 git-tag -v blanks-signed-tag
763 get_tag_header blank-signed-tag $commit commit $time >expect
764 echo '-----BEGIN PGP SIGNATURE-----' >>expect
765 test_expect_success \
766 'creating a signed tag with a blank -m message should succeed' '
767 git-tag -s -m " " blank-signed-tag &&
768 get_tag_msg blank-signed-tag >actual &&
769 git diff expect actual &&
770 git-tag -v blank-signed-tag
773 echo ' ' >sigblankfile
774 echo '' >>sigblankfile
775 echo ' ' >>sigblankfile
776 get_tag_header blankfile-signed-tag $commit commit $time >expect
777 echo '-----BEGIN PGP SIGNATURE-----' >>expect
778 test_expect_success \
779 'creating a signed tag with blank -F file with spaces should succeed' '
780 git-tag -s -F sigblankfile blankfile-signed-tag &&
781 get_tag_msg blankfile-signed-tag >actual &&
782 git diff expect actual &&
783 git-tag -v blankfile-signed-tag
786 printf ' ' >sigblanknonlfile
787 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
788 echo '-----BEGIN PGP SIGNATURE-----' >>expect
789 test_expect_success \
790 'creating a signed tag with spaces and no newline should succeed' '
791 git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
792 get_tag_msg blanknonlfile-signed-tag >actual &&
793 git diff expect actual &&
794 git-tag -v signed-tag
797 # messages with commented lines for signed tags:
799 cat >sigcommentsfile <<EOF
800 # A comment
802 ############
803 The message.
804 ############
805 One line.
808 # commented lines
809 # commented lines
811 Another line.
812 # comments
814 Last line.
816 get_tag_header comments-signed-tag $commit commit $time >expect
817 cat >>expect <<EOF
818 The message.
819 One line.
821 Another line.
823 Last line.
825 echo '-----BEGIN PGP SIGNATURE-----' >>expect
826 test_expect_success \
827 'creating a signed tag with a -F file with #comments should succeed' '
828 git-tag -s -F sigcommentsfile comments-signed-tag &&
829 get_tag_msg comments-signed-tag >actual &&
830 git diff expect actual &&
831 git-tag -v comments-signed-tag
834 get_tag_header comment-signed-tag $commit commit $time >expect
835 echo '-----BEGIN PGP SIGNATURE-----' >>expect
836 test_expect_success \
837 'creating a signed tag with #commented -m message should succeed' '
838 git-tag -s -m "#comment" comment-signed-tag &&
839 get_tag_msg comment-signed-tag >actual &&
840 git diff expect actual &&
841 git-tag -v comment-signed-tag
844 echo '#comment' >sigcommentfile
845 echo '' >>sigcommentfile
846 echo '####' >>sigcommentfile
847 get_tag_header commentfile-signed-tag $commit commit $time >expect
848 echo '-----BEGIN PGP SIGNATURE-----' >>expect
849 test_expect_success \
850 'creating a signed tag with #commented -F messagefile should succeed' '
851 git-tag -s -F sigcommentfile commentfile-signed-tag &&
852 get_tag_msg commentfile-signed-tag >actual &&
853 git diff expect actual &&
854 git-tag -v commentfile-signed-tag
857 printf '#comment' >sigcommentnonlfile
858 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
859 echo '-----BEGIN PGP SIGNATURE-----' >>expect
860 test_expect_success \
861 'creating a signed tag with a #comment and no newline should succeed' '
862 git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
863 get_tag_msg commentnonlfile-signed-tag >actual &&
864 git diff expect actual &&
865 git-tag -v commentnonlfile-signed-tag
868 # listing messages for signed tags:
870 test_expect_success \
871 'listing the one-line message of a signed tag should succeed' '
872 git-tag -s -m "A message line signed" stag-one-line &&
874 echo "stag-one-line" >expect &&
875 git-tag -l | grep "^stag-one-line" >actual &&
876 git diff expect actual &&
877 git-tag -n 0 -l | grep "^stag-one-line" >actual &&
878 git diff expect actual &&
879 git-tag -n 0 -l stag-one-line >actual &&
880 git diff expect actual &&
882 echo "stag-one-line A message line signed" >expect &&
883 git-tag -n xxx -l | grep "^stag-one-line" >actual &&
884 git diff expect actual &&
885 git-tag -n "" -l | grep "^stag-one-line" >actual &&
886 git diff expect actual &&
887 git-tag -n 1 -l | grep "^stag-one-line" >actual &&
888 git diff expect actual &&
889 git-tag -n -l | grep "^stag-one-line" >actual &&
890 git diff expect actual &&
891 git-tag -n 1 -l stag-one-line >actual &&
892 git diff expect actual &&
893 git-tag -n 2 -l stag-one-line >actual &&
894 git diff expect actual &&
895 git-tag -n 999 -l stag-one-line >actual &&
896 git diff expect actual
899 test_expect_success \
900 'listing the zero-lines message of a signed tag should succeed' '
901 git-tag -s -m "" stag-zero-lines &&
903 echo "stag-zero-lines" >expect &&
904 git-tag -l | grep "^stag-zero-lines" >actual &&
905 git diff expect actual &&
906 git-tag -n 0 -l | grep "^stag-zero-lines" >actual &&
907 git diff expect actual &&
908 git-tag -n 0 -l stag-zero-lines >actual &&
909 git diff expect actual &&
911 echo "stag-zero-lines " >expect &&
912 git-tag -n 1 -l | grep "^stag-zero-lines" >actual &&
913 git diff expect actual &&
914 git-tag -n -l | grep "^stag-zero-lines" >actual &&
915 git diff expect actual &&
916 git-tag -n 1 -l stag-zero-lines >actual &&
917 git diff expect actual &&
918 git-tag -n 2 -l stag-zero-lines >actual &&
919 git diff expect actual &&
920 git-tag -n 999 -l stag-zero-lines >actual &&
921 git diff expect actual
924 echo 'stag line one' >sigtagmsg
925 echo 'stag line two' >>sigtagmsg
926 echo 'stag line three' >>sigtagmsg
927 test_expect_success \
928 'listing many message lines of a signed tag should succeed' '
929 git-tag -s -F sigtagmsg stag-lines &&
931 echo "stag-lines" >expect &&
932 git-tag -l | grep "^stag-lines" >actual &&
933 git diff expect actual &&
934 git-tag -n 0 -l | grep "^stag-lines" >actual &&
935 git diff expect actual &&
936 git-tag -n 0 -l stag-lines >actual &&
937 git diff expect actual &&
939 echo "stag-lines stag line one" >expect &&
940 git-tag -n 1 -l | grep "^stag-lines" >actual &&
941 git diff expect actual &&
942 git-tag -n -l | grep "^stag-lines" >actual &&
943 git diff expect actual &&
944 git-tag -n 1 -l stag-lines >actual &&
945 git diff expect actual &&
947 echo " stag line two" >>expect &&
948 git-tag -n 2 -l | grep "^ *stag.line" >actual &&
949 git diff expect actual &&
950 git-tag -n 2 -l stag-lines >actual &&
951 git diff expect actual &&
953 echo " stag line three" >>expect &&
954 git-tag -n 3 -l | grep "^ *stag.line" >actual &&
955 git diff expect actual &&
956 git-tag -n 3 -l stag-lines >actual &&
957 git diff expect actual &&
958 git-tag -n 4 -l | grep "^ *stag.line" >actual &&
959 git diff expect actual &&
960 git-tag -n 4 -l stag-lines >actual &&
961 git diff expect actual &&
962 git-tag -n 99 -l | grep "^ *stag.line" >actual &&
963 git diff expect actual &&
964 git-tag -n 99 -l stag-lines >actual &&
965 git diff expect actual
968 # tags pointing to objects different from commits:
970 tree=$(git rev-parse HEAD^{tree})
971 blob=$(git rev-parse HEAD:foo)
972 tag=$(git rev-parse signed-tag)
974 get_tag_header tree-signed-tag $tree tree $time >expect
975 echo "A message for a tree" >>expect
976 echo '-----BEGIN PGP SIGNATURE-----' >>expect
977 test_expect_success \
978 'creating a signed tag pointing to a tree should succeed' '
979 git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
980 get_tag_msg tree-signed-tag >actual &&
981 git diff expect actual
984 get_tag_header blob-signed-tag $blob blob $time >expect
985 echo "A message for a blob" >>expect
986 echo '-----BEGIN PGP SIGNATURE-----' >>expect
987 test_expect_success \
988 'creating a signed tag pointing to a blob should succeed' '
989 git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
990 get_tag_msg blob-signed-tag >actual &&
991 git diff expect actual
994 get_tag_header tag-signed-tag $tag tag $time >expect
995 echo "A message for another tag" >>expect
996 echo '-----BEGIN PGP SIGNATURE-----' >>expect
997 test_expect_success \
998 'creating a signed tag pointing to another tag should succeed' '
999 git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1000 get_tag_msg tag-signed-tag >actual &&
1001 git diff expect actual
1004 # try to sign with bad user.signingkey
1005 git config user.signingkey BobTheMouse
1006 test_expect_failure \
1007 'git-tag -s fails if gpg is misconfigured' \
1008 'git tag -s -m tail tag-gpg-failure'
1009 git config --unset user.signingkey
1011 # try to verify without gpg:
1013 rm -rf gpghome
1014 test_expect_failure \
1015 'verify signed tag fails when public key is not present' \
1016 'git-tag -v signed-tag'
1018 test_expect_failure \
1019 'git-tag -a fails if tag annotation is empty' '
1020 GIT_EDITOR=cat git tag -a initial-comment
1023 test_expect_success \
1024 'message in editor has initial comment' '
1025 GIT_EDITOR=cat git tag -a initial-comment > actual
1026 # check the first line --- should be empty
1027 first=$(sed -e 1q <actual) &&
1028 test -z "$first" &&
1029 # remove commented lines from the remainder -- should be empty
1030 rest=$(sed -e 1d -e '/^#/d' <actual) &&
1031 test -z "$rest"
1034 get_tag_header reuse $commit commit $time >expect
1035 echo "An annotation to be reused" >> expect
1036 test_expect_success \
1037 'overwriting an annoted tag should use its previous body' '
1038 git tag -a -m "An annotation to be reused" reuse &&
1039 GIT_EDITOR=true git tag -f -a reuse &&
1040 get_tag_msg reuse >actual &&
1041 git diff expect actual
1044 test_done