git stash: make sure that .git/logs/refs/ exists
[git/mingw/4msysgit.git] / t / t7004-tag.sh
blobc8d6e9f88cc36f7e6a1208721ea6c45991452b9e
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-gpg.sh
13 # creating and listing lightweight tags:
15 tag_exists () {
16 git show-ref --quiet --verify refs/tags/"$1"
19 # todo: git tag -l now returns always zero, when fixed, change this test
20 test_expect_success 'listing all tags in an empty tree should succeed' '
21 git tag -l &&
22 git tag
25 test_expect_success 'listing all tags in an empty tree should output nothing' '
26 test `git tag -l | wc -l` -eq 0 &&
27 test `git tag | wc -l` -eq 0
30 test_expect_success 'looking for a tag in an empty tree should fail' \
31 '! (tag_exists mytag)'
33 test_expect_success 'creating a tag in an empty tree should fail' '
34 test_must_fail git tag mynotag &&
35 ! tag_exists mynotag
38 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
39 test_must_fail git tag mytaghead HEAD &&
40 ! tag_exists mytaghead
43 test_expect_success 'creating a tag for an unknown revision should fail' '
44 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
45 ! tag_exists mytagnorev
48 # commit used in the tests, test_tick is also called here to freeze the date:
49 test_expect_success 'creating a tag using default HEAD should succeed' '
50 test_tick &&
51 echo foo >foo &&
52 git add foo &&
53 git commit -m Foo &&
54 git tag mytag
57 test_expect_success 'listing all tags if one exists should succeed' '
58 git tag -l &&
59 git tag
62 test_expect_success 'listing all tags if one exists should output that tag' '
63 test `git tag -l` = mytag &&
64 test `git tag` = mytag
67 # pattern matching:
69 test_expect_success 'listing a tag using a matching pattern should succeed' \
70 'git tag -l mytag'
72 test_expect_success \
73 'listing a tag using a matching pattern should output that tag' \
74 'test `git tag -l mytag` = mytag'
76 # todo: git tag -l now returns always zero, when fixed, change this test
77 test_expect_success \
78 'listing tags using a non-matching pattern should suceed' \
79 'git tag -l xxx'
81 test_expect_success \
82 'listing tags using a non-matching pattern should output nothing' \
83 'test `git tag -l xxx | wc -l` -eq 0'
85 # special cases for creating tags:
87 test_expect_success \
88 'trying to create a tag with the name of one existing should fail' \
89 'test_must_fail git tag mytag'
91 test_expect_success \
92 'trying to create a tag with a non-valid name should fail' '
93 test `git tag -l | wc -l` -eq 1 &&
94 test_must_fail git tag "" &&
95 test_must_fail git tag .othertag &&
96 test_must_fail git tag "other tag" &&
97 test_must_fail git tag "othertag^" &&
98 test_must_fail git tag "other~tag" &&
99 test `git tag -l | wc -l` -eq 1
102 test_expect_success 'creating a tag using HEAD directly should succeed' '
103 git tag myhead HEAD &&
104 tag_exists myhead
107 test_expect_success '--force can create a tag with the name of one existing' '
108 tag_exists mytag &&
109 git tag --force mytag &&
110 tag_exists mytag'
112 test_expect_success '--force is moot with a non-existing tag name' '
113 git tag newtag >expect &&
114 git tag --force forcetag >actual &&
115 test_cmp expect actual
117 git tag -d newtag forcetag
119 # deleting tags:
121 test_expect_success 'trying to delete an unknown tag should fail' '
122 ! tag_exists unknown-tag &&
123 test_must_fail git tag -d unknown-tag
126 cat >expect <<EOF
127 myhead
128 mytag
130 test_expect_success \
131 'trying to delete tags without params should succeed and do nothing' '
132 git tag -l > actual && test_cmp expect actual &&
133 git tag -d &&
134 git tag -l > actual && test_cmp expect actual
137 test_expect_success \
138 'deleting two existing tags in one command should succeed' '
139 tag_exists mytag &&
140 tag_exists myhead &&
141 git tag -d mytag myhead &&
142 ! tag_exists mytag &&
143 ! tag_exists myhead
146 test_expect_success \
147 'creating a tag with the name of another deleted one should succeed' '
148 ! tag_exists mytag &&
149 git tag mytag &&
150 tag_exists mytag
153 test_expect_success \
154 'trying to delete two tags, existing and not, should fail in the 2nd' '
155 tag_exists mytag &&
156 ! tag_exists myhead &&
157 test_must_fail git tag -d mytag anothertag &&
158 ! tag_exists mytag &&
159 ! tag_exists myhead
162 test_expect_success 'trying to delete an already deleted tag should fail' \
163 'test_must_fail git tag -d mytag'
165 # listing various tags with pattern matching:
167 cat >expect <<EOF
171 t210
172 t211
173 v0.2.1
174 v1.0
175 v1.0.1
176 v1.1.3
178 test_expect_success 'listing all tags should print them ordered' '
179 git tag v1.0.1 &&
180 git tag t211 &&
181 git tag aa1 &&
182 git tag v0.2.1 &&
183 git tag v1.1.3 &&
184 git tag cba &&
185 git tag a1 &&
186 git tag v1.0 &&
187 git tag t210 &&
188 git tag -l > actual &&
189 test_cmp expect actual &&
190 git tag > actual &&
191 test_cmp expect actual
194 cat >expect <<EOF
199 test_expect_success \
200 'listing tags with substring as pattern must print those matching' '
201 rm *a* &&
202 git tag -l "*a*" > current &&
203 test_cmp expect current
206 cat >expect <<EOF
207 v0.2.1
208 v1.0.1
210 test_expect_success \
211 'listing tags with a suffix as pattern must print those matching' '
212 git tag -l "*.1" > actual &&
213 test_cmp expect actual
216 cat >expect <<EOF
217 t210
218 t211
220 test_expect_success \
221 'listing tags with a prefix as pattern must print those matching' '
222 git tag -l "t21*" > actual &&
223 test_cmp expect actual
226 cat >expect <<EOF
229 test_expect_success \
230 'listing tags using a name as pattern must print that one matching' '
231 git tag -l a1 > actual &&
232 test_cmp expect actual
235 cat >expect <<EOF
236 v1.0
238 test_expect_success \
239 'listing tags using a name as pattern must print that one matching' '
240 git tag -l v1.0 > actual &&
241 test_cmp expect actual
244 cat >expect <<EOF
245 v1.0.1
246 v1.1.3
248 test_expect_success \
249 'listing tags with ? in the pattern should print those matching' '
250 git tag -l "v1.?.?" > actual &&
251 test_cmp expect actual
254 >expect
255 test_expect_success \
256 'listing tags using v.* should print nothing because none have v.' '
257 git tag -l "v.*" > actual &&
258 test_cmp expect actual
261 cat >expect <<EOF
262 v0.2.1
263 v1.0
264 v1.0.1
265 v1.1.3
267 test_expect_success \
268 'listing tags using v* should print only those having v' '
269 git tag -l "v*" > actual &&
270 test_cmp expect actual
273 test_expect_success 'tag -l can accept multiple patterns' '
274 git tag -l "v1*" "v0*" >actual &&
275 test_cmp expect actual
278 test_expect_success 'listing tags in column' '
279 COLUMNS=40 git tag -l --column=row >actual &&
280 cat >expected <<\EOF &&
281 a1 aa1 cba t210 t211
282 v0.2.1 v1.0 v1.0.1 v1.1.3
284 test_cmp expected actual
287 test_expect_success 'listing tags in column with column.*' '
288 git config column.tag row &&
289 git config column.ui dense &&
290 COLUMNS=40 git tag -l >actual &&
291 git config --unset column.ui &&
292 git config --unset column.tag &&
293 cat >expected <<\EOF &&
294 a1 aa1 cba t210 t211
295 v0.2.1 v1.0 v1.0.1 v1.1.3
297 test_cmp expected actual
300 test_expect_success 'listing tag with -n --column should fail' '
301 test_must_fail git tag --column -n
304 test_expect_success 'listing tags -n in column with column.ui ignored' '
305 git config column.ui "row dense" &&
306 COLUMNS=40 git tag -l -n >actual &&
307 git config --unset column.ui &&
308 cat >expected <<\EOF &&
309 a1 Foo
310 aa1 Foo
311 cba Foo
312 t210 Foo
313 t211 Foo
314 v0.2.1 Foo
315 v1.0 Foo
316 v1.0.1 Foo
317 v1.1.3 Foo
319 test_cmp expected actual
322 # creating and verifying lightweight tags:
324 test_expect_success \
325 'a non-annotated tag created without parameters should point to HEAD' '
326 git tag non-annotated-tag &&
327 test $(git cat-file -t non-annotated-tag) = commit &&
328 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
331 test_expect_success 'trying to verify an unknown tag should fail' \
332 'test_must_fail git tag -v unknown-tag'
334 test_expect_success \
335 'trying to verify a non-annotated and non-signed tag should fail' \
336 'test_must_fail git tag -v non-annotated-tag'
338 test_expect_success \
339 'trying to verify many non-annotated or unknown tags, should fail' \
340 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
342 # creating annotated tags:
344 get_tag_msg () {
345 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
348 # run test_tick before committing always gives the time in that timezone
349 get_tag_header () {
350 cat <<EOF
351 object $2
352 type $3
353 tag $1
354 tagger C O Mitter <committer@example.com> $4 -0700
359 commit=$(git rev-parse HEAD)
360 time=$test_tick
362 get_tag_header annotated-tag $commit commit $time >expect
363 echo "A message" >>expect
364 test_expect_success \
365 'creating an annotated tag with -m message should succeed' '
366 git tag -m "A message" annotated-tag &&
367 get_tag_msg annotated-tag >actual &&
368 test_cmp expect actual
371 cat >msgfile <<EOF
372 Another message
373 in a file.
375 get_tag_header file-annotated-tag $commit commit $time >expect
376 cat msgfile >>expect
377 test_expect_success \
378 'creating an annotated tag with -F messagefile should succeed' '
379 git tag -F msgfile file-annotated-tag &&
380 get_tag_msg file-annotated-tag >actual &&
381 test_cmp expect actual
384 cat >inputmsg <<EOF
385 A message from the
386 standard input
388 get_tag_header stdin-annotated-tag $commit commit $time >expect
389 cat inputmsg >>expect
390 test_expect_success 'creating an annotated tag with -F - should succeed' '
391 git tag -F - stdin-annotated-tag <inputmsg &&
392 get_tag_msg stdin-annotated-tag >actual &&
393 test_cmp expect actual
396 test_expect_success \
397 'trying to create a tag with a non-existing -F file should fail' '
398 ! test -f nonexistingfile &&
399 ! tag_exists notag &&
400 test_must_fail git tag -F nonexistingfile notag &&
401 ! tag_exists notag
404 test_expect_success \
405 'trying to create tags giving both -m or -F options should fail' '
406 echo "message file 1" >msgfile1 &&
407 echo "message file 2" >msgfile2 &&
408 ! tag_exists msgtag &&
409 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
410 ! tag_exists msgtag &&
411 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
412 ! tag_exists msgtag &&
413 test_must_fail git tag -m "message 1" -F msgfile1 \
414 -m "message 2" msgtag &&
415 ! tag_exists msgtag
418 # blank and empty messages:
420 get_tag_header empty-annotated-tag $commit commit $time >expect
421 test_expect_success \
422 'creating a tag with an empty -m message should succeed' '
423 git tag -m "" empty-annotated-tag &&
424 get_tag_msg empty-annotated-tag >actual &&
425 test_cmp expect actual
428 >emptyfile
429 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
430 test_expect_success \
431 'creating a tag with an empty -F messagefile should succeed' '
432 git tag -F emptyfile emptyfile-annotated-tag &&
433 get_tag_msg emptyfile-annotated-tag >actual &&
434 test_cmp expect actual
437 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
438 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
439 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
440 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
441 get_tag_header blanks-annotated-tag $commit commit $time >expect
442 cat >>expect <<EOF
443 Leading blank lines
445 Repeated blank lines
447 Trailing spaces
449 Trailing blank lines
451 test_expect_success \
452 'extra blanks in the message for an annotated tag should be removed' '
453 git tag -F blanksfile blanks-annotated-tag &&
454 get_tag_msg blanks-annotated-tag >actual &&
455 test_cmp expect actual
458 get_tag_header blank-annotated-tag $commit commit $time >expect
459 test_expect_success \
460 'creating a tag with blank -m message with spaces should succeed' '
461 git tag -m " " blank-annotated-tag &&
462 get_tag_msg blank-annotated-tag >actual &&
463 test_cmp expect actual
466 echo ' ' >blankfile
467 echo '' >>blankfile
468 echo ' ' >>blankfile
469 get_tag_header blankfile-annotated-tag $commit commit $time >expect
470 test_expect_success \
471 'creating a tag with blank -F messagefile with spaces should succeed' '
472 git tag -F blankfile blankfile-annotated-tag &&
473 get_tag_msg blankfile-annotated-tag >actual &&
474 test_cmp expect actual
477 printf ' ' >blanknonlfile
478 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
479 test_expect_success \
480 'creating a tag with -F file of spaces and no newline should succeed' '
481 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
482 get_tag_msg blanknonlfile-annotated-tag >actual &&
483 test_cmp expect actual
486 # messages with commented lines:
488 cat >commentsfile <<EOF
489 # A comment
491 ############
492 The message.
493 ############
494 One line.
497 # commented lines
498 # commented lines
500 Another line.
501 # comments
503 Last line.
505 get_tag_header comments-annotated-tag $commit commit $time >expect
506 cat >>expect <<EOF
507 The message.
508 One line.
510 Another line.
512 Last line.
514 test_expect_success \
515 'creating a tag using a -F messagefile with #comments should succeed' '
516 git tag -F commentsfile comments-annotated-tag &&
517 get_tag_msg comments-annotated-tag >actual &&
518 test_cmp expect actual
521 get_tag_header comment-annotated-tag $commit commit $time >expect
522 test_expect_success \
523 'creating a tag with a #comment in the -m message should succeed' '
524 git tag -m "#comment" comment-annotated-tag &&
525 get_tag_msg comment-annotated-tag >actual &&
526 test_cmp expect actual
529 echo '#comment' >commentfile
530 echo '' >>commentfile
531 echo '####' >>commentfile
532 get_tag_header commentfile-annotated-tag $commit commit $time >expect
533 test_expect_success \
534 'creating a tag with #comments in the -F messagefile should succeed' '
535 git tag -F commentfile commentfile-annotated-tag &&
536 get_tag_msg commentfile-annotated-tag >actual &&
537 test_cmp expect actual
540 printf '#comment' >commentnonlfile
541 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
542 test_expect_success \
543 'creating a tag with a file of #comment and no newline should succeed' '
544 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
545 get_tag_msg commentnonlfile-annotated-tag >actual &&
546 test_cmp expect actual
549 # listing messages for annotated non-signed tags:
551 test_expect_success \
552 'listing the one-line message of a non-signed tag should succeed' '
553 git tag -m "A msg" tag-one-line &&
555 echo "tag-one-line" >expect &&
556 git tag -l | grep "^tag-one-line" >actual &&
557 test_cmp expect actual &&
558 git tag -n0 -l | grep "^tag-one-line" >actual &&
559 test_cmp expect actual &&
560 git tag -n0 -l tag-one-line >actual &&
561 test_cmp expect actual &&
563 echo "tag-one-line A msg" >expect &&
564 git tag -n1 -l | grep "^tag-one-line" >actual &&
565 test_cmp expect actual &&
566 git tag -n -l | grep "^tag-one-line" >actual &&
567 test_cmp expect actual &&
568 git tag -n1 -l tag-one-line >actual &&
569 test_cmp expect actual &&
570 git tag -n2 -l tag-one-line >actual &&
571 test_cmp expect actual &&
572 git tag -n999 -l tag-one-line >actual &&
573 test_cmp expect actual
576 test_expect_success \
577 'listing the zero-lines message of a non-signed tag should succeed' '
578 git tag -m "" tag-zero-lines &&
580 echo "tag-zero-lines" >expect &&
581 git tag -l | grep "^tag-zero-lines" >actual &&
582 test_cmp expect actual &&
583 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
584 test_cmp expect actual &&
585 git tag -n0 -l tag-zero-lines >actual &&
586 test_cmp expect actual &&
588 echo "tag-zero-lines " >expect &&
589 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
590 test_cmp expect actual &&
591 git tag -n -l | grep "^tag-zero-lines" >actual &&
592 test_cmp expect actual &&
593 git tag -n1 -l tag-zero-lines >actual &&
594 test_cmp expect actual &&
595 git tag -n2 -l tag-zero-lines >actual &&
596 test_cmp expect actual &&
597 git tag -n999 -l tag-zero-lines >actual &&
598 test_cmp expect actual
601 echo 'tag line one' >annotagmsg
602 echo 'tag line two' >>annotagmsg
603 echo 'tag line three' >>annotagmsg
604 test_expect_success \
605 'listing many message lines of a non-signed tag should succeed' '
606 git tag -F annotagmsg tag-lines &&
608 echo "tag-lines" >expect &&
609 git tag -l | grep "^tag-lines" >actual &&
610 test_cmp expect actual &&
611 git tag -n0 -l | grep "^tag-lines" >actual &&
612 test_cmp expect actual &&
613 git tag -n0 -l tag-lines >actual &&
614 test_cmp expect actual &&
616 echo "tag-lines tag line one" >expect &&
617 git tag -n1 -l | grep "^tag-lines" >actual &&
618 test_cmp expect actual &&
619 git tag -n -l | grep "^tag-lines" >actual &&
620 test_cmp expect actual &&
621 git tag -n1 -l tag-lines >actual &&
622 test_cmp expect actual &&
624 echo " tag line two" >>expect &&
625 git tag -n2 -l | grep "^ *tag.line" >actual &&
626 test_cmp expect actual &&
627 git tag -n2 -l tag-lines >actual &&
628 test_cmp expect actual &&
630 echo " tag line three" >>expect &&
631 git tag -n3 -l | grep "^ *tag.line" >actual &&
632 test_cmp expect actual &&
633 git tag -n3 -l tag-lines >actual &&
634 test_cmp expect actual &&
635 git tag -n4 -l | grep "^ *tag.line" >actual &&
636 test_cmp expect actual &&
637 git tag -n4 -l tag-lines >actual &&
638 test_cmp expect actual &&
639 git tag -n99 -l | grep "^ *tag.line" >actual &&
640 test_cmp expect actual &&
641 git tag -n99 -l tag-lines >actual &&
642 test_cmp expect actual
645 test_expect_success 'annotations for blobs are empty' '
646 blob=$(git hash-object -w --stdin <<-\EOF
647 Blob paragraph 1.
649 Blob paragraph 2.
651 ) &&
652 git tag tag-blob $blob &&
653 echo "tag-blob " >expect &&
654 git tag -n1 -l tag-blob >actual &&
655 test_cmp expect actual
658 # trying to verify annotated non-signed tags:
660 test_expect_success GPG \
661 'trying to verify an annotated non-signed tag should fail' '
662 tag_exists annotated-tag &&
663 test_must_fail git tag -v annotated-tag
666 test_expect_success GPG \
667 'trying to verify a file-annotated non-signed tag should fail' '
668 tag_exists file-annotated-tag &&
669 test_must_fail git tag -v file-annotated-tag
672 test_expect_success GPG \
673 'trying to verify two annotated non-signed tags should fail' '
674 tag_exists annotated-tag file-annotated-tag &&
675 test_must_fail git tag -v annotated-tag file-annotated-tag
678 # creating and verifying signed tags:
680 get_tag_header signed-tag $commit commit $time >expect
681 echo 'A signed tag message' >>expect
682 echo '-----BEGIN PGP SIGNATURE-----' >>expect
683 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
684 git tag -s -m "A signed tag message" signed-tag &&
685 get_tag_msg signed-tag >actual &&
686 test_cmp expect actual
689 get_tag_header u-signed-tag $commit commit $time >expect
690 echo 'Another message' >>expect
691 echo '-----BEGIN PGP SIGNATURE-----' >>expect
692 test_expect_success GPG 'sign with a given key id' '
694 git tag -u committer@example.com -m "Another message" u-signed-tag &&
695 get_tag_msg u-signed-tag >actual &&
696 test_cmp expect actual
700 test_expect_success GPG 'sign with an unknown id (1)' '
702 test_must_fail git tag -u author@example.com \
703 -m "Another message" o-signed-tag
707 test_expect_success GPG 'sign with an unknown id (2)' '
709 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
713 cat >fakeeditor <<'EOF'
714 #!/bin/sh
715 test -n "$1" && exec >"$1"
716 echo A signed tag message
717 echo from a fake editor.
719 chmod +x fakeeditor
721 get_tag_header implied-sign $commit commit $time >expect
722 ./fakeeditor >>expect
723 echo '-----BEGIN PGP SIGNATURE-----' >>expect
724 test_expect_success GPG '-u implies signed tag' '
725 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
726 get_tag_msg implied-sign >actual &&
727 test_cmp expect actual
730 cat >sigmsgfile <<EOF
731 Another signed tag
732 message in a file.
734 get_tag_header file-signed-tag $commit commit $time >expect
735 cat sigmsgfile >>expect
736 echo '-----BEGIN PGP SIGNATURE-----' >>expect
737 test_expect_success GPG \
738 'creating a signed tag with -F messagefile should succeed' '
739 git tag -s -F sigmsgfile file-signed-tag &&
740 get_tag_msg file-signed-tag >actual &&
741 test_cmp expect actual
744 cat >siginputmsg <<EOF
745 A signed tag message from
746 the standard input
748 get_tag_header stdin-signed-tag $commit commit $time >expect
749 cat siginputmsg >>expect
750 echo '-----BEGIN PGP SIGNATURE-----' >>expect
751 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
752 git tag -s -F - stdin-signed-tag <siginputmsg &&
753 get_tag_msg stdin-signed-tag >actual &&
754 test_cmp expect actual
757 get_tag_header implied-annotate $commit commit $time >expect
758 ./fakeeditor >>expect
759 echo '-----BEGIN PGP SIGNATURE-----' >>expect
760 test_expect_success GPG '-s implies annotated tag' '
761 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
762 get_tag_msg implied-annotate >actual &&
763 test_cmp expect actual
766 test_expect_success GPG \
767 'trying to create a signed tag with non-existing -F file should fail' '
768 ! test -f nonexistingfile &&
769 ! tag_exists nosigtag &&
770 test_must_fail git tag -s -F nonexistingfile nosigtag &&
771 ! tag_exists nosigtag
774 test_expect_success GPG 'verifying a signed tag should succeed' \
775 'git tag -v signed-tag'
777 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
778 'git tag -v signed-tag file-signed-tag'
780 test_expect_success GPG \
781 'verifying many signed and non-signed tags should fail' '
782 test_must_fail git tag -v signed-tag annotated-tag &&
783 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
784 test_must_fail git tag -v annotated-tag \
785 file-signed-tag file-annotated-tag &&
786 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
789 test_expect_success GPG 'verifying a forged tag should fail' '
790 forged=$(git cat-file tag signed-tag |
791 sed -e "s/signed-tag/forged-tag/" |
792 git mktag) &&
793 git tag forged-tag $forged &&
794 test_must_fail git tag -v forged-tag
797 # blank and empty messages for signed tags:
799 get_tag_header empty-signed-tag $commit commit $time >expect
800 echo '-----BEGIN PGP SIGNATURE-----' >>expect
801 test_expect_success GPG \
802 'creating a signed tag with an empty -m message should succeed' '
803 git tag -s -m "" empty-signed-tag &&
804 get_tag_msg empty-signed-tag >actual &&
805 test_cmp expect actual &&
806 git tag -v empty-signed-tag
809 >sigemptyfile
810 get_tag_header emptyfile-signed-tag $commit commit $time >expect
811 echo '-----BEGIN PGP SIGNATURE-----' >>expect
812 test_expect_success GPG \
813 'creating a signed tag with an empty -F messagefile should succeed' '
814 git tag -s -F sigemptyfile emptyfile-signed-tag &&
815 get_tag_msg emptyfile-signed-tag >actual &&
816 test_cmp expect actual &&
817 git tag -v emptyfile-signed-tag
820 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
821 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
822 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
823 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
824 get_tag_header blanks-signed-tag $commit commit $time >expect
825 cat >>expect <<EOF
826 Leading blank lines
828 Repeated blank lines
830 Trailing spaces
832 Trailing blank lines
834 echo '-----BEGIN PGP SIGNATURE-----' >>expect
835 test_expect_success GPG \
836 'extra blanks in the message for a signed tag should be removed' '
837 git tag -s -F sigblanksfile blanks-signed-tag &&
838 get_tag_msg blanks-signed-tag >actual &&
839 test_cmp expect actual &&
840 git tag -v blanks-signed-tag
843 get_tag_header blank-signed-tag $commit commit $time >expect
844 echo '-----BEGIN PGP SIGNATURE-----' >>expect
845 test_expect_success GPG \
846 'creating a signed tag with a blank -m message should succeed' '
847 git tag -s -m " " blank-signed-tag &&
848 get_tag_msg blank-signed-tag >actual &&
849 test_cmp expect actual &&
850 git tag -v blank-signed-tag
853 echo ' ' >sigblankfile
854 echo '' >>sigblankfile
855 echo ' ' >>sigblankfile
856 get_tag_header blankfile-signed-tag $commit commit $time >expect
857 echo '-----BEGIN PGP SIGNATURE-----' >>expect
858 test_expect_success GPG \
859 'creating a signed tag with blank -F file with spaces should succeed' '
860 git tag -s -F sigblankfile blankfile-signed-tag &&
861 get_tag_msg blankfile-signed-tag >actual &&
862 test_cmp expect actual &&
863 git tag -v blankfile-signed-tag
866 printf ' ' >sigblanknonlfile
867 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
868 echo '-----BEGIN PGP SIGNATURE-----' >>expect
869 test_expect_success GPG \
870 'creating a signed tag with spaces and no newline should succeed' '
871 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
872 get_tag_msg blanknonlfile-signed-tag >actual &&
873 test_cmp expect actual &&
874 git tag -v signed-tag
877 # messages with commented lines for signed tags:
879 cat >sigcommentsfile <<EOF
880 # A comment
882 ############
883 The message.
884 ############
885 One line.
888 # commented lines
889 # commented lines
891 Another line.
892 # comments
894 Last line.
896 get_tag_header comments-signed-tag $commit commit $time >expect
897 cat >>expect <<EOF
898 The message.
899 One line.
901 Another line.
903 Last line.
905 echo '-----BEGIN PGP SIGNATURE-----' >>expect
906 test_expect_success GPG \
907 'creating a signed tag with a -F file with #comments should succeed' '
908 git tag -s -F sigcommentsfile comments-signed-tag &&
909 get_tag_msg comments-signed-tag >actual &&
910 test_cmp expect actual &&
911 git tag -v comments-signed-tag
914 get_tag_header comment-signed-tag $commit commit $time >expect
915 echo '-----BEGIN PGP SIGNATURE-----' >>expect
916 test_expect_success GPG \
917 'creating a signed tag with #commented -m message should succeed' '
918 git tag -s -m "#comment" comment-signed-tag &&
919 get_tag_msg comment-signed-tag >actual &&
920 test_cmp expect actual &&
921 git tag -v comment-signed-tag
924 echo '#comment' >sigcommentfile
925 echo '' >>sigcommentfile
926 echo '####' >>sigcommentfile
927 get_tag_header commentfile-signed-tag $commit commit $time >expect
928 echo '-----BEGIN PGP SIGNATURE-----' >>expect
929 test_expect_success GPG \
930 'creating a signed tag with #commented -F messagefile should succeed' '
931 git tag -s -F sigcommentfile commentfile-signed-tag &&
932 get_tag_msg commentfile-signed-tag >actual &&
933 test_cmp expect actual &&
934 git tag -v commentfile-signed-tag
937 printf '#comment' >sigcommentnonlfile
938 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
939 echo '-----BEGIN PGP SIGNATURE-----' >>expect
940 test_expect_success GPG \
941 'creating a signed tag with a #comment and no newline should succeed' '
942 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
943 get_tag_msg commentnonlfile-signed-tag >actual &&
944 test_cmp expect actual &&
945 git tag -v commentnonlfile-signed-tag
948 # listing messages for signed tags:
950 test_expect_success GPG \
951 'listing the one-line message of a signed tag should succeed' '
952 git tag -s -m "A message line signed" stag-one-line &&
954 echo "stag-one-line" >expect &&
955 git tag -l | grep "^stag-one-line" >actual &&
956 test_cmp expect actual &&
957 git tag -n0 -l | grep "^stag-one-line" >actual &&
958 test_cmp expect actual &&
959 git tag -n0 -l stag-one-line >actual &&
960 test_cmp expect actual &&
962 echo "stag-one-line A message line signed" >expect &&
963 git tag -n1 -l | grep "^stag-one-line" >actual &&
964 test_cmp expect actual &&
965 git tag -n -l | grep "^stag-one-line" >actual &&
966 test_cmp expect actual &&
967 git tag -n1 -l stag-one-line >actual &&
968 test_cmp expect actual &&
969 git tag -n2 -l stag-one-line >actual &&
970 test_cmp expect actual &&
971 git tag -n999 -l stag-one-line >actual &&
972 test_cmp expect actual
975 test_expect_success GPG \
976 'listing the zero-lines message of a signed tag should succeed' '
977 git tag -s -m "" stag-zero-lines &&
979 echo "stag-zero-lines" >expect &&
980 git tag -l | grep "^stag-zero-lines" >actual &&
981 test_cmp expect actual &&
982 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
983 test_cmp expect actual &&
984 git tag -n0 -l stag-zero-lines >actual &&
985 test_cmp expect actual &&
987 echo "stag-zero-lines " >expect &&
988 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
989 test_cmp expect actual &&
990 git tag -n -l | grep "^stag-zero-lines" >actual &&
991 test_cmp expect actual &&
992 git tag -n1 -l stag-zero-lines >actual &&
993 test_cmp expect actual &&
994 git tag -n2 -l stag-zero-lines >actual &&
995 test_cmp expect actual &&
996 git tag -n999 -l stag-zero-lines >actual &&
997 test_cmp expect actual
1000 echo 'stag line one' >sigtagmsg
1001 echo 'stag line two' >>sigtagmsg
1002 echo 'stag line three' >>sigtagmsg
1003 test_expect_success GPG \
1004 'listing many message lines of a signed tag should succeed' '
1005 git tag -s -F sigtagmsg stag-lines &&
1007 echo "stag-lines" >expect &&
1008 git tag -l | grep "^stag-lines" >actual &&
1009 test_cmp expect actual &&
1010 git tag -n0 -l | grep "^stag-lines" >actual &&
1011 test_cmp expect actual &&
1012 git tag -n0 -l stag-lines >actual &&
1013 test_cmp expect actual &&
1015 echo "stag-lines stag line one" >expect &&
1016 git tag -n1 -l | grep "^stag-lines" >actual &&
1017 test_cmp expect actual &&
1018 git tag -n -l | grep "^stag-lines" >actual &&
1019 test_cmp expect actual &&
1020 git tag -n1 -l stag-lines >actual &&
1021 test_cmp expect actual &&
1023 echo " stag line two" >>expect &&
1024 git tag -n2 -l | grep "^ *stag.line" >actual &&
1025 test_cmp expect actual &&
1026 git tag -n2 -l stag-lines >actual &&
1027 test_cmp expect actual &&
1029 echo " stag line three" >>expect &&
1030 git tag -n3 -l | grep "^ *stag.line" >actual &&
1031 test_cmp expect actual &&
1032 git tag -n3 -l stag-lines >actual &&
1033 test_cmp expect actual &&
1034 git tag -n4 -l | grep "^ *stag.line" >actual &&
1035 test_cmp expect actual &&
1036 git tag -n4 -l stag-lines >actual &&
1037 test_cmp expect actual &&
1038 git tag -n99 -l | grep "^ *stag.line" >actual &&
1039 test_cmp expect actual &&
1040 git tag -n99 -l stag-lines >actual &&
1041 test_cmp expect actual
1044 # tags pointing to objects different from commits:
1046 tree=$(git rev-parse HEAD^{tree})
1047 blob=$(git rev-parse HEAD:foo)
1048 tag=$(git rev-parse signed-tag 2>/dev/null)
1050 get_tag_header tree-signed-tag $tree tree $time >expect
1051 echo "A message for a tree" >>expect
1052 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1053 test_expect_success GPG \
1054 'creating a signed tag pointing to a tree should succeed' '
1055 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1056 get_tag_msg tree-signed-tag >actual &&
1057 test_cmp expect actual
1060 get_tag_header blob-signed-tag $blob blob $time >expect
1061 echo "A message for a blob" >>expect
1062 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1063 test_expect_success GPG \
1064 'creating a signed tag pointing to a blob should succeed' '
1065 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1066 get_tag_msg blob-signed-tag >actual &&
1067 test_cmp expect actual
1070 get_tag_header tag-signed-tag $tag tag $time >expect
1071 echo "A message for another tag" >>expect
1072 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1073 test_expect_success GPG \
1074 'creating a signed tag pointing to another tag should succeed' '
1075 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1076 get_tag_msg tag-signed-tag >actual &&
1077 test_cmp expect actual
1080 # usage with rfc1991 signatures
1081 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1082 echo "RFC1991 signed tag" >>expect
1083 echo '-----BEGIN PGP MESSAGE-----' >>expect
1084 test_expect_success GPG \
1085 'creating a signed tag with rfc1991' '
1086 echo "rfc1991" >gpghome/gpg.conf &&
1087 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1088 get_tag_msg rfc1991-signed-tag >actual &&
1089 test_cmp expect actual
1092 cat >fakeeditor <<'EOF'
1093 #!/bin/sh
1094 cp "$1" actual
1096 chmod +x fakeeditor
1098 test_expect_success GPG \
1099 'reediting a signed tag body omits signature' '
1100 echo "rfc1991" >gpghome/gpg.conf &&
1101 echo "RFC1991 signed tag" >expect &&
1102 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1103 test_cmp expect actual
1106 test_expect_success GPG \
1107 'verifying rfc1991 signature' '
1108 echo "rfc1991" >gpghome/gpg.conf &&
1109 git tag -v rfc1991-signed-tag
1112 test_expect_success GPG \
1113 'list tag with rfc1991 signature' '
1114 echo "rfc1991" >gpghome/gpg.conf &&
1115 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1116 git tag -l -n1 rfc1991-signed-tag >actual &&
1117 test_cmp expect actual &&
1118 git tag -l -n2 rfc1991-signed-tag >actual &&
1119 test_cmp expect actual &&
1120 git tag -l -n999 rfc1991-signed-tag >actual &&
1121 test_cmp expect actual
1124 rm -f gpghome/gpg.conf
1126 test_expect_success GPG \
1127 'verifying rfc1991 signature without --rfc1991' '
1128 git tag -v rfc1991-signed-tag
1131 test_expect_success GPG \
1132 'list tag with rfc1991 signature without --rfc1991' '
1133 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1134 git tag -l -n1 rfc1991-signed-tag >actual &&
1135 test_cmp expect actual &&
1136 git tag -l -n2 rfc1991-signed-tag >actual &&
1137 test_cmp expect actual &&
1138 git tag -l -n999 rfc1991-signed-tag >actual &&
1139 test_cmp expect actual
1142 test_expect_success GPG \
1143 'reediting a signed tag body omits signature' '
1144 echo "RFC1991 signed tag" >expect &&
1145 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1146 test_cmp expect actual
1149 # try to sign with bad user.signingkey
1150 git config user.signingkey BobTheMouse
1151 test_expect_success GPG \
1152 'git tag -s fails if gpg is misconfigured' \
1153 'test_must_fail git tag -s -m tail tag-gpg-failure'
1154 git config --unset user.signingkey
1156 # try to verify without gpg:
1158 rm -rf gpghome
1159 test_expect_success GPG \
1160 'verify signed tag fails when public key is not present' \
1161 'test_must_fail git tag -v signed-tag'
1163 test_expect_success \
1164 'git tag -a fails if tag annotation is empty' '
1165 ! (GIT_EDITOR=cat git tag -a initial-comment)
1168 test_expect_success \
1169 'message in editor has initial comment' '
1170 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1173 test_expect_success 'message in editor has initial comment: first line' '
1174 # check the first line --- should be empty
1175 echo >first.expect &&
1176 sed -e 1q <actual >first.actual &&
1177 test_i18ncmp first.expect first.actual
1180 test_expect_success \
1181 'message in editor has initial comment: remainder' '
1182 # remove commented lines from the remainder -- should be empty
1183 >rest.expect
1184 sed -e 1d -e '/^#/d' <actual >rest.actual &&
1185 test_cmp rest.expect rest.actual
1188 get_tag_header reuse $commit commit $time >expect
1189 echo "An annotation to be reused" >> expect
1190 test_expect_success \
1191 'overwriting an annoted tag should use its previous body' '
1192 git tag -a -m "An annotation to be reused" reuse &&
1193 GIT_EDITOR=true git tag -f -a reuse &&
1194 get_tag_msg reuse >actual &&
1195 test_cmp expect actual
1198 test_expect_success 'filename for the message is relative to cwd' '
1199 mkdir subdir &&
1200 echo "Tag message in top directory" >msgfile-5 &&
1201 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1203 cd subdir &&
1204 git tag -a -F msgfile-5 tag-from-subdir
1205 ) &&
1206 git cat-file tag tag-from-subdir | grep "in sub directory"
1209 test_expect_success 'filename for the message is relative to cwd' '
1210 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1212 cd subdir &&
1213 git tag -a -F msgfile-6 tag-from-subdir-2
1214 ) &&
1215 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1218 # create a few more commits to test --contains
1220 hash1=$(git rev-parse HEAD)
1222 test_expect_success 'creating second commit and tag' '
1223 echo foo-2.0 >foo &&
1224 git add foo &&
1225 git commit -m second &&
1226 git tag v2.0
1229 hash2=$(git rev-parse HEAD)
1231 test_expect_success 'creating third commit without tag' '
1232 echo foo-dev >foo &&
1233 git add foo &&
1234 git commit -m third
1237 hash3=$(git rev-parse HEAD)
1239 # simple linear checks of --continue
1241 cat > expected <<EOF
1242 v0.2.1
1243 v1.0
1244 v1.0.1
1245 v1.1.3
1246 v2.0
1249 test_expect_success 'checking that first commit is in all tags (hash)' "
1250 git tag -l --contains $hash1 v* >actual &&
1251 test_cmp expected actual
1254 # other ways of specifying the commit
1255 test_expect_success 'checking that first commit is in all tags (tag)' "
1256 git tag -l --contains v1.0 v* >actual &&
1257 test_cmp expected actual
1260 test_expect_success 'checking that first commit is in all tags (relative)' "
1261 git tag -l --contains HEAD~2 v* >actual &&
1262 test_cmp expected actual
1265 cat > expected <<EOF
1266 v2.0
1269 test_expect_success 'checking that second commit only has one tag' "
1270 git tag -l --contains $hash2 v* >actual &&
1271 test_cmp expected actual
1275 cat > expected <<EOF
1278 test_expect_success 'checking that third commit has no tags' "
1279 git tag -l --contains $hash3 v* >actual &&
1280 test_cmp expected actual
1283 # how about a simple merge?
1285 test_expect_success 'creating simple branch' '
1286 git branch stable v2.0 &&
1287 git checkout stable &&
1288 echo foo-3.0 > foo &&
1289 git commit foo -m fourth &&
1290 git tag v3.0
1293 hash4=$(git rev-parse HEAD)
1295 cat > expected <<EOF
1296 v3.0
1299 test_expect_success 'checking that branch head only has one tag' "
1300 git tag -l --contains $hash4 v* >actual &&
1301 test_cmp expected actual
1304 test_expect_success 'merging original branch into this branch' '
1305 git merge --strategy=ours master &&
1306 git tag v4.0
1309 cat > expected <<EOF
1310 v4.0
1313 test_expect_success 'checking that original branch head has one tag now' "
1314 git tag -l --contains $hash3 v* >actual &&
1315 test_cmp expected actual
1318 cat > expected <<EOF
1319 v0.2.1
1320 v1.0
1321 v1.0.1
1322 v1.1.3
1323 v2.0
1324 v3.0
1325 v4.0
1328 test_expect_success 'checking that initial commit is in all tags' "
1329 git tag -l --contains $hash1 v* >actual &&
1330 test_cmp expected actual
1333 # mixing modes and options:
1335 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1336 test_must_fail git tag -a &&
1337 test_must_fail git tag -l -v &&
1338 test_must_fail git tag -n 100 &&
1339 test_must_fail git tag -l -m msg &&
1340 test_must_fail git tag -l -F some file &&
1341 test_must_fail git tag -v -s
1344 # check points-at
1346 test_expect_success '--points-at cannot be used in non-list mode' '
1347 test_must_fail git tag --points-at=v4.0 foo
1350 test_expect_success '--points-at finds lightweight tags' '
1351 echo v4.0 >expect &&
1352 git tag --points-at v4.0 >actual &&
1353 test_cmp expect actual
1356 test_expect_success '--points-at finds annotated tags of commits' '
1357 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1358 echo annotated-v4.0 >expect &&
1359 git tag -l --points-at v4.0 "annotated*" >actual &&
1360 test_cmp expect actual
1363 test_expect_success '--points-at finds annotated tags of tags' '
1364 git tag -m "describing the v4.0 tag object" \
1365 annotated-again-v4.0 annotated-v4.0 &&
1366 cat >expect <<-\EOF &&
1367 annotated-again-v4.0
1368 annotated-v4.0
1370 git tag --points-at=annotated-v4.0 >actual &&
1371 test_cmp expect actual
1374 test_expect_success 'multiple --points-at are OR-ed together' '
1375 cat >expect <<-\EOF &&
1376 v2.0
1377 v3.0
1379 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1380 test_cmp expect actual
1383 test_done