Round-down years in "years+months" relative date view
[git/dscho.git] / t / t7004-tag.sh
blob69501e2711f26a7c498d545520dcf47c00d9b1e1
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_success 'looking for a tag in an empty tree should fail' \
30 '! (tag_exists mytag)'
32 test_expect_success 'creating a tag in an empty tree should fail' '
33 test_must_fail git tag mynotag &&
34 ! tag_exists mynotag
37 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
38 test_must_fail git tag mytaghead HEAD &&
39 ! tag_exists mytaghead
42 test_expect_success 'creating a tag for an unknown revision should fail' '
43 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
44 ! tag_exists mytagnorev
47 # commit used in the tests, test_tick is also called here to freeze the date:
48 test_expect_success 'creating a tag using default HEAD should succeed' '
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_success \
87 'trying to create a tag with the name of one existing should fail' \
88 'test_must_fail 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 test_must_fail git tag "" &&
94 test_must_fail git tag .othertag &&
95 test_must_fail git tag "other tag" &&
96 test_must_fail git tag "othertag^" &&
97 test_must_fail git tag "other~tag" &&
98 test `git tag -l | wc -l` -eq 1
101 test_expect_success 'creating a tag using HEAD directly should succeed' '
102 git tag myhead HEAD &&
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 test_must_fail 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 && test_cmp expect actual &&
120 git tag -d &&
121 git tag -l > actual && test_cmp 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 test_must_fail git tag -d mytag anothertag &&
145 ! tag_exists mytag &&
146 ! tag_exists myhead
149 test_expect_success 'trying to delete an already deleted tag should fail' \
150 'test_must_fail git tag -d mytag'
152 # listing various tags with pattern matching:
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 test_cmp expect actual &&
177 git tag > actual &&
178 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp expect actual
259 # creating and verifying lightweight tags:
261 test_expect_success \
262 'a non-annotated tag created without parameters should point to HEAD' '
263 git tag non-annotated-tag &&
264 test $(git cat-file -t non-annotated-tag) = commit &&
265 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
268 test_expect_success 'trying to verify an unknown tag should fail' \
269 'test_must_fail git tag -v unknown-tag'
271 test_expect_success \
272 'trying to verify a non-annotated and non-signed tag should fail' \
273 'test_must_fail git tag -v non-annotated-tag'
275 test_expect_success \
276 'trying to verify many non-annotated or unknown tags, should fail' \
277 'test_must_fail 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 test_cmp 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 test_cmp 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 test_cmp 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 test_must_fail 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 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
347 ! tag_exists msgtag &&
348 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
349 ! tag_exists msgtag &&
350 test_must_fail git tag -m "message 1" -F msgfile1 \
351 -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 test_cmp 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 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
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 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
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 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
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 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"
586 test_done
587 exit
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 test_must_fail 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 test_must_fail 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 test_must_fail 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"
618 test_done
619 exit
621 esac
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 "$TEST_DIRECTORY"/t7004 ./gpghome
629 chmod 0700 gpghome
630 GNUPGHOME="$(pwd)/gpghome"
631 export GNUPGHOME
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 test_must_fail git tag -u author@example.com \
656 -m "Another message" o-signed-tag
660 test_expect_success 'sign with an unknown id (2)' '
662 test_must_fail 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_must_fail 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 test_must_fail git tag -v signed-tag annotated-tag &&
736 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
737 test_must_fail git tag -v annotated-tag \
738 file-signed-tag file-annotated-tag &&
739 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
742 test_expect_success 'verifying a forged tag should fail' '
743 forged=$(git cat-file tag signed-tag |
744 sed -e "s/signed-tag/forged-tag/" |
745 git mktag) &&
746 git tag forged-tag $forged &&
747 test_must_fail git tag -v forged-tag
750 # blank and empty messages for signed tags:
752 get_tag_header empty-signed-tag $commit commit $time >expect
753 echo '-----BEGIN PGP SIGNATURE-----' >>expect
754 test_expect_success \
755 'creating a signed tag with an empty -m message should succeed' '
756 git tag -s -m "" empty-signed-tag &&
757 get_tag_msg empty-signed-tag >actual &&
758 test_cmp expect actual &&
759 git tag -v empty-signed-tag
762 >sigemptyfile
763 get_tag_header emptyfile-signed-tag $commit commit $time >expect
764 echo '-----BEGIN PGP SIGNATURE-----' >>expect
765 test_expect_success \
766 'creating a signed tag with an empty -F messagefile should succeed' '
767 git tag -s -F sigemptyfile emptyfile-signed-tag &&
768 get_tag_msg emptyfile-signed-tag >actual &&
769 test_cmp expect actual &&
770 git tag -v emptyfile-signed-tag
773 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
774 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
775 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
776 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
777 get_tag_header blanks-signed-tag $commit commit $time >expect
778 cat >>expect <<EOF
779 Leading blank lines
781 Repeated blank lines
783 Trailing spaces
785 Trailing blank lines
787 echo '-----BEGIN PGP SIGNATURE-----' >>expect
788 test_expect_success \
789 'extra blanks in the message for a signed tag should be removed' '
790 git tag -s -F sigblanksfile blanks-signed-tag &&
791 get_tag_msg blanks-signed-tag >actual &&
792 test_cmp expect actual &&
793 git tag -v blanks-signed-tag
796 get_tag_header blank-signed-tag $commit commit $time >expect
797 echo '-----BEGIN PGP SIGNATURE-----' >>expect
798 test_expect_success \
799 'creating a signed tag with a blank -m message should succeed' '
800 git tag -s -m " " blank-signed-tag &&
801 get_tag_msg blank-signed-tag >actual &&
802 test_cmp expect actual &&
803 git tag -v blank-signed-tag
806 echo ' ' >sigblankfile
807 echo '' >>sigblankfile
808 echo ' ' >>sigblankfile
809 get_tag_header blankfile-signed-tag $commit commit $time >expect
810 echo '-----BEGIN PGP SIGNATURE-----' >>expect
811 test_expect_success \
812 'creating a signed tag with blank -F file with spaces should succeed' '
813 git tag -s -F sigblankfile blankfile-signed-tag &&
814 get_tag_msg blankfile-signed-tag >actual &&
815 test_cmp expect actual &&
816 git tag -v blankfile-signed-tag
819 printf ' ' >sigblanknonlfile
820 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
821 echo '-----BEGIN PGP SIGNATURE-----' >>expect
822 test_expect_success \
823 'creating a signed tag with spaces and no newline should succeed' '
824 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
825 get_tag_msg blanknonlfile-signed-tag >actual &&
826 test_cmp expect actual &&
827 git tag -v signed-tag
830 # messages with commented lines for signed tags:
832 cat >sigcommentsfile <<EOF
833 # A comment
835 ############
836 The message.
837 ############
838 One line.
841 # commented lines
842 # commented lines
844 Another line.
845 # comments
847 Last line.
849 get_tag_header comments-signed-tag $commit commit $time >expect
850 cat >>expect <<EOF
851 The message.
852 One line.
854 Another line.
856 Last line.
858 echo '-----BEGIN PGP SIGNATURE-----' >>expect
859 test_expect_success \
860 'creating a signed tag with a -F file with #comments should succeed' '
861 git tag -s -F sigcommentsfile comments-signed-tag &&
862 get_tag_msg comments-signed-tag >actual &&
863 test_cmp expect actual &&
864 git tag -v comments-signed-tag
867 get_tag_header comment-signed-tag $commit commit $time >expect
868 echo '-----BEGIN PGP SIGNATURE-----' >>expect
869 test_expect_success \
870 'creating a signed tag with #commented -m message should succeed' '
871 git tag -s -m "#comment" comment-signed-tag &&
872 get_tag_msg comment-signed-tag >actual &&
873 test_cmp expect actual &&
874 git tag -v comment-signed-tag
877 echo '#comment' >sigcommentfile
878 echo '' >>sigcommentfile
879 echo '####' >>sigcommentfile
880 get_tag_header commentfile-signed-tag $commit commit $time >expect
881 echo '-----BEGIN PGP SIGNATURE-----' >>expect
882 test_expect_success \
883 'creating a signed tag with #commented -F messagefile should succeed' '
884 git tag -s -F sigcommentfile commentfile-signed-tag &&
885 get_tag_msg commentfile-signed-tag >actual &&
886 test_cmp expect actual &&
887 git tag -v commentfile-signed-tag
890 printf '#comment' >sigcommentnonlfile
891 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
892 echo '-----BEGIN PGP SIGNATURE-----' >>expect
893 test_expect_success \
894 'creating a signed tag with a #comment and no newline should succeed' '
895 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
896 get_tag_msg commentnonlfile-signed-tag >actual &&
897 test_cmp expect actual &&
898 git tag -v commentnonlfile-signed-tag
901 # listing messages for signed tags:
903 test_expect_success \
904 'listing the one-line message of a signed tag should succeed' '
905 git tag -s -m "A message line signed" stag-one-line &&
907 echo "stag-one-line" >expect &&
908 git tag -l | grep "^stag-one-line" >actual &&
909 test_cmp expect actual &&
910 git tag -n0 -l | grep "^stag-one-line" >actual &&
911 test_cmp expect actual &&
912 git tag -n0 -l stag-one-line >actual &&
913 test_cmp expect actual &&
915 echo "stag-one-line A message line signed" >expect &&
916 git tag -n1 -l | grep "^stag-one-line" >actual &&
917 test_cmp expect actual &&
918 git tag -n -l | grep "^stag-one-line" >actual &&
919 test_cmp expect actual &&
920 git tag -n1 -l stag-one-line >actual &&
921 test_cmp expect actual &&
922 git tag -n2 -l stag-one-line >actual &&
923 test_cmp expect actual &&
924 git tag -n999 -l stag-one-line >actual &&
925 test_cmp expect actual
928 test_expect_success \
929 'listing the zero-lines message of a signed tag should succeed' '
930 git tag -s -m "" stag-zero-lines &&
932 echo "stag-zero-lines" >expect &&
933 git tag -l | grep "^stag-zero-lines" >actual &&
934 test_cmp expect actual &&
935 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
936 test_cmp expect actual &&
937 git tag -n0 -l stag-zero-lines >actual &&
938 test_cmp expect actual &&
940 echo "stag-zero-lines " >expect &&
941 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
942 test_cmp expect actual &&
943 git tag -n -l | grep "^stag-zero-lines" >actual &&
944 test_cmp expect actual &&
945 git tag -n1 -l stag-zero-lines >actual &&
946 test_cmp expect actual &&
947 git tag -n2 -l stag-zero-lines >actual &&
948 test_cmp expect actual &&
949 git tag -n999 -l stag-zero-lines >actual &&
950 test_cmp expect actual
953 echo 'stag line one' >sigtagmsg
954 echo 'stag line two' >>sigtagmsg
955 echo 'stag line three' >>sigtagmsg
956 test_expect_success \
957 'listing many message lines of a signed tag should succeed' '
958 git tag -s -F sigtagmsg stag-lines &&
960 echo "stag-lines" >expect &&
961 git tag -l | grep "^stag-lines" >actual &&
962 test_cmp expect actual &&
963 git tag -n0 -l | grep "^stag-lines" >actual &&
964 test_cmp expect actual &&
965 git tag -n0 -l stag-lines >actual &&
966 test_cmp expect actual &&
968 echo "stag-lines stag line one" >expect &&
969 git tag -n1 -l | grep "^stag-lines" >actual &&
970 test_cmp expect actual &&
971 git tag -n -l | grep "^stag-lines" >actual &&
972 test_cmp expect actual &&
973 git tag -n1 -l stag-lines >actual &&
974 test_cmp expect actual &&
976 echo " stag line two" >>expect &&
977 git tag -n2 -l | grep "^ *stag.line" >actual &&
978 test_cmp expect actual &&
979 git tag -n2 -l stag-lines >actual &&
980 test_cmp expect actual &&
982 echo " stag line three" >>expect &&
983 git tag -n3 -l | grep "^ *stag.line" >actual &&
984 test_cmp expect actual &&
985 git tag -n3 -l stag-lines >actual &&
986 test_cmp expect actual &&
987 git tag -n4 -l | grep "^ *stag.line" >actual &&
988 test_cmp expect actual &&
989 git tag -n4 -l stag-lines >actual &&
990 test_cmp expect actual &&
991 git tag -n99 -l | grep "^ *stag.line" >actual &&
992 test_cmp expect actual &&
993 git tag -n99 -l stag-lines >actual &&
994 test_cmp expect actual
997 # tags pointing to objects different from commits:
999 tree=$(git rev-parse HEAD^{tree})
1000 blob=$(git rev-parse HEAD:foo)
1001 tag=$(git rev-parse signed-tag)
1003 get_tag_header tree-signed-tag $tree tree $time >expect
1004 echo "A message for a tree" >>expect
1005 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1006 test_expect_success \
1007 'creating a signed tag pointing to a tree should succeed' '
1008 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1009 get_tag_msg tree-signed-tag >actual &&
1010 test_cmp expect actual
1013 get_tag_header blob-signed-tag $blob blob $time >expect
1014 echo "A message for a blob" >>expect
1015 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1016 test_expect_success \
1017 'creating a signed tag pointing to a blob should succeed' '
1018 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1019 get_tag_msg blob-signed-tag >actual &&
1020 test_cmp expect actual
1023 get_tag_header tag-signed-tag $tag tag $time >expect
1024 echo "A message for another tag" >>expect
1025 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1026 test_expect_success \
1027 'creating a signed tag pointing to another tag should succeed' '
1028 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1029 get_tag_msg tag-signed-tag >actual &&
1030 test_cmp expect actual
1033 # try to sign with bad user.signingkey
1034 git config user.signingkey BobTheMouse
1035 test_expect_success \
1036 'git tag -s fails if gpg is misconfigured' \
1037 'test_must_fail git tag -s -m tail tag-gpg-failure'
1038 git config --unset user.signingkey
1040 # try to verify without gpg:
1042 rm -rf gpghome
1043 test_expect_success \
1044 'verify signed tag fails when public key is not present' \
1045 'test_must_fail git tag -v signed-tag'
1047 test_expect_success \
1048 'git tag -a fails if tag annotation is empty' '
1049 ! (GIT_EDITOR=cat git tag -a initial-comment)
1052 test_expect_success \
1053 'message in editor has initial comment' '
1054 GIT_EDITOR=cat git tag -a initial-comment > actual
1055 # check the first line --- should be empty
1056 first=$(sed -e 1q <actual) &&
1057 test -z "$first" &&
1058 # remove commented lines from the remainder -- should be empty
1059 rest=$(sed -e 1d -e '/^#/d' <actual) &&
1060 test -z "$rest"
1063 get_tag_header reuse $commit commit $time >expect
1064 echo "An annotation to be reused" >> expect
1065 test_expect_success \
1066 'overwriting an annoted tag should use its previous body' '
1067 git tag -a -m "An annotation to be reused" reuse &&
1068 GIT_EDITOR=true git tag -f -a reuse &&
1069 get_tag_msg reuse >actual &&
1070 test_cmp expect actual
1073 test_expect_success 'filename for the message is relative to cwd' '
1074 mkdir subdir &&
1075 echo "Tag message in top directory" >msgfile-5 &&
1076 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1078 cd subdir &&
1079 git tag -a -F msgfile-5 tag-from-subdir
1080 ) &&
1081 git cat-file tag tag-from-subdir | grep "in sub directory"
1084 test_expect_success 'filename for the message is relative to cwd' '
1085 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1087 cd subdir &&
1088 git tag -a -F msgfile-6 tag-from-subdir-2
1089 ) &&
1090 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1093 # create a few more commits to test --contains
1095 hash1=$(git rev-parse HEAD)
1097 test_expect_success 'creating second commit and tag' '
1098 echo foo-2.0 >foo &&
1099 git add foo &&
1100 git commit -m second
1101 git tag v2.0
1104 hash2=$(git rev-parse HEAD)
1106 test_expect_success 'creating third commit without tag' '
1107 echo foo-dev >foo &&
1108 git add foo &&
1109 git commit -m third
1112 hash3=$(git rev-parse HEAD)
1114 # simple linear checks of --continue
1116 cat > expected <<EOF
1117 v0.2.1
1118 v1.0
1119 v1.0.1
1120 v1.1.3
1121 v2.0
1124 test_expect_success 'checking that first commit is in all tags (hash)' "
1125 git tag -l --contains $hash1 v* >actual
1126 test_cmp expected actual
1129 # other ways of specifying the commit
1130 test_expect_success 'checking that first commit is in all tags (tag)' "
1131 git tag -l --contains v1.0 v* >actual
1132 test_cmp expected actual
1135 test_expect_success 'checking that first commit is in all tags (relative)' "
1136 git tag -l --contains HEAD~2 v* >actual
1137 test_cmp expected actual
1140 cat > expected <<EOF
1141 v2.0
1144 test_expect_success 'checking that second commit only has one tag' "
1145 git tag -l --contains $hash2 v* >actual
1146 test_cmp expected actual
1150 cat > expected <<EOF
1153 test_expect_success 'checking that third commit has no tags' "
1154 git tag -l --contains $hash3 v* >actual
1155 test_cmp expected actual
1158 # how about a simple merge?
1160 test_expect_success 'creating simple branch' '
1161 git branch stable v2.0 &&
1162 git checkout stable &&
1163 echo foo-3.0 > foo &&
1164 git commit foo -m fourth
1165 git tag v3.0
1168 hash4=$(git rev-parse HEAD)
1170 cat > expected <<EOF
1171 v3.0
1174 test_expect_success 'checking that branch head only has one tag' "
1175 git tag -l --contains $hash4 v* >actual
1176 test_cmp expected actual
1179 test_expect_success 'merging original branch into this branch' '
1180 git merge --strategy=ours master &&
1181 git tag v4.0
1184 cat > expected <<EOF
1185 v4.0
1188 test_expect_success 'checking that original branch head has one tag now' "
1189 git tag -l --contains $hash3 v* >actual
1190 test_cmp expected actual
1193 cat > expected <<EOF
1194 v0.2.1
1195 v1.0
1196 v1.0.1
1197 v1.1.3
1198 v2.0
1199 v3.0
1200 v4.0
1203 test_expect_success 'checking that initial commit is in all tags' "
1204 git tag -l --contains $hash1 v* >actual
1205 test_cmp expected actual
1208 # mixing modes and options:
1210 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1211 test_must_fail git tag -a
1212 test_must_fail git tag -l -v
1213 test_must_fail git tag -n 100
1214 test_must_fail git tag -l -m msg
1215 test_must_fail git tag -l -F some file
1216 test_must_fail git tag -v -s
1219 test_done