Merge branch 'nd/fetch-status-alignment'
[alt-git.git] / t / t7004-tag.sh
blob518944653477225da94db0826d77936eaa0d249a
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 # deleting tags:
109 test_expect_success 'trying to delete an unknown tag should fail' '
110 ! tag_exists unknown-tag &&
111 test_must_fail git tag -d unknown-tag
114 cat >expect <<EOF
115 myhead
116 mytag
118 test_expect_success \
119 'trying to delete tags without params should succeed and do nothing' '
120 git tag -l > actual && test_cmp expect actual &&
121 git tag -d &&
122 git tag -l > actual && test_cmp expect actual
125 test_expect_success \
126 'deleting two existing tags in one command should succeed' '
127 tag_exists mytag &&
128 tag_exists myhead &&
129 git tag -d mytag myhead &&
130 ! tag_exists mytag &&
131 ! tag_exists myhead
134 test_expect_success \
135 'creating a tag with the name of another deleted one should succeed' '
136 ! tag_exists mytag &&
137 git tag mytag &&
138 tag_exists mytag
141 test_expect_success \
142 'trying to delete two tags, existing and not, should fail in the 2nd' '
143 tag_exists mytag &&
144 ! tag_exists myhead &&
145 test_must_fail git tag -d mytag anothertag &&
146 ! tag_exists mytag &&
147 ! tag_exists myhead
150 test_expect_success 'trying to delete an already deleted tag should fail' \
151 'test_must_fail git tag -d mytag'
153 # listing various tags with pattern matching:
155 cat >expect <<EOF
159 t210
160 t211
161 v0.2.1
162 v1.0
163 v1.0.1
164 v1.1.3
166 test_expect_success 'listing all tags should print them ordered' '
167 git tag v1.0.1 &&
168 git tag t211 &&
169 git tag aa1 &&
170 git tag v0.2.1 &&
171 git tag v1.1.3 &&
172 git tag cba &&
173 git tag a1 &&
174 git tag v1.0 &&
175 git tag t210 &&
176 git tag -l > actual &&
177 test_cmp expect actual &&
178 git tag > actual &&
179 test_cmp expect actual
182 cat >expect <<EOF
187 test_expect_success \
188 'listing tags with substring as pattern must print those matching' '
189 rm *a* &&
190 git tag -l "*a*" > current &&
191 test_cmp expect current
194 cat >expect <<EOF
195 v0.2.1
196 v1.0.1
198 test_expect_success \
199 'listing tags with a suffix as pattern must print those matching' '
200 git tag -l "*.1" > actual &&
201 test_cmp expect actual
204 cat >expect <<EOF
205 t210
206 t211
208 test_expect_success \
209 'listing tags with a prefix as pattern must print those matching' '
210 git tag -l "t21*" > actual &&
211 test_cmp expect actual
214 cat >expect <<EOF
217 test_expect_success \
218 'listing tags using a name as pattern must print that one matching' '
219 git tag -l a1 > actual &&
220 test_cmp expect actual
223 cat >expect <<EOF
224 v1.0
226 test_expect_success \
227 'listing tags using a name as pattern must print that one matching' '
228 git tag -l v1.0 > actual &&
229 test_cmp expect actual
232 cat >expect <<EOF
233 v1.0.1
234 v1.1.3
236 test_expect_success \
237 'listing tags with ? in the pattern should print those matching' '
238 git tag -l "v1.?.?" > actual &&
239 test_cmp expect actual
242 >expect
243 test_expect_success \
244 'listing tags using v.* should print nothing because none have v.' '
245 git tag -l "v.*" > actual &&
246 test_cmp expect actual
249 cat >expect <<EOF
250 v0.2.1
251 v1.0
252 v1.0.1
253 v1.1.3
255 test_expect_success \
256 'listing tags using v* should print only those having v' '
257 git tag -l "v*" > actual &&
258 test_cmp expect actual
261 test_expect_success 'tag -l can accept multiple patterns' '
262 git tag -l "v1*" "v0*" >actual &&
263 test_cmp expect actual
266 test_expect_success 'listing tags in column' '
267 COLUMNS=40 git tag -l --column=row >actual &&
268 cat >expected <<\EOF &&
269 a1 aa1 cba t210 t211
270 v0.2.1 v1.0 v1.0.1 v1.1.3
272 test_cmp expected actual
275 test_expect_success 'listing tags in column with column.*' '
276 git config column.tag row &&
277 git config column.ui dense &&
278 COLUMNS=40 git tag -l >actual &&
279 git config --unset column.ui &&
280 git config --unset column.tag &&
281 cat >expected <<\EOF &&
282 a1 aa1 cba t210 t211
283 v0.2.1 v1.0 v1.0.1 v1.1.3
285 test_cmp expected actual
288 test_expect_success 'listing tag with -n --column should fail' '
289 test_must_fail git tag --column -n
292 test_expect_success 'listing tags -n in column with column.ui ignored' '
293 git config column.ui "row dense" &&
294 COLUMNS=40 git tag -l -n >actual &&
295 git config --unset column.ui &&
296 cat >expected <<\EOF &&
297 a1 Foo
298 aa1 Foo
299 cba Foo
300 t210 Foo
301 t211 Foo
302 v0.2.1 Foo
303 v1.0 Foo
304 v1.0.1 Foo
305 v1.1.3 Foo
307 test_cmp expected actual
310 # creating and verifying lightweight tags:
312 test_expect_success \
313 'a non-annotated tag created without parameters should point to HEAD' '
314 git tag non-annotated-tag &&
315 test $(git cat-file -t non-annotated-tag) = commit &&
316 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
319 test_expect_success 'trying to verify an unknown tag should fail' \
320 'test_must_fail git tag -v unknown-tag'
322 test_expect_success \
323 'trying to verify a non-annotated and non-signed tag should fail' \
324 'test_must_fail git tag -v non-annotated-tag'
326 test_expect_success \
327 'trying to verify many non-annotated or unknown tags, should fail' \
328 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
330 # creating annotated tags:
332 get_tag_msg () {
333 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
336 # run test_tick before committing always gives the time in that timezone
337 get_tag_header () {
338 cat <<EOF
339 object $2
340 type $3
341 tag $1
342 tagger C O Mitter <committer@example.com> $4 -0700
347 commit=$(git rev-parse HEAD)
348 time=$test_tick
350 get_tag_header annotated-tag $commit commit $time >expect
351 echo "A message" >>expect
352 test_expect_success \
353 'creating an annotated tag with -m message should succeed' '
354 git tag -m "A message" annotated-tag &&
355 get_tag_msg annotated-tag >actual &&
356 test_cmp expect actual
359 cat >msgfile <<EOF
360 Another message
361 in a file.
363 get_tag_header file-annotated-tag $commit commit $time >expect
364 cat msgfile >>expect
365 test_expect_success \
366 'creating an annotated tag with -F messagefile should succeed' '
367 git tag -F msgfile file-annotated-tag &&
368 get_tag_msg file-annotated-tag >actual &&
369 test_cmp expect actual
372 cat >inputmsg <<EOF
373 A message from the
374 standard input
376 get_tag_header stdin-annotated-tag $commit commit $time >expect
377 cat inputmsg >>expect
378 test_expect_success 'creating an annotated tag with -F - should succeed' '
379 git tag -F - stdin-annotated-tag <inputmsg &&
380 get_tag_msg stdin-annotated-tag >actual &&
381 test_cmp expect actual
384 test_expect_success \
385 'trying to create a tag with a non-existing -F file should fail' '
386 ! test -f nonexistingfile &&
387 ! tag_exists notag &&
388 test_must_fail git tag -F nonexistingfile notag &&
389 ! tag_exists notag
392 test_expect_success \
393 'trying to create tags giving both -m or -F options should fail' '
394 echo "message file 1" >msgfile1 &&
395 echo "message file 2" >msgfile2 &&
396 ! tag_exists msgtag &&
397 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
398 ! tag_exists msgtag &&
399 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
400 ! tag_exists msgtag &&
401 test_must_fail git tag -m "message 1" -F msgfile1 \
402 -m "message 2" msgtag &&
403 ! tag_exists msgtag
406 # blank and empty messages:
408 get_tag_header empty-annotated-tag $commit commit $time >expect
409 test_expect_success \
410 'creating a tag with an empty -m message should succeed' '
411 git tag -m "" empty-annotated-tag &&
412 get_tag_msg empty-annotated-tag >actual &&
413 test_cmp expect actual
416 >emptyfile
417 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
418 test_expect_success \
419 'creating a tag with an empty -F messagefile should succeed' '
420 git tag -F emptyfile emptyfile-annotated-tag &&
421 get_tag_msg emptyfile-annotated-tag >actual &&
422 test_cmp expect actual
425 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
426 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
427 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
428 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
429 get_tag_header blanks-annotated-tag $commit commit $time >expect
430 cat >>expect <<EOF
431 Leading blank lines
433 Repeated blank lines
435 Trailing spaces
437 Trailing blank lines
439 test_expect_success \
440 'extra blanks in the message for an annotated tag should be removed' '
441 git tag -F blanksfile blanks-annotated-tag &&
442 get_tag_msg blanks-annotated-tag >actual &&
443 test_cmp expect actual
446 get_tag_header blank-annotated-tag $commit commit $time >expect
447 test_expect_success \
448 'creating a tag with blank -m message with spaces should succeed' '
449 git tag -m " " blank-annotated-tag &&
450 get_tag_msg blank-annotated-tag >actual &&
451 test_cmp expect actual
454 echo ' ' >blankfile
455 echo '' >>blankfile
456 echo ' ' >>blankfile
457 get_tag_header blankfile-annotated-tag $commit commit $time >expect
458 test_expect_success \
459 'creating a tag with blank -F messagefile with spaces should succeed' '
460 git tag -F blankfile blankfile-annotated-tag &&
461 get_tag_msg blankfile-annotated-tag >actual &&
462 test_cmp expect actual
465 printf ' ' >blanknonlfile
466 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
467 test_expect_success \
468 'creating a tag with -F file of spaces and no newline should succeed' '
469 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
470 get_tag_msg blanknonlfile-annotated-tag >actual &&
471 test_cmp expect actual
474 # messages with commented lines:
476 cat >commentsfile <<EOF
477 # A comment
479 ############
480 The message.
481 ############
482 One line.
485 # commented lines
486 # commented lines
488 Another line.
489 # comments
491 Last line.
493 get_tag_header comments-annotated-tag $commit commit $time >expect
494 cat >>expect <<EOF
495 The message.
496 One line.
498 Another line.
500 Last line.
502 test_expect_success \
503 'creating a tag using a -F messagefile with #comments should succeed' '
504 git tag -F commentsfile comments-annotated-tag &&
505 get_tag_msg comments-annotated-tag >actual &&
506 test_cmp expect actual
509 get_tag_header comment-annotated-tag $commit commit $time >expect
510 test_expect_success \
511 'creating a tag with a #comment in the -m message should succeed' '
512 git tag -m "#comment" comment-annotated-tag &&
513 get_tag_msg comment-annotated-tag >actual &&
514 test_cmp expect actual
517 echo '#comment' >commentfile
518 echo '' >>commentfile
519 echo '####' >>commentfile
520 get_tag_header commentfile-annotated-tag $commit commit $time >expect
521 test_expect_success \
522 'creating a tag with #comments in the -F messagefile should succeed' '
523 git tag -F commentfile commentfile-annotated-tag &&
524 get_tag_msg commentfile-annotated-tag >actual &&
525 test_cmp expect actual
528 printf '#comment' >commentnonlfile
529 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
530 test_expect_success \
531 'creating a tag with a file of #comment and no newline should succeed' '
532 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
533 get_tag_msg commentnonlfile-annotated-tag >actual &&
534 test_cmp expect actual
537 # listing messages for annotated non-signed tags:
539 test_expect_success \
540 'listing the one-line message of a non-signed tag should succeed' '
541 git tag -m "A msg" tag-one-line &&
543 echo "tag-one-line" >expect &&
544 git tag -l | grep "^tag-one-line" >actual &&
545 test_cmp expect actual &&
546 git tag -n0 -l | grep "^tag-one-line" >actual &&
547 test_cmp expect actual &&
548 git tag -n0 -l tag-one-line >actual &&
549 test_cmp expect actual &&
551 echo "tag-one-line A msg" >expect &&
552 git tag -n1 -l | grep "^tag-one-line" >actual &&
553 test_cmp expect actual &&
554 git tag -n -l | grep "^tag-one-line" >actual &&
555 test_cmp expect actual &&
556 git tag -n1 -l tag-one-line >actual &&
557 test_cmp expect actual &&
558 git tag -n2 -l tag-one-line >actual &&
559 test_cmp expect actual &&
560 git tag -n999 -l tag-one-line >actual &&
561 test_cmp expect actual
564 test_expect_success \
565 'listing the zero-lines message of a non-signed tag should succeed' '
566 git tag -m "" tag-zero-lines &&
568 echo "tag-zero-lines" >expect &&
569 git tag -l | grep "^tag-zero-lines" >actual &&
570 test_cmp expect actual &&
571 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
572 test_cmp expect actual &&
573 git tag -n0 -l tag-zero-lines >actual &&
574 test_cmp expect actual &&
576 echo "tag-zero-lines " >expect &&
577 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
578 test_cmp expect actual &&
579 git tag -n -l | grep "^tag-zero-lines" >actual &&
580 test_cmp expect actual &&
581 git tag -n1 -l tag-zero-lines >actual &&
582 test_cmp expect actual &&
583 git tag -n2 -l tag-zero-lines >actual &&
584 test_cmp expect actual &&
585 git tag -n999 -l tag-zero-lines >actual &&
586 test_cmp expect actual
589 echo 'tag line one' >annotagmsg
590 echo 'tag line two' >>annotagmsg
591 echo 'tag line three' >>annotagmsg
592 test_expect_success \
593 'listing many message lines of a non-signed tag should succeed' '
594 git tag -F annotagmsg tag-lines &&
596 echo "tag-lines" >expect &&
597 git tag -l | grep "^tag-lines" >actual &&
598 test_cmp expect actual &&
599 git tag -n0 -l | grep "^tag-lines" >actual &&
600 test_cmp expect actual &&
601 git tag -n0 -l tag-lines >actual &&
602 test_cmp expect actual &&
604 echo "tag-lines tag line one" >expect &&
605 git tag -n1 -l | grep "^tag-lines" >actual &&
606 test_cmp expect actual &&
607 git tag -n -l | grep "^tag-lines" >actual &&
608 test_cmp expect actual &&
609 git tag -n1 -l tag-lines >actual &&
610 test_cmp expect actual &&
612 echo " tag line two" >>expect &&
613 git tag -n2 -l | grep "^ *tag.line" >actual &&
614 test_cmp expect actual &&
615 git tag -n2 -l tag-lines >actual &&
616 test_cmp expect actual &&
618 echo " tag line three" >>expect &&
619 git tag -n3 -l | grep "^ *tag.line" >actual &&
620 test_cmp expect actual &&
621 git tag -n3 -l tag-lines >actual &&
622 test_cmp expect actual &&
623 git tag -n4 -l | grep "^ *tag.line" >actual &&
624 test_cmp expect actual &&
625 git tag -n4 -l tag-lines >actual &&
626 test_cmp expect actual &&
627 git tag -n99 -l | grep "^ *tag.line" >actual &&
628 test_cmp expect actual &&
629 git tag -n99 -l tag-lines >actual &&
630 test_cmp expect actual
633 test_expect_success 'annotations for blobs are empty' '
634 blob=$(git hash-object -w --stdin <<-\EOF
635 Blob paragraph 1.
637 Blob paragraph 2.
639 ) &&
640 git tag tag-blob $blob &&
641 echo "tag-blob " >expect &&
642 git tag -n1 -l tag-blob >actual &&
643 test_cmp expect actual
646 # trying to verify annotated non-signed tags:
648 test_expect_success GPG \
649 'trying to verify an annotated non-signed tag should fail' '
650 tag_exists annotated-tag &&
651 test_must_fail git tag -v annotated-tag
654 test_expect_success GPG \
655 'trying to verify a file-annotated non-signed tag should fail' '
656 tag_exists file-annotated-tag &&
657 test_must_fail git tag -v file-annotated-tag
660 test_expect_success GPG \
661 'trying to verify two annotated non-signed tags should fail' '
662 tag_exists annotated-tag file-annotated-tag &&
663 test_must_fail git tag -v annotated-tag file-annotated-tag
666 # creating and verifying signed tags:
668 get_tag_header signed-tag $commit commit $time >expect
669 echo 'A signed tag message' >>expect
670 echo '-----BEGIN PGP SIGNATURE-----' >>expect
671 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
672 git tag -s -m "A signed tag message" signed-tag &&
673 get_tag_msg signed-tag >actual &&
674 test_cmp expect actual
677 get_tag_header u-signed-tag $commit commit $time >expect
678 echo 'Another message' >>expect
679 echo '-----BEGIN PGP SIGNATURE-----' >>expect
680 test_expect_success GPG 'sign with a given key id' '
682 git tag -u committer@example.com -m "Another message" u-signed-tag &&
683 get_tag_msg u-signed-tag >actual &&
684 test_cmp expect actual
688 test_expect_success GPG 'sign with an unknown id (1)' '
690 test_must_fail git tag -u author@example.com \
691 -m "Another message" o-signed-tag
695 test_expect_success GPG 'sign with an unknown id (2)' '
697 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
701 cat >fakeeditor <<'EOF'
702 #!/bin/sh
703 test -n "$1" && exec >"$1"
704 echo A signed tag message
705 echo from a fake editor.
707 chmod +x fakeeditor
709 get_tag_header implied-sign $commit commit $time >expect
710 ./fakeeditor >>expect
711 echo '-----BEGIN PGP SIGNATURE-----' >>expect
712 test_expect_success GPG '-u implies signed tag' '
713 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
714 get_tag_msg implied-sign >actual &&
715 test_cmp expect actual
718 cat >sigmsgfile <<EOF
719 Another signed tag
720 message in a file.
722 get_tag_header file-signed-tag $commit commit $time >expect
723 cat sigmsgfile >>expect
724 echo '-----BEGIN PGP SIGNATURE-----' >>expect
725 test_expect_success GPG \
726 'creating a signed tag with -F messagefile should succeed' '
727 git tag -s -F sigmsgfile file-signed-tag &&
728 get_tag_msg file-signed-tag >actual &&
729 test_cmp expect actual
732 cat >siginputmsg <<EOF
733 A signed tag message from
734 the standard input
736 get_tag_header stdin-signed-tag $commit commit $time >expect
737 cat siginputmsg >>expect
738 echo '-----BEGIN PGP SIGNATURE-----' >>expect
739 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
740 git tag -s -F - stdin-signed-tag <siginputmsg &&
741 get_tag_msg stdin-signed-tag >actual &&
742 test_cmp expect actual
745 get_tag_header implied-annotate $commit commit $time >expect
746 ./fakeeditor >>expect
747 echo '-----BEGIN PGP SIGNATURE-----' >>expect
748 test_expect_success GPG '-s implies annotated tag' '
749 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
750 get_tag_msg implied-annotate >actual &&
751 test_cmp expect actual
754 test_expect_success GPG \
755 'trying to create a signed tag with non-existing -F file should fail' '
756 ! test -f nonexistingfile &&
757 ! tag_exists nosigtag &&
758 test_must_fail git tag -s -F nonexistingfile nosigtag &&
759 ! tag_exists nosigtag
762 test_expect_success GPG 'verifying a signed tag should succeed' \
763 'git tag -v signed-tag'
765 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
766 'git tag -v signed-tag file-signed-tag'
768 test_expect_success GPG \
769 'verifying many signed and non-signed tags should fail' '
770 test_must_fail git tag -v signed-tag annotated-tag &&
771 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
772 test_must_fail git tag -v annotated-tag \
773 file-signed-tag file-annotated-tag &&
774 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
777 test_expect_success GPG 'verifying a forged tag should fail' '
778 forged=$(git cat-file tag signed-tag |
779 sed -e "s/signed-tag/forged-tag/" |
780 git mktag) &&
781 git tag forged-tag $forged &&
782 test_must_fail git tag -v forged-tag
785 # blank and empty messages for signed tags:
787 get_tag_header empty-signed-tag $commit commit $time >expect
788 echo '-----BEGIN PGP SIGNATURE-----' >>expect
789 test_expect_success GPG \
790 'creating a signed tag with an empty -m message should succeed' '
791 git tag -s -m "" empty-signed-tag &&
792 get_tag_msg empty-signed-tag >actual &&
793 test_cmp expect actual &&
794 git tag -v empty-signed-tag
797 >sigemptyfile
798 get_tag_header emptyfile-signed-tag $commit commit $time >expect
799 echo '-----BEGIN PGP SIGNATURE-----' >>expect
800 test_expect_success GPG \
801 'creating a signed tag with an empty -F messagefile should succeed' '
802 git tag -s -F sigemptyfile emptyfile-signed-tag &&
803 get_tag_msg emptyfile-signed-tag >actual &&
804 test_cmp expect actual &&
805 git tag -v emptyfile-signed-tag
808 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
809 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
810 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
811 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
812 get_tag_header blanks-signed-tag $commit commit $time >expect
813 cat >>expect <<EOF
814 Leading blank lines
816 Repeated blank lines
818 Trailing spaces
820 Trailing blank lines
822 echo '-----BEGIN PGP SIGNATURE-----' >>expect
823 test_expect_success GPG \
824 'extra blanks in the message for a signed tag should be removed' '
825 git tag -s -F sigblanksfile blanks-signed-tag &&
826 get_tag_msg blanks-signed-tag >actual &&
827 test_cmp expect actual &&
828 git tag -v blanks-signed-tag
831 get_tag_header blank-signed-tag $commit commit $time >expect
832 echo '-----BEGIN PGP SIGNATURE-----' >>expect
833 test_expect_success GPG \
834 'creating a signed tag with a blank -m message should succeed' '
835 git tag -s -m " " blank-signed-tag &&
836 get_tag_msg blank-signed-tag >actual &&
837 test_cmp expect actual &&
838 git tag -v blank-signed-tag
841 echo ' ' >sigblankfile
842 echo '' >>sigblankfile
843 echo ' ' >>sigblankfile
844 get_tag_header blankfile-signed-tag $commit commit $time >expect
845 echo '-----BEGIN PGP SIGNATURE-----' >>expect
846 test_expect_success GPG \
847 'creating a signed tag with blank -F file with spaces should succeed' '
848 git tag -s -F sigblankfile blankfile-signed-tag &&
849 get_tag_msg blankfile-signed-tag >actual &&
850 test_cmp expect actual &&
851 git tag -v blankfile-signed-tag
854 printf ' ' >sigblanknonlfile
855 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
856 echo '-----BEGIN PGP SIGNATURE-----' >>expect
857 test_expect_success GPG \
858 'creating a signed tag with spaces and no newline should succeed' '
859 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
860 get_tag_msg blanknonlfile-signed-tag >actual &&
861 test_cmp expect actual &&
862 git tag -v signed-tag
865 # messages with commented lines for signed tags:
867 cat >sigcommentsfile <<EOF
868 # A comment
870 ############
871 The message.
872 ############
873 One line.
876 # commented lines
877 # commented lines
879 Another line.
880 # comments
882 Last line.
884 get_tag_header comments-signed-tag $commit commit $time >expect
885 cat >>expect <<EOF
886 The message.
887 One line.
889 Another line.
891 Last line.
893 echo '-----BEGIN PGP SIGNATURE-----' >>expect
894 test_expect_success GPG \
895 'creating a signed tag with a -F file with #comments should succeed' '
896 git tag -s -F sigcommentsfile comments-signed-tag &&
897 get_tag_msg comments-signed-tag >actual &&
898 test_cmp expect actual &&
899 git tag -v comments-signed-tag
902 get_tag_header comment-signed-tag $commit commit $time >expect
903 echo '-----BEGIN PGP SIGNATURE-----' >>expect
904 test_expect_success GPG \
905 'creating a signed tag with #commented -m message should succeed' '
906 git tag -s -m "#comment" comment-signed-tag &&
907 get_tag_msg comment-signed-tag >actual &&
908 test_cmp expect actual &&
909 git tag -v comment-signed-tag
912 echo '#comment' >sigcommentfile
913 echo '' >>sigcommentfile
914 echo '####' >>sigcommentfile
915 get_tag_header commentfile-signed-tag $commit commit $time >expect
916 echo '-----BEGIN PGP SIGNATURE-----' >>expect
917 test_expect_success GPG \
918 'creating a signed tag with #commented -F messagefile should succeed' '
919 git tag -s -F sigcommentfile commentfile-signed-tag &&
920 get_tag_msg commentfile-signed-tag >actual &&
921 test_cmp expect actual &&
922 git tag -v commentfile-signed-tag
925 printf '#comment' >sigcommentnonlfile
926 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
927 echo '-----BEGIN PGP SIGNATURE-----' >>expect
928 test_expect_success GPG \
929 'creating a signed tag with a #comment and no newline should succeed' '
930 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
931 get_tag_msg commentnonlfile-signed-tag >actual &&
932 test_cmp expect actual &&
933 git tag -v commentnonlfile-signed-tag
936 # listing messages for signed tags:
938 test_expect_success GPG \
939 'listing the one-line message of a signed tag should succeed' '
940 git tag -s -m "A message line signed" stag-one-line &&
942 echo "stag-one-line" >expect &&
943 git tag -l | grep "^stag-one-line" >actual &&
944 test_cmp expect actual &&
945 git tag -n0 -l | grep "^stag-one-line" >actual &&
946 test_cmp expect actual &&
947 git tag -n0 -l stag-one-line >actual &&
948 test_cmp expect actual &&
950 echo "stag-one-line A message line signed" >expect &&
951 git tag -n1 -l | grep "^stag-one-line" >actual &&
952 test_cmp expect actual &&
953 git tag -n -l | grep "^stag-one-line" >actual &&
954 test_cmp expect actual &&
955 git tag -n1 -l stag-one-line >actual &&
956 test_cmp expect actual &&
957 git tag -n2 -l stag-one-line >actual &&
958 test_cmp expect actual &&
959 git tag -n999 -l stag-one-line >actual &&
960 test_cmp expect actual
963 test_expect_success GPG \
964 'listing the zero-lines message of a signed tag should succeed' '
965 git tag -s -m "" stag-zero-lines &&
967 echo "stag-zero-lines" >expect &&
968 git tag -l | grep "^stag-zero-lines" >actual &&
969 test_cmp expect actual &&
970 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
971 test_cmp expect actual &&
972 git tag -n0 -l stag-zero-lines >actual &&
973 test_cmp expect actual &&
975 echo "stag-zero-lines " >expect &&
976 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
977 test_cmp expect actual &&
978 git tag -n -l | grep "^stag-zero-lines" >actual &&
979 test_cmp expect actual &&
980 git tag -n1 -l stag-zero-lines >actual &&
981 test_cmp expect actual &&
982 git tag -n2 -l stag-zero-lines >actual &&
983 test_cmp expect actual &&
984 git tag -n999 -l stag-zero-lines >actual &&
985 test_cmp expect actual
988 echo 'stag line one' >sigtagmsg
989 echo 'stag line two' >>sigtagmsg
990 echo 'stag line three' >>sigtagmsg
991 test_expect_success GPG \
992 'listing many message lines of a signed tag should succeed' '
993 git tag -s -F sigtagmsg stag-lines &&
995 echo "stag-lines" >expect &&
996 git tag -l | grep "^stag-lines" >actual &&
997 test_cmp expect actual &&
998 git tag -n0 -l | grep "^stag-lines" >actual &&
999 test_cmp expect actual &&
1000 git tag -n0 -l stag-lines >actual &&
1001 test_cmp expect actual &&
1003 echo "stag-lines stag line one" >expect &&
1004 git tag -n1 -l | grep "^stag-lines" >actual &&
1005 test_cmp expect actual &&
1006 git tag -n -l | grep "^stag-lines" >actual &&
1007 test_cmp expect actual &&
1008 git tag -n1 -l stag-lines >actual &&
1009 test_cmp expect actual &&
1011 echo " stag line two" >>expect &&
1012 git tag -n2 -l | grep "^ *stag.line" >actual &&
1013 test_cmp expect actual &&
1014 git tag -n2 -l stag-lines >actual &&
1015 test_cmp expect actual &&
1017 echo " stag line three" >>expect &&
1018 git tag -n3 -l | grep "^ *stag.line" >actual &&
1019 test_cmp expect actual &&
1020 git tag -n3 -l stag-lines >actual &&
1021 test_cmp expect actual &&
1022 git tag -n4 -l | grep "^ *stag.line" >actual &&
1023 test_cmp expect actual &&
1024 git tag -n4 -l stag-lines >actual &&
1025 test_cmp expect actual &&
1026 git tag -n99 -l | grep "^ *stag.line" >actual &&
1027 test_cmp expect actual &&
1028 git tag -n99 -l stag-lines >actual &&
1029 test_cmp expect actual
1032 # tags pointing to objects different from commits:
1034 tree=$(git rev-parse HEAD^{tree})
1035 blob=$(git rev-parse HEAD:foo)
1036 tag=$(git rev-parse signed-tag 2>/dev/null)
1038 get_tag_header tree-signed-tag $tree tree $time >expect
1039 echo "A message for a tree" >>expect
1040 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1041 test_expect_success GPG \
1042 'creating a signed tag pointing to a tree should succeed' '
1043 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1044 get_tag_msg tree-signed-tag >actual &&
1045 test_cmp expect actual
1048 get_tag_header blob-signed-tag $blob blob $time >expect
1049 echo "A message for a blob" >>expect
1050 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1051 test_expect_success GPG \
1052 'creating a signed tag pointing to a blob should succeed' '
1053 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1054 get_tag_msg blob-signed-tag >actual &&
1055 test_cmp expect actual
1058 get_tag_header tag-signed-tag $tag tag $time >expect
1059 echo "A message for another tag" >>expect
1060 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1061 test_expect_success GPG \
1062 'creating a signed tag pointing to another tag should succeed' '
1063 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1064 get_tag_msg tag-signed-tag >actual &&
1065 test_cmp expect actual
1068 # usage with rfc1991 signatures
1069 echo "rfc1991" > gpghome/gpg.conf
1070 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1071 echo "RFC1991 signed tag" >>expect
1072 echo '-----BEGIN PGP MESSAGE-----' >>expect
1073 test_expect_success GPG \
1074 'creating a signed tag with rfc1991' '
1075 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1076 get_tag_msg rfc1991-signed-tag >actual &&
1077 test_cmp expect actual
1080 cat >fakeeditor <<'EOF'
1081 #!/bin/sh
1082 cp "$1" actual
1084 chmod +x fakeeditor
1086 test_expect_success GPG \
1087 'reediting a signed tag body omits signature' '
1088 echo "RFC1991 signed tag" >expect &&
1089 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1090 test_cmp expect actual
1093 test_expect_success GPG \
1094 'verifying rfc1991 signature' '
1095 git tag -v rfc1991-signed-tag
1098 test_expect_success GPG \
1099 'list tag with rfc1991 signature' '
1100 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1101 git tag -l -n1 rfc1991-signed-tag >actual &&
1102 test_cmp expect actual &&
1103 git tag -l -n2 rfc1991-signed-tag >actual &&
1104 test_cmp expect actual &&
1105 git tag -l -n999 rfc1991-signed-tag >actual &&
1106 test_cmp expect actual
1109 rm -f gpghome/gpg.conf
1111 test_expect_success GPG \
1112 'verifying rfc1991 signature without --rfc1991' '
1113 git tag -v rfc1991-signed-tag
1116 test_expect_success GPG \
1117 'list tag with rfc1991 signature without --rfc1991' '
1118 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1119 git tag -l -n1 rfc1991-signed-tag >actual &&
1120 test_cmp expect actual &&
1121 git tag -l -n2 rfc1991-signed-tag >actual &&
1122 test_cmp expect actual &&
1123 git tag -l -n999 rfc1991-signed-tag >actual &&
1124 test_cmp expect actual
1127 test_expect_success GPG \
1128 'reediting a signed tag body omits signature' '
1129 echo "RFC1991 signed tag" >expect &&
1130 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1131 test_cmp expect actual
1134 # try to sign with bad user.signingkey
1135 git config user.signingkey BobTheMouse
1136 test_expect_success GPG \
1137 'git tag -s fails if gpg is misconfigured' \
1138 'test_must_fail git tag -s -m tail tag-gpg-failure'
1139 git config --unset user.signingkey
1141 # try to verify without gpg:
1143 rm -rf gpghome
1144 test_expect_success GPG \
1145 'verify signed tag fails when public key is not present' \
1146 'test_must_fail git tag -v signed-tag'
1148 test_expect_success \
1149 'git tag -a fails if tag annotation is empty' '
1150 ! (GIT_EDITOR=cat git tag -a initial-comment)
1153 test_expect_success \
1154 'message in editor has initial comment' '
1155 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1158 test_expect_success 'message in editor has initial comment: first line' '
1159 # check the first line --- should be empty
1160 echo >first.expect &&
1161 sed -e 1q <actual >first.actual &&
1162 test_i18ncmp first.expect first.actual
1165 test_expect_success \
1166 'message in editor has initial comment: remainder' '
1167 # remove commented lines from the remainder -- should be empty
1168 >rest.expect
1169 sed -e 1d -e '/^#/d' <actual >rest.actual &&
1170 test_cmp rest.expect rest.actual
1173 get_tag_header reuse $commit commit $time >expect
1174 echo "An annotation to be reused" >> expect
1175 test_expect_success \
1176 'overwriting an annoted tag should use its previous body' '
1177 git tag -a -m "An annotation to be reused" reuse &&
1178 GIT_EDITOR=true git tag -f -a reuse &&
1179 get_tag_msg reuse >actual &&
1180 test_cmp expect actual
1183 test_expect_success 'filename for the message is relative to cwd' '
1184 mkdir subdir &&
1185 echo "Tag message in top directory" >msgfile-5 &&
1186 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1188 cd subdir &&
1189 git tag -a -F msgfile-5 tag-from-subdir
1190 ) &&
1191 git cat-file tag tag-from-subdir | grep "in sub directory"
1194 test_expect_success 'filename for the message is relative to cwd' '
1195 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1197 cd subdir &&
1198 git tag -a -F msgfile-6 tag-from-subdir-2
1199 ) &&
1200 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1203 # create a few more commits to test --contains
1205 hash1=$(git rev-parse HEAD)
1207 test_expect_success 'creating second commit and tag' '
1208 echo foo-2.0 >foo &&
1209 git add foo &&
1210 git commit -m second &&
1211 git tag v2.0
1214 hash2=$(git rev-parse HEAD)
1216 test_expect_success 'creating third commit without tag' '
1217 echo foo-dev >foo &&
1218 git add foo &&
1219 git commit -m third
1222 hash3=$(git rev-parse HEAD)
1224 # simple linear checks of --continue
1226 cat > expected <<EOF
1227 v0.2.1
1228 v1.0
1229 v1.0.1
1230 v1.1.3
1231 v2.0
1234 test_expect_success 'checking that first commit is in all tags (hash)' "
1235 git tag -l --contains $hash1 v* >actual &&
1236 test_cmp expected actual
1239 # other ways of specifying the commit
1240 test_expect_success 'checking that first commit is in all tags (tag)' "
1241 git tag -l --contains v1.0 v* >actual &&
1242 test_cmp expected actual
1245 test_expect_success 'checking that first commit is in all tags (relative)' "
1246 git tag -l --contains HEAD~2 v* >actual &&
1247 test_cmp expected actual
1250 cat > expected <<EOF
1251 v2.0
1254 test_expect_success 'checking that second commit only has one tag' "
1255 git tag -l --contains $hash2 v* >actual &&
1256 test_cmp expected actual
1260 cat > expected <<EOF
1263 test_expect_success 'checking that third commit has no tags' "
1264 git tag -l --contains $hash3 v* >actual &&
1265 test_cmp expected actual
1268 # how about a simple merge?
1270 test_expect_success 'creating simple branch' '
1271 git branch stable v2.0 &&
1272 git checkout stable &&
1273 echo foo-3.0 > foo &&
1274 git commit foo -m fourth &&
1275 git tag v3.0
1278 hash4=$(git rev-parse HEAD)
1280 cat > expected <<EOF
1281 v3.0
1284 test_expect_success 'checking that branch head only has one tag' "
1285 git tag -l --contains $hash4 v* >actual &&
1286 test_cmp expected actual
1289 test_expect_success 'merging original branch into this branch' '
1290 git merge --strategy=ours master &&
1291 git tag v4.0
1294 cat > expected <<EOF
1295 v4.0
1298 test_expect_success 'checking that original branch head has one tag now' "
1299 git tag -l --contains $hash3 v* >actual &&
1300 test_cmp expected actual
1303 cat > expected <<EOF
1304 v0.2.1
1305 v1.0
1306 v1.0.1
1307 v1.1.3
1308 v2.0
1309 v3.0
1310 v4.0
1313 test_expect_success 'checking that initial commit is in all tags' "
1314 git tag -l --contains $hash1 v* >actual &&
1315 test_cmp expected actual
1318 # mixing modes and options:
1320 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1321 test_must_fail git tag -a &&
1322 test_must_fail git tag -l -v &&
1323 test_must_fail git tag -n 100 &&
1324 test_must_fail git tag -l -m msg &&
1325 test_must_fail git tag -l -F some file &&
1326 test_must_fail git tag -v -s
1329 # check points-at
1331 test_expect_success '--points-at cannot be used in non-list mode' '
1332 test_must_fail git tag --points-at=v4.0 foo
1335 test_expect_success '--points-at finds lightweight tags' '
1336 echo v4.0 >expect &&
1337 git tag --points-at v4.0 >actual &&
1338 test_cmp expect actual
1341 test_expect_success '--points-at finds annotated tags of commits' '
1342 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1343 echo annotated-v4.0 >expect &&
1344 git tag -l --points-at v4.0 "annotated*" >actual &&
1345 test_cmp expect actual
1348 test_expect_success '--points-at finds annotated tags of tags' '
1349 git tag -m "describing the v4.0 tag object" \
1350 annotated-again-v4.0 annotated-v4.0 &&
1351 cat >expect <<-\EOF &&
1352 annotated-again-v4.0
1353 annotated-v4.0
1355 git tag --points-at=annotated-v4.0 >actual &&
1356 test_cmp expect actual
1359 test_expect_success 'multiple --points-at are OR-ed together' '
1360 cat >expect <<-\EOF &&
1361 v2.0
1362 v3.0
1364 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1365 test_cmp expect actual
1368 test_done