Code

tag: do not show non-tag contents with "-n"
[git.git] / t / t7004-tag.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Carlos Rica
4 #
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"
16 }
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
22 '
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
27 '
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
35 '
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
40 '
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
45 '
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
54 '
56 test_expect_success 'listing all tags if one exists should succeed' '
57         git tag -l &&
58         git tag
59 '
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
64 '
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
99 '
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
116 EOF
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
155 a1
156 aa1
157 cba
158 t210
159 t211
160 v0.2.1
161 v1.0
162 v1.0.1
163 v1.1.3
164 EOF
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
182 a1
183 aa1
184 cba
185 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
196 EOF
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
206 EOF
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
214 a1
215 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
224 EOF
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
234 EOF
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
253 EOF
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
299 EOF
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.
317 EOF
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
330 EOF
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
393 EOF
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.
447 EOF
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.
456 EOF
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 test_expect_success 'annotations for blobs are empty' '
589         blob=$(git hash-object -w --stdin <<-\EOF
590         Blob paragraph 1.
592         Blob paragraph 2.
593         EOF
594         ) &&
595         git tag tag-blob $blob &&
596         echo "tag-blob        " >expect &&
597         git tag -n1 -l tag-blob >actual &&
598         test_cmp expect actual
601 # subsequent tests require gpg; check if it is available
602 gpg --version >/dev/null 2>/dev/null
603 if [ $? -eq 127 ]; then
604         say "# gpg not found - skipping tag signing and verification tests"
605 else
606         # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
607         # the gpg version 1.0.6 didn't parse trust packets correctly, so for
608         # that version, creation of signed tags using the generated key fails.
609         case "$(gpg --version)" in
610         'gpg (GnuPG) 1.0.6'*)
611                 say "Skipping signed tag tests, because a bug in 1.0.6 version"
612                 ;;
613         *)
614                 test_set_prereq GPG
615                 ;;
616         esac
617 fi
619 # trying to verify annotated non-signed tags:
621 test_expect_success GPG \
622         'trying to verify an annotated non-signed tag should fail' '
623         tag_exists annotated-tag &&
624         test_must_fail git tag -v annotated-tag
627 test_expect_success GPG \
628         'trying to verify a file-annotated non-signed tag should fail' '
629         tag_exists file-annotated-tag &&
630         test_must_fail git tag -v file-annotated-tag
633 test_expect_success GPG \
634         'trying to verify two annotated non-signed tags should fail' '
635         tag_exists annotated-tag file-annotated-tag &&
636         test_must_fail git tag -v annotated-tag file-annotated-tag
639 # creating and verifying signed tags:
641 # key generation info: gpg --homedir t/t7004 --gen-key
642 # Type DSA and Elgamal, size 2048 bits, no expiration date.
643 # Name and email: C O Mitter <committer@example.com>
644 # No password given, to enable non-interactive operation.
646 cp -R "$TEST_DIRECTORY"/t7004 ./gpghome
647 chmod 0700 gpghome
648 GNUPGHOME="$(pwd)/gpghome"
649 export GNUPGHOME
651 get_tag_header signed-tag $commit commit $time >expect
652 echo 'A signed tag message' >>expect
653 echo '-----BEGIN PGP SIGNATURE-----' >>expect
654 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
655         git tag -s -m "A signed tag message" signed-tag &&
656         get_tag_msg signed-tag >actual &&
657         test_cmp expect actual
660 get_tag_header u-signed-tag $commit commit $time >expect
661 echo 'Another message' >>expect
662 echo '-----BEGIN PGP SIGNATURE-----' >>expect
663 test_expect_success GPG 'sign with a given key id' '
665         git tag -u committer@example.com -m "Another message" u-signed-tag &&
666         get_tag_msg u-signed-tag >actual &&
667         test_cmp expect actual
671 test_expect_success GPG 'sign with an unknown id (1)' '
673         test_must_fail git tag -u author@example.com \
674                 -m "Another message" o-signed-tag
678 test_expect_success GPG 'sign with an unknown id (2)' '
680         test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
684 cat >fakeeditor <<'EOF'
685 #!/bin/sh
686 test -n "$1" && exec >"$1"
687 echo A signed tag message
688 echo from a fake editor.
689 EOF
690 chmod +x fakeeditor
692 get_tag_header implied-sign $commit commit $time >expect
693 ./fakeeditor >>expect
694 echo '-----BEGIN PGP SIGNATURE-----' >>expect
695 test_expect_success GPG '-u implies signed tag' '
696         GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
697         get_tag_msg implied-sign >actual &&
698         test_cmp expect actual
701 cat >sigmsgfile <<EOF
702 Another signed tag
703 message in a file.
704 EOF
705 get_tag_header file-signed-tag $commit commit $time >expect
706 cat sigmsgfile >>expect
707 echo '-----BEGIN PGP SIGNATURE-----' >>expect
708 test_expect_success GPG \
709         'creating a signed tag with -F messagefile should succeed' '
710         git tag -s -F sigmsgfile file-signed-tag &&
711         get_tag_msg file-signed-tag >actual &&
712         test_cmp expect actual
715 cat >siginputmsg <<EOF
716 A signed tag message from
717 the standard input
718 EOF
719 get_tag_header stdin-signed-tag $commit commit $time >expect
720 cat siginputmsg >>expect
721 echo '-----BEGIN PGP SIGNATURE-----' >>expect
722 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
723         git tag -s -F - stdin-signed-tag <siginputmsg &&
724         get_tag_msg stdin-signed-tag >actual &&
725         test_cmp expect actual
728 get_tag_header implied-annotate $commit commit $time >expect
729 ./fakeeditor >>expect
730 echo '-----BEGIN PGP SIGNATURE-----' >>expect
731 test_expect_success GPG '-s implies annotated tag' '
732         GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
733         get_tag_msg implied-annotate >actual &&
734         test_cmp expect actual
737 test_expect_success GPG \
738         'trying to create a signed tag with non-existing -F file should fail' '
739         ! test -f nonexistingfile &&
740         ! tag_exists nosigtag &&
741         test_must_fail git tag -s -F nonexistingfile nosigtag &&
742         ! tag_exists nosigtag
745 test_expect_success GPG 'verifying a signed tag should succeed' \
746         'git tag -v signed-tag'
748 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
749         'git tag -v signed-tag file-signed-tag'
751 test_expect_success GPG \
752         'verifying many signed and non-signed tags should fail' '
753         test_must_fail git tag -v signed-tag annotated-tag &&
754         test_must_fail git tag -v file-annotated-tag file-signed-tag &&
755         test_must_fail git tag -v annotated-tag \
756                 file-signed-tag file-annotated-tag &&
757         test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
760 test_expect_success GPG 'verifying a forged tag should fail' '
761         forged=$(git cat-file tag signed-tag |
762                 sed -e "s/signed-tag/forged-tag/" |
763                 git mktag) &&
764         git tag forged-tag $forged &&
765         test_must_fail git tag -v forged-tag
768 # blank and empty messages for signed tags:
770 get_tag_header empty-signed-tag $commit commit $time >expect
771 echo '-----BEGIN PGP SIGNATURE-----' >>expect
772 test_expect_success GPG \
773         'creating a signed tag with an empty -m message should succeed' '
774         git tag -s -m "" empty-signed-tag &&
775         get_tag_msg empty-signed-tag >actual &&
776         test_cmp expect actual &&
777         git tag -v empty-signed-tag
780 >sigemptyfile
781 get_tag_header emptyfile-signed-tag $commit commit $time >expect
782 echo '-----BEGIN PGP SIGNATURE-----' >>expect
783 test_expect_success GPG \
784         'creating a signed tag with an empty -F messagefile should succeed' '
785         git tag -s -F sigemptyfile emptyfile-signed-tag &&
786         get_tag_msg emptyfile-signed-tag >actual &&
787         test_cmp expect actual &&
788         git tag -v emptyfile-signed-tag
791 printf '\n\n  \n\t\nLeading blank lines\n' > sigblanksfile
792 printf '\n\t \t  \nRepeated blank lines\n' >>sigblanksfile
793 printf '\n\n\nTrailing spaces      \t  \n' >>sigblanksfile
794 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
795 get_tag_header blanks-signed-tag $commit commit $time >expect
796 cat >>expect <<EOF
797 Leading blank lines
799 Repeated blank lines
801 Trailing spaces
803 Trailing blank lines
804 EOF
805 echo '-----BEGIN PGP SIGNATURE-----' >>expect
806 test_expect_success GPG \
807         'extra blanks in the message for a signed tag should be removed' '
808         git tag -s -F sigblanksfile blanks-signed-tag &&
809         get_tag_msg blanks-signed-tag >actual &&
810         test_cmp expect actual &&
811         git tag -v blanks-signed-tag
814 get_tag_header blank-signed-tag $commit commit $time >expect
815 echo '-----BEGIN PGP SIGNATURE-----' >>expect
816 test_expect_success GPG \
817         'creating a signed tag with a blank -m message should succeed' '
818         git tag -s -m "     " blank-signed-tag &&
819         get_tag_msg blank-signed-tag >actual &&
820         test_cmp expect actual &&
821         git tag -v blank-signed-tag
824 echo '     ' >sigblankfile
825 echo ''      >>sigblankfile
826 echo '  '    >>sigblankfile
827 get_tag_header blankfile-signed-tag $commit commit $time >expect
828 echo '-----BEGIN PGP SIGNATURE-----' >>expect
829 test_expect_success GPG \
830         'creating a signed tag with blank -F file with spaces should succeed' '
831         git tag -s -F sigblankfile blankfile-signed-tag &&
832         get_tag_msg blankfile-signed-tag >actual &&
833         test_cmp expect actual &&
834         git tag -v blankfile-signed-tag
837 printf '      ' >sigblanknonlfile
838 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
839 echo '-----BEGIN PGP SIGNATURE-----' >>expect
840 test_expect_success GPG \
841         'creating a signed tag with spaces and no newline should succeed' '
842         git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
843         get_tag_msg blanknonlfile-signed-tag >actual &&
844         test_cmp expect actual &&
845         git tag -v signed-tag
848 # messages with commented lines for signed tags:
850 cat >sigcommentsfile <<EOF
851 # A comment
853 ############
854 The message.
855 ############
856 One line.
859 # commented lines
860 # commented lines
862 Another line.
863 # comments
865 Last line.
866 EOF
867 get_tag_header comments-signed-tag $commit commit $time >expect
868 cat >>expect <<EOF
869 The message.
870 One line.
872 Another line.
874 Last line.
875 EOF
876 echo '-----BEGIN PGP SIGNATURE-----' >>expect
877 test_expect_success GPG \
878         'creating a signed tag with a -F file with #comments should succeed' '
879         git tag -s -F sigcommentsfile comments-signed-tag &&
880         get_tag_msg comments-signed-tag >actual &&
881         test_cmp expect actual &&
882         git tag -v comments-signed-tag
885 get_tag_header comment-signed-tag $commit commit $time >expect
886 echo '-----BEGIN PGP SIGNATURE-----' >>expect
887 test_expect_success GPG \
888         'creating a signed tag with #commented -m message should succeed' '
889         git tag -s -m "#comment" comment-signed-tag &&
890         get_tag_msg comment-signed-tag >actual &&
891         test_cmp expect actual &&
892         git tag -v comment-signed-tag
895 echo '#comment' >sigcommentfile
896 echo ''         >>sigcommentfile
897 echo '####'     >>sigcommentfile
898 get_tag_header commentfile-signed-tag $commit commit $time >expect
899 echo '-----BEGIN PGP SIGNATURE-----' >>expect
900 test_expect_success GPG \
901         'creating a signed tag with #commented -F messagefile should succeed' '
902         git tag -s -F sigcommentfile commentfile-signed-tag &&
903         get_tag_msg commentfile-signed-tag >actual &&
904         test_cmp expect actual &&
905         git tag -v commentfile-signed-tag
908 printf '#comment' >sigcommentnonlfile
909 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
910 echo '-----BEGIN PGP SIGNATURE-----' >>expect
911 test_expect_success GPG \
912         'creating a signed tag with a #comment and no newline should succeed' '
913         git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
914         get_tag_msg commentnonlfile-signed-tag >actual &&
915         test_cmp expect actual &&
916         git tag -v commentnonlfile-signed-tag
919 # listing messages for signed tags:
921 test_expect_success GPG \
922         'listing the one-line message of a signed tag should succeed' '
923         git tag -s -m "A message line signed" stag-one-line &&
925         echo "stag-one-line" >expect &&
926         git tag -l | grep "^stag-one-line" >actual &&
927         test_cmp expect actual &&
928         git tag -n0 -l | grep "^stag-one-line" >actual &&
929         test_cmp expect actual &&
930         git tag -n0 -l stag-one-line >actual &&
931         test_cmp expect actual &&
933         echo "stag-one-line   A message line signed" >expect &&
934         git tag -n1 -l | grep "^stag-one-line" >actual &&
935         test_cmp expect actual &&
936         git tag -n -l | grep "^stag-one-line" >actual &&
937         test_cmp expect actual &&
938         git tag -n1 -l stag-one-line >actual &&
939         test_cmp expect actual &&
940         git tag -n2 -l stag-one-line >actual &&
941         test_cmp expect actual &&
942         git tag -n999 -l stag-one-line >actual &&
943         test_cmp expect actual
946 test_expect_success GPG \
947         'listing the zero-lines message of a signed tag should succeed' '
948         git tag -s -m "" stag-zero-lines &&
950         echo "stag-zero-lines" >expect &&
951         git tag -l | grep "^stag-zero-lines" >actual &&
952         test_cmp expect actual &&
953         git tag -n0 -l | grep "^stag-zero-lines" >actual &&
954         test_cmp expect actual &&
955         git tag -n0 -l stag-zero-lines >actual &&
956         test_cmp expect actual &&
958         echo "stag-zero-lines " >expect &&
959         git tag -n1 -l | grep "^stag-zero-lines" >actual &&
960         test_cmp expect actual &&
961         git tag -n -l | grep "^stag-zero-lines" >actual &&
962         test_cmp expect actual &&
963         git tag -n1 -l stag-zero-lines >actual &&
964         test_cmp expect actual &&
965         git tag -n2 -l stag-zero-lines >actual &&
966         test_cmp expect actual &&
967         git tag -n999 -l stag-zero-lines >actual &&
968         test_cmp expect actual
971 echo 'stag line one' >sigtagmsg
972 echo 'stag line two' >>sigtagmsg
973 echo 'stag line three' >>sigtagmsg
974 test_expect_success GPG \
975         'listing many message lines of a signed tag should succeed' '
976         git tag -s -F sigtagmsg stag-lines &&
978         echo "stag-lines" >expect &&
979         git tag -l | grep "^stag-lines" >actual &&
980         test_cmp expect actual &&
981         git tag -n0 -l | grep "^stag-lines" >actual &&
982         test_cmp expect actual &&
983         git tag -n0 -l stag-lines >actual &&
984         test_cmp expect actual &&
986         echo "stag-lines      stag line one" >expect &&
987         git tag -n1 -l | grep "^stag-lines" >actual &&
988         test_cmp expect actual &&
989         git tag -n -l | grep "^stag-lines" >actual &&
990         test_cmp expect actual &&
991         git tag -n1 -l stag-lines >actual &&
992         test_cmp expect actual &&
994         echo "    stag line two" >>expect &&
995         git tag -n2 -l | grep "^ *stag.line" >actual &&
996         test_cmp expect actual &&
997         git tag -n2 -l stag-lines >actual &&
998         test_cmp expect actual &&
1000         echo "    stag line three" >>expect &&
1001         git tag -n3 -l | grep "^ *stag.line" >actual &&
1002         test_cmp expect actual &&
1003         git tag -n3 -l stag-lines >actual &&
1004         test_cmp expect actual &&
1005         git tag -n4 -l | grep "^ *stag.line" >actual &&
1006         test_cmp expect actual &&
1007         git tag -n4 -l stag-lines >actual &&
1008         test_cmp expect actual &&
1009         git tag -n99 -l | grep "^ *stag.line" >actual &&
1010         test_cmp expect actual &&
1011         git tag -n99 -l stag-lines >actual &&
1012         test_cmp expect actual
1015 # tags pointing to objects different from commits:
1017 tree=$(git rev-parse HEAD^{tree})
1018 blob=$(git rev-parse HEAD:foo)
1019 tag=$(git rev-parse signed-tag 2>/dev/null)
1021 get_tag_header tree-signed-tag $tree tree $time >expect
1022 echo "A message for a tree" >>expect
1023 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1024 test_expect_success GPG \
1025         'creating a signed tag pointing to a tree should succeed' '
1026         git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1027         get_tag_msg tree-signed-tag >actual &&
1028         test_cmp expect actual
1031 get_tag_header blob-signed-tag $blob blob $time >expect
1032 echo "A message for a blob" >>expect
1033 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1034 test_expect_success GPG \
1035         'creating a signed tag pointing to a blob should succeed' '
1036         git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1037         get_tag_msg blob-signed-tag >actual &&
1038         test_cmp expect actual
1041 get_tag_header tag-signed-tag $tag tag $time >expect
1042 echo "A message for another tag" >>expect
1043 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1044 test_expect_success GPG \
1045         'creating a signed tag pointing to another tag should succeed' '
1046         git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1047         get_tag_msg tag-signed-tag >actual &&
1048         test_cmp expect actual
1051 # usage with rfc1991 signatures
1052 echo "rfc1991" > gpghome/gpg.conf
1053 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1054 echo "RFC1991 signed tag" >>expect
1055 echo '-----BEGIN PGP MESSAGE-----' >>expect
1056 test_expect_success GPG \
1057         'creating a signed tag with rfc1991' '
1058         git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1059         get_tag_msg rfc1991-signed-tag >actual &&
1060         test_cmp expect actual
1063 cat >fakeeditor <<'EOF'
1064 #!/bin/sh
1065 cp "$1" actual
1066 EOF
1067 chmod +x fakeeditor
1069 test_expect_success GPG \
1070         'reediting a signed tag body omits signature' '
1071         echo "RFC1991 signed tag" >expect &&
1072         GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1073         test_cmp expect actual
1076 test_expect_success GPG \
1077         'verifying rfc1991 signature' '
1078         git tag -v rfc1991-signed-tag
1081 test_expect_success GPG \
1082         'list tag with rfc1991 signature' '
1083         echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1084         git tag -l -n1 rfc1991-signed-tag >actual &&
1085         test_cmp expect actual &&
1086         git tag -l -n2 rfc1991-signed-tag >actual &&
1087         test_cmp expect actual &&
1088         git tag -l -n999 rfc1991-signed-tag >actual &&
1089         test_cmp expect actual
1092 rm -f gpghome/gpg.conf
1094 test_expect_success GPG \
1095         'verifying rfc1991 signature without --rfc1991' '
1096         git tag -v rfc1991-signed-tag
1099 test_expect_success GPG \
1100         'list tag with rfc1991 signature without --rfc1991' '
1101         echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1102         git tag -l -n1 rfc1991-signed-tag >actual &&
1103         test_cmp expect actual &&
1104         git tag -l -n2 rfc1991-signed-tag >actual &&
1105         test_cmp expect actual &&
1106         git tag -l -n999 rfc1991-signed-tag >actual &&
1107         test_cmp expect actual
1110 test_expect_success GPG \
1111         'reediting a signed tag body omits signature' '
1112         echo "RFC1991 signed tag" >expect &&
1113         GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1114         test_cmp expect actual
1117 # try to sign with bad user.signingkey
1118 git config user.signingkey BobTheMouse
1119 test_expect_success GPG \
1120         'git tag -s fails if gpg is misconfigured' \
1121         'test_must_fail git tag -s -m tail tag-gpg-failure'
1122 git config --unset user.signingkey
1124 # try to verify without gpg:
1126 rm -rf gpghome
1127 test_expect_success GPG \
1128         'verify signed tag fails when public key is not present' \
1129         'test_must_fail git tag -v signed-tag'
1131 test_expect_success \
1132         'git tag -a fails if tag annotation is empty' '
1133         ! (GIT_EDITOR=cat git tag -a initial-comment)
1136 test_expect_success \
1137         'message in editor has initial comment' '
1138         ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1141 test_expect_success 'message in editor has initial comment: first line' '
1142         # check the first line --- should be empty
1143         echo >first.expect &&
1144         sed -e 1q <actual >first.actual &&
1145         test_i18ncmp first.expect first.actual
1148 test_expect_success \
1149         'message in editor has initial comment: remainder' '
1150         # remove commented lines from the remainder -- should be empty
1151         >rest.expect
1152         sed -e 1d -e '/^#/d' <actual >rest.actual &&
1153         test_cmp rest.expect rest.actual
1156 get_tag_header reuse $commit commit $time >expect
1157 echo "An annotation to be reused" >> expect
1158 test_expect_success \
1159         'overwriting an annoted tag should use its previous body' '
1160         git tag -a -m "An annotation to be reused" reuse &&
1161         GIT_EDITOR=true git tag -f -a reuse &&
1162         get_tag_msg reuse >actual &&
1163         test_cmp expect actual
1166 test_expect_success 'filename for the message is relative to cwd' '
1167         mkdir subdir &&
1168         echo "Tag message in top directory" >msgfile-5 &&
1169         echo "Tag message in sub directory" >subdir/msgfile-5 &&
1170         (
1171                 cd subdir &&
1172                 git tag -a -F msgfile-5 tag-from-subdir
1173         ) &&
1174         git cat-file tag tag-from-subdir | grep "in sub directory"
1177 test_expect_success 'filename for the message is relative to cwd' '
1178         echo "Tag message in sub directory" >subdir/msgfile-6 &&
1179         (
1180                 cd subdir &&
1181                 git tag -a -F msgfile-6 tag-from-subdir-2
1182         ) &&
1183         git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1186 # create a few more commits to test --contains
1188 hash1=$(git rev-parse HEAD)
1190 test_expect_success 'creating second commit and tag' '
1191         echo foo-2.0 >foo &&
1192         git add foo &&
1193         git commit -m second &&
1194         git tag v2.0
1197 hash2=$(git rev-parse HEAD)
1199 test_expect_success 'creating third commit without tag' '
1200         echo foo-dev >foo &&
1201         git add foo &&
1202         git commit -m third
1205 hash3=$(git rev-parse HEAD)
1207 # simple linear checks of --continue
1209 cat > expected <<EOF
1210 v0.2.1
1211 v1.0
1212 v1.0.1
1213 v1.1.3
1214 v2.0
1215 EOF
1217 test_expect_success 'checking that first commit is in all tags (hash)' "
1218         git tag -l --contains $hash1 v* >actual &&
1219         test_cmp expected actual
1222 # other ways of specifying the commit
1223 test_expect_success 'checking that first commit is in all tags (tag)' "
1224         git tag -l --contains v1.0 v* >actual &&
1225         test_cmp expected actual
1228 test_expect_success 'checking that first commit is in all tags (relative)' "
1229         git tag -l --contains HEAD~2 v* >actual &&
1230         test_cmp expected actual
1233 cat > expected <<EOF
1234 v2.0
1235 EOF
1237 test_expect_success 'checking that second commit only has one tag' "
1238         git tag -l --contains $hash2 v* >actual &&
1239         test_cmp expected actual
1243 cat > expected <<EOF
1244 EOF
1246 test_expect_success 'checking that third commit has no tags' "
1247         git tag -l --contains $hash3 v* >actual &&
1248         test_cmp expected actual
1251 # how about a simple merge?
1253 test_expect_success 'creating simple branch' '
1254         git branch stable v2.0 &&
1255         git checkout stable &&
1256         echo foo-3.0 > foo &&
1257         git commit foo -m fourth &&
1258         git tag v3.0
1261 hash4=$(git rev-parse HEAD)
1263 cat > expected <<EOF
1264 v3.0
1265 EOF
1267 test_expect_success 'checking that branch head only has one tag' "
1268         git tag -l --contains $hash4 v* >actual &&
1269         test_cmp expected actual
1272 test_expect_success 'merging original branch into this branch' '
1273         git merge --strategy=ours master &&
1274         git tag v4.0
1277 cat > expected <<EOF
1278 v4.0
1279 EOF
1281 test_expect_success 'checking that original branch head has one tag now' "
1282         git tag -l --contains $hash3 v* >actual &&
1283         test_cmp expected actual
1286 cat > expected <<EOF
1287 v0.2.1
1288 v1.0
1289 v1.0.1
1290 v1.1.3
1291 v2.0
1292 v3.0
1293 v4.0
1294 EOF
1296 test_expect_success 'checking that initial commit is in all tags' "
1297         git tag -l --contains $hash1 v* >actual &&
1298         test_cmp expected actual
1301 # mixing modes and options:
1303 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1304         test_must_fail git tag -a &&
1305         test_must_fail git tag -l -v &&
1306         test_must_fail git tag -n 100 &&
1307         test_must_fail git tag -l -m msg &&
1308         test_must_fail git tag -l -F some file &&
1309         test_must_fail git tag -v -s
1312 test_done