log: respect date_mode_explicit with --format:%gd
[git/jrn.git] / t / t7004-tag.sh
blob097ce2bc8382e748925aa25c2dc0a1f06f6c7b4c
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 rm *a* &&
189 git tag -l "*a*" > current &&
190 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp 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 test_cmp expect actual
260 test_expect_success 'tag -l can accept multiple patterns' '
261 git tag -l "v1*" "v0*" >actual &&
262 test_cmp expect actual
265 # creating and verifying lightweight tags:
267 test_expect_success \
268 'a non-annotated tag created without parameters should point to HEAD' '
269 git tag non-annotated-tag &&
270 test $(git cat-file -t non-annotated-tag) = commit &&
271 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
274 test_expect_success 'trying to verify an unknown tag should fail' \
275 'test_must_fail git tag -v unknown-tag'
277 test_expect_success \
278 'trying to verify a non-annotated and non-signed tag should fail' \
279 'test_must_fail git tag -v non-annotated-tag'
281 test_expect_success \
282 'trying to verify many non-annotated or unknown tags, should fail' \
283 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
285 # creating annotated tags:
287 get_tag_msg () {
288 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
291 # run test_tick before committing always gives the time in that timezone
292 get_tag_header () {
293 cat <<EOF
294 object $2
295 type $3
296 tag $1
297 tagger C O Mitter <committer@example.com> $4 -0700
302 commit=$(git rev-parse HEAD)
303 time=$test_tick
305 get_tag_header annotated-tag $commit commit $time >expect
306 echo "A message" >>expect
307 test_expect_success \
308 'creating an annotated tag with -m message should succeed' '
309 git tag -m "A message" annotated-tag &&
310 get_tag_msg annotated-tag >actual &&
311 test_cmp expect actual
314 cat >msgfile <<EOF
315 Another message
316 in a file.
318 get_tag_header file-annotated-tag $commit commit $time >expect
319 cat msgfile >>expect
320 test_expect_success \
321 'creating an annotated tag with -F messagefile should succeed' '
322 git tag -F msgfile file-annotated-tag &&
323 get_tag_msg file-annotated-tag >actual &&
324 test_cmp expect actual
327 cat >inputmsg <<EOF
328 A message from the
329 standard input
331 get_tag_header stdin-annotated-tag $commit commit $time >expect
332 cat inputmsg >>expect
333 test_expect_success 'creating an annotated tag with -F - should succeed' '
334 git tag -F - stdin-annotated-tag <inputmsg &&
335 get_tag_msg stdin-annotated-tag >actual &&
336 test_cmp expect actual
339 test_expect_success \
340 'trying to create a tag with a non-existing -F file should fail' '
341 ! test -f nonexistingfile &&
342 ! tag_exists notag &&
343 test_must_fail git tag -F nonexistingfile notag &&
344 ! tag_exists notag
347 test_expect_success \
348 'trying to create tags giving both -m or -F options should fail' '
349 echo "message file 1" >msgfile1 &&
350 echo "message file 2" >msgfile2 &&
351 ! tag_exists msgtag &&
352 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
353 ! tag_exists msgtag &&
354 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
355 ! tag_exists msgtag &&
356 test_must_fail git tag -m "message 1" -F msgfile1 \
357 -m "message 2" msgtag &&
358 ! tag_exists msgtag
361 # blank and empty messages:
363 get_tag_header empty-annotated-tag $commit commit $time >expect
364 test_expect_success \
365 'creating a tag with an empty -m message should succeed' '
366 git tag -m "" empty-annotated-tag &&
367 get_tag_msg empty-annotated-tag >actual &&
368 test_cmp expect actual
371 >emptyfile
372 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
373 test_expect_success \
374 'creating a tag with an empty -F messagefile should succeed' '
375 git tag -F emptyfile emptyfile-annotated-tag &&
376 get_tag_msg emptyfile-annotated-tag >actual &&
377 test_cmp expect actual
380 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
381 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
382 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
383 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
384 get_tag_header blanks-annotated-tag $commit commit $time >expect
385 cat >>expect <<EOF
386 Leading blank lines
388 Repeated blank lines
390 Trailing spaces
392 Trailing blank lines
394 test_expect_success \
395 'extra blanks in the message for an annotated tag should be removed' '
396 git tag -F blanksfile blanks-annotated-tag &&
397 get_tag_msg blanks-annotated-tag >actual &&
398 test_cmp expect actual
401 get_tag_header blank-annotated-tag $commit commit $time >expect
402 test_expect_success \
403 'creating a tag with blank -m message with spaces should succeed' '
404 git tag -m " " blank-annotated-tag &&
405 get_tag_msg blank-annotated-tag >actual &&
406 test_cmp expect actual
409 echo ' ' >blankfile
410 echo '' >>blankfile
411 echo ' ' >>blankfile
412 get_tag_header blankfile-annotated-tag $commit commit $time >expect
413 test_expect_success \
414 'creating a tag with blank -F messagefile with spaces should succeed' '
415 git tag -F blankfile blankfile-annotated-tag &&
416 get_tag_msg blankfile-annotated-tag >actual &&
417 test_cmp expect actual
420 printf ' ' >blanknonlfile
421 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
422 test_expect_success \
423 'creating a tag with -F file of spaces and no newline should succeed' '
424 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
425 get_tag_msg blanknonlfile-annotated-tag >actual &&
426 test_cmp expect actual
429 # messages with commented lines:
431 cat >commentsfile <<EOF
432 # A comment
434 ############
435 The message.
436 ############
437 One line.
440 # commented lines
441 # commented lines
443 Another line.
444 # comments
446 Last line.
448 get_tag_header comments-annotated-tag $commit commit $time >expect
449 cat >>expect <<EOF
450 The message.
451 One line.
453 Another line.
455 Last line.
457 test_expect_success \
458 'creating a tag using a -F messagefile with #comments should succeed' '
459 git tag -F commentsfile comments-annotated-tag &&
460 get_tag_msg comments-annotated-tag >actual &&
461 test_cmp expect actual
464 get_tag_header comment-annotated-tag $commit commit $time >expect
465 test_expect_success \
466 'creating a tag with a #comment in the -m message should succeed' '
467 git tag -m "#comment" comment-annotated-tag &&
468 get_tag_msg comment-annotated-tag >actual &&
469 test_cmp expect actual
472 echo '#comment' >commentfile
473 echo '' >>commentfile
474 echo '####' >>commentfile
475 get_tag_header commentfile-annotated-tag $commit commit $time >expect
476 test_expect_success \
477 'creating a tag with #comments in the -F messagefile should succeed' '
478 git tag -F commentfile commentfile-annotated-tag &&
479 get_tag_msg commentfile-annotated-tag >actual &&
480 test_cmp expect actual
483 printf '#comment' >commentnonlfile
484 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
485 test_expect_success \
486 'creating a tag with a file of #comment and no newline should succeed' '
487 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
488 get_tag_msg commentnonlfile-annotated-tag >actual &&
489 test_cmp expect actual
492 # listing messages for annotated non-signed tags:
494 test_expect_success \
495 'listing the one-line message of a non-signed tag should succeed' '
496 git tag -m "A msg" tag-one-line &&
498 echo "tag-one-line" >expect &&
499 git tag -l | grep "^tag-one-line" >actual &&
500 test_cmp expect actual &&
501 git tag -n0 -l | grep "^tag-one-line" >actual &&
502 test_cmp expect actual &&
503 git tag -n0 -l tag-one-line >actual &&
504 test_cmp expect actual &&
506 echo "tag-one-line A msg" >expect &&
507 git tag -n1 -l | grep "^tag-one-line" >actual &&
508 test_cmp expect actual &&
509 git tag -n -l | grep "^tag-one-line" >actual &&
510 test_cmp expect actual &&
511 git tag -n1 -l tag-one-line >actual &&
512 test_cmp expect actual &&
513 git tag -n2 -l tag-one-line >actual &&
514 test_cmp expect actual &&
515 git tag -n999 -l tag-one-line >actual &&
516 test_cmp expect actual
519 test_expect_success \
520 'listing the zero-lines message of a non-signed tag should succeed' '
521 git tag -m "" tag-zero-lines &&
523 echo "tag-zero-lines" >expect &&
524 git tag -l | grep "^tag-zero-lines" >actual &&
525 test_cmp expect actual &&
526 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
527 test_cmp expect actual &&
528 git tag -n0 -l tag-zero-lines >actual &&
529 test_cmp expect actual &&
531 echo "tag-zero-lines " >expect &&
532 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
533 test_cmp expect actual &&
534 git tag -n -l | grep "^tag-zero-lines" >actual &&
535 test_cmp expect actual &&
536 git tag -n1 -l tag-zero-lines >actual &&
537 test_cmp expect actual &&
538 git tag -n2 -l tag-zero-lines >actual &&
539 test_cmp expect actual &&
540 git tag -n999 -l tag-zero-lines >actual &&
541 test_cmp expect actual
544 echo 'tag line one' >annotagmsg
545 echo 'tag line two' >>annotagmsg
546 echo 'tag line three' >>annotagmsg
547 test_expect_success \
548 'listing many message lines of a non-signed tag should succeed' '
549 git tag -F annotagmsg tag-lines &&
551 echo "tag-lines" >expect &&
552 git tag -l | grep "^tag-lines" >actual &&
553 test_cmp expect actual &&
554 git tag -n0 -l | grep "^tag-lines" >actual &&
555 test_cmp expect actual &&
556 git tag -n0 -l tag-lines >actual &&
557 test_cmp expect actual &&
559 echo "tag-lines tag line one" >expect &&
560 git tag -n1 -l | grep "^tag-lines" >actual &&
561 test_cmp expect actual &&
562 git tag -n -l | grep "^tag-lines" >actual &&
563 test_cmp expect actual &&
564 git tag -n1 -l tag-lines >actual &&
565 test_cmp expect actual &&
567 echo " tag line two" >>expect &&
568 git tag -n2 -l | grep "^ *tag.line" >actual &&
569 test_cmp expect actual &&
570 git tag -n2 -l tag-lines >actual &&
571 test_cmp expect actual &&
573 echo " tag line three" >>expect &&
574 git tag -n3 -l | grep "^ *tag.line" >actual &&
575 test_cmp expect actual &&
576 git tag -n3 -l tag-lines >actual &&
577 test_cmp expect actual &&
578 git tag -n4 -l | grep "^ *tag.line" >actual &&
579 test_cmp expect actual &&
580 git tag -n4 -l tag-lines >actual &&
581 test_cmp expect actual &&
582 git tag -n99 -l | grep "^ *tag.line" >actual &&
583 test_cmp expect actual &&
584 git tag -n99 -l tag-lines >actual &&
585 test_cmp expect actual
588 # subsequent tests require gpg; check if it is available
589 gpg --version >/dev/null 2>/dev/null
590 if [ $? -eq 127 ]; then
591 say "# gpg not found - skipping tag signing and verification tests"
592 else
593 # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
594 # the gpg version 1.0.6 didn't parse trust packets correctly, so for
595 # that version, creation of signed tags using the generated key fails.
596 case "$(gpg --version)" in
597 'gpg (GnuPG) 1.0.6'*)
598 say "Skipping signed tag tests, because a bug in 1.0.6 version"
601 test_set_prereq GPG
603 esac
606 # trying to verify annotated non-signed tags:
608 test_expect_success GPG \
609 'trying to verify an annotated non-signed tag should fail' '
610 tag_exists annotated-tag &&
611 test_must_fail git tag -v annotated-tag
614 test_expect_success GPG \
615 'trying to verify a file-annotated non-signed tag should fail' '
616 tag_exists file-annotated-tag &&
617 test_must_fail git tag -v file-annotated-tag
620 test_expect_success GPG \
621 'trying to verify two annotated non-signed tags should fail' '
622 tag_exists annotated-tag file-annotated-tag &&
623 test_must_fail git tag -v annotated-tag file-annotated-tag
626 # creating and verifying signed tags:
628 # key generation info: gpg --homedir t/t7004 --gen-key
629 # Type DSA and Elgamal, size 2048 bits, no expiration date.
630 # Name and email: C O Mitter <committer@example.com>
631 # No password given, to enable non-interactive operation.
633 cp -R "$TEST_DIRECTORY"/t7004 ./gpghome
634 chmod 0700 gpghome
635 GNUPGHOME="$(pwd)/gpghome"
636 export GNUPGHOME
638 get_tag_header signed-tag $commit commit $time >expect
639 echo 'A signed tag message' >>expect
640 echo '-----BEGIN PGP SIGNATURE-----' >>expect
641 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
642 git tag -s -m "A signed tag message" signed-tag &&
643 get_tag_msg signed-tag >actual &&
644 test_cmp expect actual
647 get_tag_header u-signed-tag $commit commit $time >expect
648 echo 'Another message' >>expect
649 echo '-----BEGIN PGP SIGNATURE-----' >>expect
650 test_expect_success GPG 'sign with a given key id' '
652 git tag -u committer@example.com -m "Another message" u-signed-tag &&
653 get_tag_msg u-signed-tag >actual &&
654 test_cmp expect actual
658 test_expect_success GPG 'sign with an unknown id (1)' '
660 test_must_fail git tag -u author@example.com \
661 -m "Another message" o-signed-tag
665 test_expect_success GPG 'sign with an unknown id (2)' '
667 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
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
679 get_tag_header implied-sign $commit commit $time >expect
680 ./fakeeditor >>expect
681 echo '-----BEGIN PGP SIGNATURE-----' >>expect
682 test_expect_success GPG '-u implies signed tag' '
683 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
684 get_tag_msg implied-sign >actual &&
685 test_cmp expect actual
688 cat >sigmsgfile <<EOF
689 Another signed tag
690 message in a file.
692 get_tag_header file-signed-tag $commit commit $time >expect
693 cat sigmsgfile >>expect
694 echo '-----BEGIN PGP SIGNATURE-----' >>expect
695 test_expect_success GPG \
696 'creating a signed tag with -F messagefile should succeed' '
697 git tag -s -F sigmsgfile file-signed-tag &&
698 get_tag_msg file-signed-tag >actual &&
699 test_cmp expect actual
702 cat >siginputmsg <<EOF
703 A signed tag message from
704 the standard input
706 get_tag_header stdin-signed-tag $commit commit $time >expect
707 cat siginputmsg >>expect
708 echo '-----BEGIN PGP SIGNATURE-----' >>expect
709 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
710 git tag -s -F - stdin-signed-tag <siginputmsg &&
711 get_tag_msg stdin-signed-tag >actual &&
712 test_cmp expect actual
715 get_tag_header implied-annotate $commit commit $time >expect
716 ./fakeeditor >>expect
717 echo '-----BEGIN PGP SIGNATURE-----' >>expect
718 test_expect_success GPG '-s implies annotated tag' '
719 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
720 get_tag_msg implied-annotate >actual &&
721 test_cmp expect actual
724 test_expect_success GPG \
725 'trying to create a signed tag with non-existing -F file should fail' '
726 ! test -f nonexistingfile &&
727 ! tag_exists nosigtag &&
728 test_must_fail git tag -s -F nonexistingfile nosigtag &&
729 ! tag_exists nosigtag
732 test_expect_success GPG 'verifying a signed tag should succeed' \
733 'git tag -v signed-tag'
735 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
736 'git tag -v signed-tag file-signed-tag'
738 test_expect_success GPG \
739 'verifying many signed and non-signed tags should fail' '
740 test_must_fail git tag -v signed-tag annotated-tag &&
741 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
742 test_must_fail git tag -v annotated-tag \
743 file-signed-tag file-annotated-tag &&
744 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
747 test_expect_success GPG 'verifying a forged tag should fail' '
748 forged=$(git cat-file tag signed-tag |
749 sed -e "s/signed-tag/forged-tag/" |
750 git mktag) &&
751 git tag forged-tag $forged &&
752 test_must_fail git tag -v forged-tag
755 # blank and empty messages for signed tags:
757 get_tag_header empty-signed-tag $commit commit $time >expect
758 echo '-----BEGIN PGP SIGNATURE-----' >>expect
759 test_expect_success GPG \
760 'creating a signed tag with an empty -m message should succeed' '
761 git tag -s -m "" empty-signed-tag &&
762 get_tag_msg empty-signed-tag >actual &&
763 test_cmp expect actual &&
764 git tag -v empty-signed-tag
767 >sigemptyfile
768 get_tag_header emptyfile-signed-tag $commit commit $time >expect
769 echo '-----BEGIN PGP SIGNATURE-----' >>expect
770 test_expect_success GPG \
771 'creating a signed tag with an empty -F messagefile should succeed' '
772 git tag -s -F sigemptyfile emptyfile-signed-tag &&
773 get_tag_msg emptyfile-signed-tag >actual &&
774 test_cmp expect actual &&
775 git tag -v emptyfile-signed-tag
778 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
779 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
780 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
781 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
782 get_tag_header blanks-signed-tag $commit commit $time >expect
783 cat >>expect <<EOF
784 Leading blank lines
786 Repeated blank lines
788 Trailing spaces
790 Trailing blank lines
792 echo '-----BEGIN PGP SIGNATURE-----' >>expect
793 test_expect_success GPG \
794 'extra blanks in the message for a signed tag should be removed' '
795 git tag -s -F sigblanksfile blanks-signed-tag &&
796 get_tag_msg blanks-signed-tag >actual &&
797 test_cmp expect actual &&
798 git tag -v blanks-signed-tag
801 get_tag_header blank-signed-tag $commit commit $time >expect
802 echo '-----BEGIN PGP SIGNATURE-----' >>expect
803 test_expect_success GPG \
804 'creating a signed tag with a blank -m message should succeed' '
805 git tag -s -m " " blank-signed-tag &&
806 get_tag_msg blank-signed-tag >actual &&
807 test_cmp expect actual &&
808 git tag -v blank-signed-tag
811 echo ' ' >sigblankfile
812 echo '' >>sigblankfile
813 echo ' ' >>sigblankfile
814 get_tag_header blankfile-signed-tag $commit commit $time >expect
815 echo '-----BEGIN PGP SIGNATURE-----' >>expect
816 test_expect_success GPG \
817 'creating a signed tag with blank -F file with spaces should succeed' '
818 git tag -s -F sigblankfile blankfile-signed-tag &&
819 get_tag_msg blankfile-signed-tag >actual &&
820 test_cmp expect actual &&
821 git tag -v blankfile-signed-tag
824 printf ' ' >sigblanknonlfile
825 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
826 echo '-----BEGIN PGP SIGNATURE-----' >>expect
827 test_expect_success GPG \
828 'creating a signed tag with spaces and no newline should succeed' '
829 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
830 get_tag_msg blanknonlfile-signed-tag >actual &&
831 test_cmp expect actual &&
832 git tag -v signed-tag
835 # messages with commented lines for signed tags:
837 cat >sigcommentsfile <<EOF
838 # A comment
840 ############
841 The message.
842 ############
843 One line.
846 # commented lines
847 # commented lines
849 Another line.
850 # comments
852 Last line.
854 get_tag_header comments-signed-tag $commit commit $time >expect
855 cat >>expect <<EOF
856 The message.
857 One line.
859 Another line.
861 Last line.
863 echo '-----BEGIN PGP SIGNATURE-----' >>expect
864 test_expect_success GPG \
865 'creating a signed tag with a -F file with #comments should succeed' '
866 git tag -s -F sigcommentsfile comments-signed-tag &&
867 get_tag_msg comments-signed-tag >actual &&
868 test_cmp expect actual &&
869 git tag -v comments-signed-tag
872 get_tag_header comment-signed-tag $commit commit $time >expect
873 echo '-----BEGIN PGP SIGNATURE-----' >>expect
874 test_expect_success GPG \
875 'creating a signed tag with #commented -m message should succeed' '
876 git tag -s -m "#comment" comment-signed-tag &&
877 get_tag_msg comment-signed-tag >actual &&
878 test_cmp expect actual &&
879 git tag -v comment-signed-tag
882 echo '#comment' >sigcommentfile
883 echo '' >>sigcommentfile
884 echo '####' >>sigcommentfile
885 get_tag_header commentfile-signed-tag $commit commit $time >expect
886 echo '-----BEGIN PGP SIGNATURE-----' >>expect
887 test_expect_success GPG \
888 'creating a signed tag with #commented -F messagefile should succeed' '
889 git tag -s -F sigcommentfile commentfile-signed-tag &&
890 get_tag_msg commentfile-signed-tag >actual &&
891 test_cmp expect actual &&
892 git tag -v commentfile-signed-tag
895 printf '#comment' >sigcommentnonlfile
896 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
897 echo '-----BEGIN PGP SIGNATURE-----' >>expect
898 test_expect_success GPG \
899 'creating a signed tag with a #comment and no newline should succeed' '
900 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
901 get_tag_msg commentnonlfile-signed-tag >actual &&
902 test_cmp expect actual &&
903 git tag -v commentnonlfile-signed-tag
906 # listing messages for signed tags:
908 test_expect_success GPG \
909 'listing the one-line message of a signed tag should succeed' '
910 git tag -s -m "A message line signed" stag-one-line &&
912 echo "stag-one-line" >expect &&
913 git tag -l | grep "^stag-one-line" >actual &&
914 test_cmp expect actual &&
915 git tag -n0 -l | grep "^stag-one-line" >actual &&
916 test_cmp expect actual &&
917 git tag -n0 -l stag-one-line >actual &&
918 test_cmp expect actual &&
920 echo "stag-one-line A message line signed" >expect &&
921 git tag -n1 -l | grep "^stag-one-line" >actual &&
922 test_cmp expect actual &&
923 git tag -n -l | grep "^stag-one-line" >actual &&
924 test_cmp expect actual &&
925 git tag -n1 -l stag-one-line >actual &&
926 test_cmp expect actual &&
927 git tag -n2 -l stag-one-line >actual &&
928 test_cmp expect actual &&
929 git tag -n999 -l stag-one-line >actual &&
930 test_cmp expect actual
933 test_expect_success GPG \
934 'listing the zero-lines message of a signed tag should succeed' '
935 git tag -s -m "" stag-zero-lines &&
937 echo "stag-zero-lines" >expect &&
938 git tag -l | grep "^stag-zero-lines" >actual &&
939 test_cmp expect actual &&
940 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
941 test_cmp expect actual &&
942 git tag -n0 -l stag-zero-lines >actual &&
943 test_cmp expect actual &&
945 echo "stag-zero-lines " >expect &&
946 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
947 test_cmp expect actual &&
948 git tag -n -l | grep "^stag-zero-lines" >actual &&
949 test_cmp expect actual &&
950 git tag -n1 -l stag-zero-lines >actual &&
951 test_cmp expect actual &&
952 git tag -n2 -l stag-zero-lines >actual &&
953 test_cmp expect actual &&
954 git tag -n999 -l stag-zero-lines >actual &&
955 test_cmp expect actual
958 echo 'stag line one' >sigtagmsg
959 echo 'stag line two' >>sigtagmsg
960 echo 'stag line three' >>sigtagmsg
961 test_expect_success GPG \
962 'listing many message lines of a signed tag should succeed' '
963 git tag -s -F sigtagmsg stag-lines &&
965 echo "stag-lines" >expect &&
966 git tag -l | grep "^stag-lines" >actual &&
967 test_cmp expect actual &&
968 git tag -n0 -l | grep "^stag-lines" >actual &&
969 test_cmp expect actual &&
970 git tag -n0 -l stag-lines >actual &&
971 test_cmp expect actual &&
973 echo "stag-lines stag line one" >expect &&
974 git tag -n1 -l | grep "^stag-lines" >actual &&
975 test_cmp expect actual &&
976 git tag -n -l | grep "^stag-lines" >actual &&
977 test_cmp expect actual &&
978 git tag -n1 -l stag-lines >actual &&
979 test_cmp expect actual &&
981 echo " stag line two" >>expect &&
982 git tag -n2 -l | grep "^ *stag.line" >actual &&
983 test_cmp expect actual &&
984 git tag -n2 -l stag-lines >actual &&
985 test_cmp expect actual &&
987 echo " stag line three" >>expect &&
988 git tag -n3 -l | grep "^ *stag.line" >actual &&
989 test_cmp expect actual &&
990 git tag -n3 -l stag-lines >actual &&
991 test_cmp expect actual &&
992 git tag -n4 -l | grep "^ *stag.line" >actual &&
993 test_cmp expect actual &&
994 git tag -n4 -l stag-lines >actual &&
995 test_cmp expect actual &&
996 git tag -n99 -l | grep "^ *stag.line" >actual &&
997 test_cmp expect actual &&
998 git tag -n99 -l stag-lines >actual &&
999 test_cmp expect actual
1002 # tags pointing to objects different from commits:
1004 tree=$(git rev-parse HEAD^{tree})
1005 blob=$(git rev-parse HEAD:foo)
1006 tag=$(git rev-parse signed-tag 2>/dev/null)
1008 get_tag_header tree-signed-tag $tree tree $time >expect
1009 echo "A message for a tree" >>expect
1010 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1011 test_expect_success GPG \
1012 'creating a signed tag pointing to a tree should succeed' '
1013 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1014 get_tag_msg tree-signed-tag >actual &&
1015 test_cmp expect actual
1018 get_tag_header blob-signed-tag $blob blob $time >expect
1019 echo "A message for a blob" >>expect
1020 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1021 test_expect_success GPG \
1022 'creating a signed tag pointing to a blob should succeed' '
1023 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1024 get_tag_msg blob-signed-tag >actual &&
1025 test_cmp expect actual
1028 get_tag_header tag-signed-tag $tag tag $time >expect
1029 echo "A message for another tag" >>expect
1030 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1031 test_expect_success GPG \
1032 'creating a signed tag pointing to another tag should succeed' '
1033 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1034 get_tag_msg tag-signed-tag >actual &&
1035 test_cmp expect actual
1038 # usage with rfc1991 signatures
1039 echo "rfc1991" > gpghome/gpg.conf
1040 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1041 echo "RFC1991 signed tag" >>expect
1042 echo '-----BEGIN PGP MESSAGE-----' >>expect
1043 test_expect_success GPG \
1044 'creating a signed tag with rfc1991' '
1045 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1046 get_tag_msg rfc1991-signed-tag >actual &&
1047 test_cmp expect actual
1050 cat >fakeeditor <<'EOF'
1051 #!/bin/sh
1052 cp "$1" actual
1054 chmod +x fakeeditor
1056 test_expect_success GPG \
1057 'reediting a signed tag body omits signature' '
1058 echo "RFC1991 signed tag" >expect &&
1059 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1060 test_cmp expect actual
1063 test_expect_success GPG \
1064 'verifying rfc1991 signature' '
1065 git tag -v rfc1991-signed-tag
1068 test_expect_success GPG \
1069 'list tag with rfc1991 signature' '
1070 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1071 git tag -l -n1 rfc1991-signed-tag >actual &&
1072 test_cmp expect actual &&
1073 git tag -l -n2 rfc1991-signed-tag >actual &&
1074 test_cmp expect actual &&
1075 git tag -l -n999 rfc1991-signed-tag >actual &&
1076 test_cmp expect actual
1079 rm -f gpghome/gpg.conf
1081 test_expect_success GPG \
1082 'verifying rfc1991 signature without --rfc1991' '
1083 git tag -v rfc1991-signed-tag
1086 test_expect_success GPG \
1087 'list tag with rfc1991 signature without --rfc1991' '
1088 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1089 git tag -l -n1 rfc1991-signed-tag >actual &&
1090 test_cmp expect actual &&
1091 git tag -l -n2 rfc1991-signed-tag >actual &&
1092 test_cmp expect actual &&
1093 git tag -l -n999 rfc1991-signed-tag >actual &&
1094 test_cmp expect actual
1097 test_expect_success GPG \
1098 'reediting a signed tag body omits signature' '
1099 echo "RFC1991 signed tag" >expect &&
1100 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1101 test_cmp expect actual
1104 # try to sign with bad user.signingkey
1105 git config user.signingkey BobTheMouse
1106 test_expect_success GPG \
1107 'git tag -s fails if gpg is misconfigured' \
1108 'test_must_fail git tag -s -m tail tag-gpg-failure'
1109 git config --unset user.signingkey
1111 # try to verify without gpg:
1113 rm -rf gpghome
1114 test_expect_success GPG \
1115 'verify signed tag fails when public key is not present' \
1116 'test_must_fail git tag -v signed-tag'
1118 test_expect_success \
1119 'git tag -a fails if tag annotation is empty' '
1120 ! (GIT_EDITOR=cat git tag -a initial-comment)
1123 test_expect_success \
1124 'message in editor has initial comment' '
1125 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1128 test_expect_success 'message in editor has initial comment: first line' '
1129 # check the first line --- should be empty
1130 echo >first.expect &&
1131 sed -e 1q <actual >first.actual &&
1132 test_i18ncmp first.expect first.actual
1135 test_expect_success \
1136 'message in editor has initial comment: remainder' '
1137 # remove commented lines from the remainder -- should be empty
1138 >rest.expect
1139 sed -e 1d -e '/^#/d' <actual >rest.actual &&
1140 test_cmp rest.expect rest.actual
1143 get_tag_header reuse $commit commit $time >expect
1144 echo "An annotation to be reused" >> expect
1145 test_expect_success \
1146 'overwriting an annoted tag should use its previous body' '
1147 git tag -a -m "An annotation to be reused" reuse &&
1148 GIT_EDITOR=true git tag -f -a reuse &&
1149 get_tag_msg reuse >actual &&
1150 test_cmp expect actual
1153 test_expect_success 'filename for the message is relative to cwd' '
1154 mkdir subdir &&
1155 echo "Tag message in top directory" >msgfile-5 &&
1156 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1158 cd subdir &&
1159 git tag -a -F msgfile-5 tag-from-subdir
1160 ) &&
1161 git cat-file tag tag-from-subdir | grep "in sub directory"
1164 test_expect_success 'filename for the message is relative to cwd' '
1165 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1167 cd subdir &&
1168 git tag -a -F msgfile-6 tag-from-subdir-2
1169 ) &&
1170 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1173 # create a few more commits to test --contains
1175 hash1=$(git rev-parse HEAD)
1177 test_expect_success 'creating second commit and tag' '
1178 echo foo-2.0 >foo &&
1179 git add foo &&
1180 git commit -m second &&
1181 git tag v2.0
1184 hash2=$(git rev-parse HEAD)
1186 test_expect_success 'creating third commit without tag' '
1187 echo foo-dev >foo &&
1188 git add foo &&
1189 git commit -m third
1192 hash3=$(git rev-parse HEAD)
1194 # simple linear checks of --continue
1196 cat > expected <<EOF
1197 v0.2.1
1198 v1.0
1199 v1.0.1
1200 v1.1.3
1201 v2.0
1204 test_expect_success 'checking that first commit is in all tags (hash)' "
1205 git tag -l --contains $hash1 v* >actual &&
1206 test_cmp expected actual
1209 # other ways of specifying the commit
1210 test_expect_success 'checking that first commit is in all tags (tag)' "
1211 git tag -l --contains v1.0 v* >actual &&
1212 test_cmp expected actual
1215 test_expect_success 'checking that first commit is in all tags (relative)' "
1216 git tag -l --contains HEAD~2 v* >actual &&
1217 test_cmp expected actual
1220 cat > expected <<EOF
1221 v2.0
1224 test_expect_success 'checking that second commit only has one tag' "
1225 git tag -l --contains $hash2 v* >actual &&
1226 test_cmp expected actual
1230 cat > expected <<EOF
1233 test_expect_success 'checking that third commit has no tags' "
1234 git tag -l --contains $hash3 v* >actual &&
1235 test_cmp expected actual
1238 # how about a simple merge?
1240 test_expect_success 'creating simple branch' '
1241 git branch stable v2.0 &&
1242 git checkout stable &&
1243 echo foo-3.0 > foo &&
1244 git commit foo -m fourth &&
1245 git tag v3.0
1248 hash4=$(git rev-parse HEAD)
1250 cat > expected <<EOF
1251 v3.0
1254 test_expect_success 'checking that branch head only has one tag' "
1255 git tag -l --contains $hash4 v* >actual &&
1256 test_cmp expected actual
1259 test_expect_success 'merging original branch into this branch' '
1260 git merge --strategy=ours master &&
1261 git tag v4.0
1264 cat > expected <<EOF
1265 v4.0
1268 test_expect_success 'checking that original branch head has one tag now' "
1269 git tag -l --contains $hash3 v* >actual &&
1270 test_cmp expected actual
1273 cat > expected <<EOF
1274 v0.2.1
1275 v1.0
1276 v1.0.1
1277 v1.1.3
1278 v2.0
1279 v3.0
1280 v4.0
1283 test_expect_success 'checking that initial commit is in all tags' "
1284 git tag -l --contains $hash1 v* >actual &&
1285 test_cmp expected actual
1288 # mixing modes and options:
1290 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1291 test_must_fail git tag -a &&
1292 test_must_fail git tag -l -v &&
1293 test_must_fail git tag -n 100 &&
1294 test_must_fail git tag -l -m msg &&
1295 test_must_fail git tag -l -F some file &&
1296 test_must_fail git tag -v -s
1299 test_done