gitweb: Make config_to_multi return [] instead of [undef]
[git/spearce.git] / t / t7004-tag.sh
blob09d56e0839f042a74bee5c13ab251f19fcc2c76e
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 git-tag -l "*a*" > actual &&
189 git diff expect actual
192 cat >expect <<EOF
193 v0.2.1
194 v1.0.1
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
202 cat >expect <<EOF
203 t210
204 t211
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
212 cat >expect <<EOF
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
221 cat >expect <<EOF
222 v1.0
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
230 cat >expect <<EOF
231 v1.0.1
232 v1.1.3
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
240 >expect
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
247 cat >expect <<EOF
248 v0.2.1
249 v1.0
250 v1.0.1
251 v1.1.3
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_failure 'trying to verify an unknown tag should fail' \
269 'git-tag -v unknown-tag'
271 test_expect_failure \
272 'trying to verify a non-annotated and non-signed tag should fail' \
273 'git-tag -v non-annotated-tag'
275 test_expect_failure \
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:
281 get_tag_msg () {
282 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
285 # run test_tick before committing always gives the time in that timezone
286 get_tag_header () {
287 cat <<EOF
288 object $2
289 type $3
290 tag $1
291 tagger C O Mitter <committer@example.com> $4 -0700
296 commit=$(git rev-parse HEAD)
297 time=$test_tick
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
308 cat >msgfile <<EOF
309 Another message
310 in a file.
312 get_tag_header file-annotated-tag $commit commit $time >expect
313 cat msgfile >>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
321 cat >inputmsg <<EOF
322 A message from the
323 standard input
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 &&
338 ! tag_exists 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 &&
351 ! tag_exists 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
364 >emptyfile
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
378 cat >>expect <<EOF
379 Leading blank lines
381 Repeated blank lines
383 Trailing spaces
385 Trailing blank lines
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
402 echo ' ' >blankfile
403 echo '' >>blankfile
404 echo ' ' >>blankfile
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
425 # A comment
427 ############
428 The message.
429 ############
430 One line.
433 # commented lines
434 # commented lines
436 Another line.
437 # comments
439 Last line.
441 get_tag_header comments-annotated-tag $commit commit $time >expect
442 cat >>expect <<EOF
443 The message.
444 One line.
446 Another line.
448 Last line.
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 -n 0 -l | grep "^tag-one-line" >actual &&
495 git diff expect actual &&
496 git-tag -n 0 -l tag-one-line >actual &&
497 git diff expect actual &&
499 echo "tag-one-line A msg" >expect &&
500 git-tag -n xxx -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 -n 1 -l | grep "^tag-one-line" >actual &&
505 git diff expect actual &&
506 git-tag -n -l | grep "^tag-one-line" >actual &&
507 git diff expect actual &&
508 git-tag -n 1 -l tag-one-line >actual &&
509 git diff expect actual &&
510 git-tag -n 2 -l tag-one-line >actual &&
511 git diff expect actual &&
512 git-tag -n 999 -l tag-one-line >actual &&
513 git diff expect actual
516 test_expect_success \
517 'listing the zero-lines message of a non-signed tag should succeed' '
518 git-tag -m "" tag-zero-lines &&
520 echo "tag-zero-lines" >expect &&
521 git-tag -l | grep "^tag-zero-lines" >actual &&
522 git diff expect actual &&
523 git-tag -n 0 -l | grep "^tag-zero-lines" >actual &&
524 git diff expect actual &&
525 git-tag -n 0 -l tag-zero-lines >actual &&
526 git diff expect actual &&
528 echo "tag-zero-lines " >expect &&
529 git-tag -n 1 -l | grep "^tag-zero-lines" >actual &&
530 git diff expect actual &&
531 git-tag -n -l | grep "^tag-zero-lines" >actual &&
532 git diff expect actual &&
533 git-tag -n 1 -l tag-zero-lines >actual &&
534 git diff expect actual &&
535 git-tag -n 2 -l tag-zero-lines >actual &&
536 git diff expect actual &&
537 git-tag -n 999 -l tag-zero-lines >actual &&
538 git diff expect actual
541 echo 'tag line one' >annotagmsg
542 echo 'tag line two' >>annotagmsg
543 echo 'tag line three' >>annotagmsg
544 test_expect_success \
545 'listing many message lines of a non-signed tag should succeed' '
546 git-tag -F annotagmsg tag-lines &&
548 echo "tag-lines" >expect &&
549 git-tag -l | grep "^tag-lines" >actual &&
550 git diff expect actual &&
551 git-tag -n 0 -l | grep "^tag-lines" >actual &&
552 git diff expect actual &&
553 git-tag -n 0 -l tag-lines >actual &&
554 git diff expect actual &&
556 echo "tag-lines tag line one" >expect &&
557 git-tag -n 1 -l | grep "^tag-lines" >actual &&
558 git diff expect actual &&
559 git-tag -n -l | grep "^tag-lines" >actual &&
560 git diff expect actual &&
561 git-tag -n 1 -l tag-lines >actual &&
562 git diff expect actual &&
564 echo " tag line two" >>expect &&
565 git-tag -n 2 -l | grep "^ *tag.line" >actual &&
566 git diff expect actual &&
567 git-tag -n 2 -l tag-lines >actual &&
568 git diff expect actual &&
570 echo " tag line three" >>expect &&
571 git-tag -n 3 -l | grep "^ *tag.line" >actual &&
572 git diff expect actual &&
573 git-tag -n 3 -l tag-lines >actual &&
574 git diff expect actual &&
575 git-tag -n 4 -l | grep "^ *tag.line" >actual &&
576 git diff expect actual &&
577 git-tag -n 4 -l tag-lines >actual &&
578 git diff expect actual &&
579 git-tag -n 99 -l | grep "^ *tag.line" >actual &&
580 git diff expect actual &&
581 git-tag -n 99 -l tag-lines >actual &&
582 git diff expect actual
585 # trying to verify annotated non-signed tags:
587 test_expect_success \
588 'trying to verify an annotated non-signed tag should fail' '
589 tag_exists annotated-tag &&
590 ! git-tag -v annotated-tag
593 test_expect_success \
594 'trying to verify a file-annotated non-signed tag should fail' '
595 tag_exists file-annotated-tag &&
596 ! git-tag -v file-annotated-tag
599 test_expect_success \
600 'trying to verify two annotated non-signed tags should fail' '
601 tag_exists annotated-tag file-annotated-tag &&
602 ! git-tag -v annotated-tag file-annotated-tag
605 # creating and verifying signed tags:
607 gpg --version >/dev/null
608 if [ $? -eq 127 ]; then
609 echo "Skipping signed tags tests, because gpg was not found"
610 test_done
611 exit
614 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
615 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
616 # that version, creation of signed tags using the generated key fails.
617 case "$(gpg --version)" in
618 'gpg (GnuPG) 1.0.6'*)
619 echo "Skipping signed tag tests, because a bug in 1.0.6 version"
620 test_done
621 exit
623 esac
625 # key generation info: gpg --homedir t/t7004 --gen-key
626 # Type DSA and Elgamal, size 2048 bits, no expiration date.
627 # Name and email: C O Mitter <committer@example.com>
628 # No password given, to enable non-interactive operation.
630 cp -R ../t7004 ./gpghome
631 chmod 0700 gpghome
632 export 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 git diff 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 git diff expect actual
654 test_expect_success 'sign with an unknown id (1)' '
656 ! git tag -u author@example.com -m "Another message" o-signed-tag
660 test_expect_success 'sign with an unknown id (2)' '
662 ! git tag -u DEADBEEF -m "Another message" o-signed-tag
666 cat >fakeeditor <<'EOF'
667 #!/bin/sh
668 test -n "$1" && exec >"$1"
669 echo A signed tag message
670 echo from a fake editor.
672 chmod +x fakeeditor
674 get_tag_header implied-sign $commit commit $time >expect
675 ./fakeeditor >>expect
676 echo '-----BEGIN PGP SIGNATURE-----' >>expect
677 test_expect_success '-u implies signed tag' '
678 GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
679 get_tag_msg implied-sign >actual &&
680 git diff expect actual
683 cat >sigmsgfile <<EOF
684 Another signed tag
685 message in a file.
687 get_tag_header file-signed-tag $commit commit $time >expect
688 cat sigmsgfile >>expect
689 echo '-----BEGIN PGP SIGNATURE-----' >>expect
690 test_expect_success \
691 'creating a signed tag with -F messagefile should succeed' '
692 git-tag -s -F sigmsgfile file-signed-tag &&
693 get_tag_msg file-signed-tag >actual &&
694 git diff expect actual
697 cat >siginputmsg <<EOF
698 A signed tag message from
699 the standard input
701 get_tag_header stdin-signed-tag $commit commit $time >expect
702 cat siginputmsg >>expect
703 echo '-----BEGIN PGP SIGNATURE-----' >>expect
704 test_expect_success 'creating a signed tag with -F - should succeed' '
705 git-tag -s -F - stdin-signed-tag <siginputmsg &&
706 get_tag_msg stdin-signed-tag >actual &&
707 git diff expect actual
710 get_tag_header implied-annotate $commit commit $time >expect
711 ./fakeeditor >>expect
712 echo '-----BEGIN PGP SIGNATURE-----' >>expect
713 test_expect_success '-s implies annotated tag' '
714 GIT_EDITOR=./fakeeditor git-tag -s implied-annotate &&
715 get_tag_msg implied-annotate >actual &&
716 git diff expect actual
719 test_expect_success \
720 'trying to create a signed tag with non-existing -F file should fail' '
721 ! test -f nonexistingfile &&
722 ! tag_exists nosigtag &&
723 ! git-tag -s -F nonexistingfile nosigtag &&
724 ! tag_exists nosigtag
727 test_expect_success 'verifying a signed tag should succeed' \
728 'git-tag -v signed-tag'
730 test_expect_success 'verifying two signed tags in one command should succeed' \
731 'git-tag -v signed-tag file-signed-tag'
733 test_expect_success \
734 'verifying many signed and non-signed tags should fail' '
735 ! git-tag -v signed-tag annotated-tag &&
736 ! git-tag -v file-annotated-tag file-signed-tag &&
737 ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
738 ! git-tag -v signed-tag annotated-tag file-signed-tag
741 test_expect_success 'verifying a forged tag should fail' '
742 forged=$(git cat-file tag signed-tag |
743 sed -e "s/signed-tag/forged-tag/" |
744 git mktag) &&
745 git tag forged-tag $forged &&
746 ! git-tag -v forged-tag
749 # blank and empty messages for signed tags:
751 get_tag_header empty-signed-tag $commit commit $time >expect
752 echo '-----BEGIN PGP SIGNATURE-----' >>expect
753 test_expect_success \
754 'creating a signed tag with an empty -m message should succeed' '
755 git-tag -s -m "" empty-signed-tag &&
756 get_tag_msg empty-signed-tag >actual &&
757 git diff expect actual &&
758 git-tag -v empty-signed-tag
761 >sigemptyfile
762 get_tag_header emptyfile-signed-tag $commit commit $time >expect
763 echo '-----BEGIN PGP SIGNATURE-----' >>expect
764 test_expect_success \
765 'creating a signed tag with an empty -F messagefile should succeed' '
766 git-tag -s -F sigemptyfile emptyfile-signed-tag &&
767 get_tag_msg emptyfile-signed-tag >actual &&
768 git diff expect actual &&
769 git-tag -v emptyfile-signed-tag
772 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
773 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
774 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
775 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
776 get_tag_header blanks-signed-tag $commit commit $time >expect
777 cat >>expect <<EOF
778 Leading blank lines
780 Repeated blank lines
782 Trailing spaces
784 Trailing blank lines
786 echo '-----BEGIN PGP SIGNATURE-----' >>expect
787 test_expect_success \
788 'extra blanks in the message for a signed tag should be removed' '
789 git-tag -s -F sigblanksfile blanks-signed-tag &&
790 get_tag_msg blanks-signed-tag >actual &&
791 git diff expect actual &&
792 git-tag -v blanks-signed-tag
795 get_tag_header blank-signed-tag $commit commit $time >expect
796 echo '-----BEGIN PGP SIGNATURE-----' >>expect
797 test_expect_success \
798 'creating a signed tag with a blank -m message should succeed' '
799 git-tag -s -m " " blank-signed-tag &&
800 get_tag_msg blank-signed-tag >actual &&
801 git diff expect actual &&
802 git-tag -v blank-signed-tag
805 echo ' ' >sigblankfile
806 echo '' >>sigblankfile
807 echo ' ' >>sigblankfile
808 get_tag_header blankfile-signed-tag $commit commit $time >expect
809 echo '-----BEGIN PGP SIGNATURE-----' >>expect
810 test_expect_success \
811 'creating a signed tag with blank -F file with spaces should succeed' '
812 git-tag -s -F sigblankfile blankfile-signed-tag &&
813 get_tag_msg blankfile-signed-tag >actual &&
814 git diff expect actual &&
815 git-tag -v blankfile-signed-tag
818 printf ' ' >sigblanknonlfile
819 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
820 echo '-----BEGIN PGP SIGNATURE-----' >>expect
821 test_expect_success \
822 'creating a signed tag with spaces and no newline should succeed' '
823 git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
824 get_tag_msg blanknonlfile-signed-tag >actual &&
825 git diff expect actual &&
826 git-tag -v signed-tag
829 # messages with commented lines for signed tags:
831 cat >sigcommentsfile <<EOF
832 # A comment
834 ############
835 The message.
836 ############
837 One line.
840 # commented lines
841 # commented lines
843 Another line.
844 # comments
846 Last line.
848 get_tag_header comments-signed-tag $commit commit $time >expect
849 cat >>expect <<EOF
850 The message.
851 One line.
853 Another line.
855 Last line.
857 echo '-----BEGIN PGP SIGNATURE-----' >>expect
858 test_expect_success \
859 'creating a signed tag with a -F file with #comments should succeed' '
860 git-tag -s -F sigcommentsfile comments-signed-tag &&
861 get_tag_msg comments-signed-tag >actual &&
862 git diff expect actual &&
863 git-tag -v comments-signed-tag
866 get_tag_header comment-signed-tag $commit commit $time >expect
867 echo '-----BEGIN PGP SIGNATURE-----' >>expect
868 test_expect_success \
869 'creating a signed tag with #commented -m message should succeed' '
870 git-tag -s -m "#comment" comment-signed-tag &&
871 get_tag_msg comment-signed-tag >actual &&
872 git diff expect actual &&
873 git-tag -v comment-signed-tag
876 echo '#comment' >sigcommentfile
877 echo '' >>sigcommentfile
878 echo '####' >>sigcommentfile
879 get_tag_header commentfile-signed-tag $commit commit $time >expect
880 echo '-----BEGIN PGP SIGNATURE-----' >>expect
881 test_expect_success \
882 'creating a signed tag with #commented -F messagefile should succeed' '
883 git-tag -s -F sigcommentfile commentfile-signed-tag &&
884 get_tag_msg commentfile-signed-tag >actual &&
885 git diff expect actual &&
886 git-tag -v commentfile-signed-tag
889 printf '#comment' >sigcommentnonlfile
890 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
891 echo '-----BEGIN PGP SIGNATURE-----' >>expect
892 test_expect_success \
893 'creating a signed tag with a #comment and no newline should succeed' '
894 git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
895 get_tag_msg commentnonlfile-signed-tag >actual &&
896 git diff expect actual &&
897 git-tag -v commentnonlfile-signed-tag
900 # listing messages for signed tags:
902 test_expect_success \
903 'listing the one-line message of a signed tag should succeed' '
904 git-tag -s -m "A message line signed" stag-one-line &&
906 echo "stag-one-line" >expect &&
907 git-tag -l | grep "^stag-one-line" >actual &&
908 git diff expect actual &&
909 git-tag -n 0 -l | grep "^stag-one-line" >actual &&
910 git diff expect actual &&
911 git-tag -n 0 -l stag-one-line >actual &&
912 git diff expect actual &&
914 echo "stag-one-line A message line signed" >expect &&
915 git-tag -n xxx -l | grep "^stag-one-line" >actual &&
916 git diff expect actual &&
917 git-tag -n "" -l | grep "^stag-one-line" >actual &&
918 git diff expect actual &&
919 git-tag -n 1 -l | grep "^stag-one-line" >actual &&
920 git diff expect actual &&
921 git-tag -n -l | grep "^stag-one-line" >actual &&
922 git diff expect actual &&
923 git-tag -n 1 -l stag-one-line >actual &&
924 git diff expect actual &&
925 git-tag -n 2 -l stag-one-line >actual &&
926 git diff expect actual &&
927 git-tag -n 999 -l stag-one-line >actual &&
928 git diff expect actual
931 test_expect_success \
932 'listing the zero-lines message of a signed tag should succeed' '
933 git-tag -s -m "" stag-zero-lines &&
935 echo "stag-zero-lines" >expect &&
936 git-tag -l | grep "^stag-zero-lines" >actual &&
937 git diff expect actual &&
938 git-tag -n 0 -l | grep "^stag-zero-lines" >actual &&
939 git diff expect actual &&
940 git-tag -n 0 -l stag-zero-lines >actual &&
941 git diff expect actual &&
943 echo "stag-zero-lines " >expect &&
944 git-tag -n 1 -l | grep "^stag-zero-lines" >actual &&
945 git diff expect actual &&
946 git-tag -n -l | grep "^stag-zero-lines" >actual &&
947 git diff expect actual &&
948 git-tag -n 1 -l stag-zero-lines >actual &&
949 git diff expect actual &&
950 git-tag -n 2 -l stag-zero-lines >actual &&
951 git diff expect actual &&
952 git-tag -n 999 -l stag-zero-lines >actual &&
953 git diff expect actual
956 echo 'stag line one' >sigtagmsg
957 echo 'stag line two' >>sigtagmsg
958 echo 'stag line three' >>sigtagmsg
959 test_expect_success \
960 'listing many message lines of a signed tag should succeed' '
961 git-tag -s -F sigtagmsg stag-lines &&
963 echo "stag-lines" >expect &&
964 git-tag -l | grep "^stag-lines" >actual &&
965 git diff expect actual &&
966 git-tag -n 0 -l | grep "^stag-lines" >actual &&
967 git diff expect actual &&
968 git-tag -n 0 -l stag-lines >actual &&
969 git diff expect actual &&
971 echo "stag-lines stag line one" >expect &&
972 git-tag -n 1 -l | grep "^stag-lines" >actual &&
973 git diff expect actual &&
974 git-tag -n -l | grep "^stag-lines" >actual &&
975 git diff expect actual &&
976 git-tag -n 1 -l stag-lines >actual &&
977 git diff expect actual &&
979 echo " stag line two" >>expect &&
980 git-tag -n 2 -l | grep "^ *stag.line" >actual &&
981 git diff expect actual &&
982 git-tag -n 2 -l stag-lines >actual &&
983 git diff expect actual &&
985 echo " stag line three" >>expect &&
986 git-tag -n 3 -l | grep "^ *stag.line" >actual &&
987 git diff expect actual &&
988 git-tag -n 3 -l stag-lines >actual &&
989 git diff expect actual &&
990 git-tag -n 4 -l | grep "^ *stag.line" >actual &&
991 git diff expect actual &&
992 git-tag -n 4 -l stag-lines >actual &&
993 git diff expect actual &&
994 git-tag -n 99 -l | grep "^ *stag.line" >actual &&
995 git diff expect actual &&
996 git-tag -n 99 -l stag-lines >actual &&
997 git diff expect actual
1000 # tags pointing to objects different from commits:
1002 tree=$(git rev-parse HEAD^{tree})
1003 blob=$(git rev-parse HEAD:foo)
1004 tag=$(git rev-parse signed-tag)
1006 get_tag_header tree-signed-tag $tree tree $time >expect
1007 echo "A message for a tree" >>expect
1008 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1009 test_expect_success \
1010 'creating a signed tag pointing to a tree should succeed' '
1011 git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1012 get_tag_msg tree-signed-tag >actual &&
1013 git diff expect actual
1016 get_tag_header blob-signed-tag $blob blob $time >expect
1017 echo "A message for a blob" >>expect
1018 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1019 test_expect_success \
1020 'creating a signed tag pointing to a blob should succeed' '
1021 git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1022 get_tag_msg blob-signed-tag >actual &&
1023 git diff expect actual
1026 get_tag_header tag-signed-tag $tag tag $time >expect
1027 echo "A message for another tag" >>expect
1028 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1029 test_expect_success \
1030 'creating a signed tag pointing to another tag should succeed' '
1031 git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1032 get_tag_msg tag-signed-tag >actual &&
1033 git diff expect actual
1036 # try to sign with bad user.signingkey
1037 git config user.signingkey BobTheMouse
1038 test_expect_failure \
1039 'git-tag -s fails if gpg is misconfigured' \
1040 'git tag -s -m tail tag-gpg-failure'
1041 git config --unset user.signingkey
1043 # try to verify without gpg:
1045 rm -rf gpghome
1046 test_expect_failure \
1047 'verify signed tag fails when public key is not present' \
1048 'git-tag -v signed-tag'
1050 test_expect_failure \
1051 'git-tag -a fails if tag annotation is empty' '
1052 GIT_EDITOR=cat git tag -a initial-comment
1055 test_expect_success \
1056 'message in editor has initial comment' '
1057 GIT_EDITOR=cat git tag -a initial-comment > actual
1058 # check the first line --- should be empty
1059 first=$(sed -e 1q <actual) &&
1060 test -z "$first" &&
1061 # remove commented lines from the remainder -- should be empty
1062 rest=$(sed -e 1d -e '/^#/d' <actual) &&
1063 test -z "$rest"
1066 get_tag_header reuse $commit commit $time >expect
1067 echo "An annotation to be reused" >> expect
1068 test_expect_success \
1069 'overwriting an annoted tag should use its previous body' '
1070 git tag -a -m "An annotation to be reused" reuse &&
1071 GIT_EDITOR=true git tag -f -a reuse &&
1072 get_tag_msg reuse >actual &&
1073 git diff expect actual
1076 test_done