Merge branch 'bw/ref-prefix-for-configured-refspec'
[git/raj.git] / t / t7004-tag.sh
blobd7b319e919c83ca677737840f70075c173364209
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
12 . "$TEST_DIRECTORY"/lib-terminal.sh
14 # creating and listing lightweight tags:
16 tag_exists () {
17 git show-ref --quiet --verify refs/tags/"$1"
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 'sort tags, ignore case' '
32 git init sort &&
33 cd sort &&
34 test_commit initial &&
35 git tag tag-one &&
36 git tag TAG-two &&
37 git tag -l >actual &&
38 cat >expected <<-\EOF &&
39 TAG-two
40 initial
41 tag-one
42 EOF
43 test_cmp expected actual &&
44 git tag -l -i >actual &&
45 cat >expected <<-\EOF &&
46 initial
47 tag-one
48 TAG-two
49 EOF
50 test_cmp expected actual
54 test_expect_success 'looking for a tag in an empty tree should fail' \
55 '! (tag_exists mytag)'
57 test_expect_success 'creating a tag in an empty tree should fail' '
58 test_must_fail git tag mynotag &&
59 ! tag_exists mynotag
62 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
63 test_must_fail git tag mytaghead HEAD &&
64 ! tag_exists mytaghead
67 test_expect_success 'creating a tag for an unknown revision should fail' '
68 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
69 ! tag_exists mytagnorev
72 # commit used in the tests, test_tick is also called here to freeze the date:
73 test_expect_success 'creating a tag using default HEAD should succeed' '
74 test_config core.logAllRefUpdates true &&
75 test_tick &&
76 echo foo >foo &&
77 git add foo &&
78 git commit -m Foo &&
79 git tag mytag &&
80 test_must_fail git reflog exists refs/tags/mytag
83 test_expect_success 'creating a tag with --create-reflog should create reflog' '
84 git log -1 \
85 --format="format:tag: tagging %h (%s, %cd)%n" \
86 --date=format:%Y-%m-%d >expected &&
87 test_when_finished "git tag -d tag_with_reflog" &&
88 git tag --create-reflog tag_with_reflog &&
89 git reflog exists refs/tags/tag_with_reflog &&
90 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
91 test_i18ncmp expected actual
94 test_expect_success 'annotated tag with --create-reflog has correct message' '
95 git log -1 \
96 --format="format:tag: tagging %h (%s, %cd)%n" \
97 --date=format:%Y-%m-%d >expected &&
98 test_when_finished "git tag -d tag_with_reflog" &&
99 git tag -m "annotated tag" --create-reflog tag_with_reflog &&
100 git reflog exists refs/tags/tag_with_reflog &&
101 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
102 test_i18ncmp expected actual
105 test_expect_success '--create-reflog does not create reflog on failure' '
106 test_must_fail git tag --create-reflog mytag &&
107 test_must_fail git reflog exists refs/tags/mytag
110 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
111 test_when_finished "git tag -d tag_with_reflog" &&
112 test_config core.logAllRefUpdates always &&
113 git tag tag_with_reflog &&
114 git reflog exists refs/tags/tag_with_reflog
117 test_expect_success 'listing all tags if one exists should succeed' '
118 git tag -l &&
119 git tag
122 cat >expect <<EOF
123 mytag
125 test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
126 git tag -l -l >actual &&
127 test_cmp expect actual &&
128 git tag --list --list >actual &&
129 test_cmp expect actual &&
130 git tag --list -l --list >actual &&
131 test_cmp expect actual
134 test_expect_success 'listing all tags if one exists should output that tag' '
135 test $(git tag -l) = mytag &&
136 test $(git tag) = mytag
139 # pattern matching:
141 test_expect_success 'listing a tag using a matching pattern should succeed' \
142 'git tag -l mytag'
144 test_expect_success 'listing a tag with --ignore-case' \
145 'test $(git tag -l --ignore-case MYTAG) = mytag'
147 test_expect_success \
148 'listing a tag using a matching pattern should output that tag' \
149 'test $(git tag -l mytag) = mytag'
151 test_expect_success \
152 'listing tags using a non-matching pattern should succeed' \
153 'git tag -l xxx'
155 test_expect_success \
156 'listing tags using a non-matching pattern should output nothing' \
157 'test $(git tag -l xxx | wc -l) -eq 0'
159 # special cases for creating tags:
161 test_expect_success \
162 'trying to create a tag with the name of one existing should fail' \
163 'test_must_fail git tag mytag'
165 test_expect_success \
166 'trying to create a tag with a non-valid name should fail' '
167 test $(git tag -l | wc -l) -eq 1 &&
168 test_must_fail git tag "" &&
169 test_must_fail git tag .othertag &&
170 test_must_fail git tag "other tag" &&
171 test_must_fail git tag "othertag^" &&
172 test_must_fail git tag "other~tag" &&
173 test $(git tag -l | wc -l) -eq 1
176 test_expect_success 'creating a tag using HEAD directly should succeed' '
177 git tag myhead HEAD &&
178 tag_exists myhead
181 test_expect_success '--force can create a tag with the name of one existing' '
182 tag_exists mytag &&
183 git tag --force mytag &&
184 tag_exists mytag'
186 test_expect_success '--force is moot with a non-existing tag name' '
187 test_when_finished git tag -d newtag forcetag &&
188 git tag newtag >expect &&
189 git tag --force forcetag >actual &&
190 test_cmp expect actual
193 # deleting tags:
195 test_expect_success 'trying to delete an unknown tag should fail' '
196 ! tag_exists unknown-tag &&
197 test_must_fail git tag -d unknown-tag
200 cat >expect <<EOF
201 myhead
202 mytag
204 test_expect_success \
205 'trying to delete tags without params should succeed and do nothing' '
206 git tag -l > actual && test_cmp expect actual &&
207 git tag -d &&
208 git tag -l > actual && test_cmp expect actual
211 test_expect_success \
212 'deleting two existing tags in one command should succeed' '
213 tag_exists mytag &&
214 tag_exists myhead &&
215 git tag -d mytag myhead &&
216 ! tag_exists mytag &&
217 ! tag_exists myhead
220 test_expect_success \
221 'creating a tag with the name of another deleted one should succeed' '
222 ! tag_exists mytag &&
223 git tag mytag &&
224 tag_exists mytag
227 test_expect_success \
228 'trying to delete two tags, existing and not, should fail in the 2nd' '
229 tag_exists mytag &&
230 ! tag_exists myhead &&
231 test_must_fail git tag -d mytag anothertag &&
232 ! tag_exists mytag &&
233 ! tag_exists myhead
236 test_expect_success 'trying to delete an already deleted tag should fail' \
237 'test_must_fail git tag -d mytag'
239 # listing various tags with pattern matching:
241 cat >expect <<EOF
245 t210
246 t211
247 v0.2.1
248 v1.0
249 v1.0.1
250 v1.1.3
252 test_expect_success 'listing all tags should print them ordered' '
253 git tag v1.0.1 &&
254 git tag t211 &&
255 git tag aa1 &&
256 git tag v0.2.1 &&
257 git tag v1.1.3 &&
258 git tag cba &&
259 git tag a1 &&
260 git tag v1.0 &&
261 git tag t210 &&
262 git tag -l > actual &&
263 test_cmp expect actual &&
264 git tag > actual &&
265 test_cmp expect actual
268 cat >expect <<EOF
273 test_expect_success \
274 'listing tags with substring as pattern must print those matching' '
275 rm *a* &&
276 git tag -l "*a*" > current &&
277 test_cmp expect current
280 cat >expect <<EOF
281 v0.2.1
282 v1.0.1
284 test_expect_success \
285 'listing tags with a suffix as pattern must print those matching' '
286 git tag -l "*.1" > actual &&
287 test_cmp expect actual
290 cat >expect <<EOF
291 t210
292 t211
294 test_expect_success \
295 'listing tags with a prefix as pattern must print those matching' '
296 git tag -l "t21*" > actual &&
297 test_cmp expect actual
300 cat >expect <<EOF
303 test_expect_success \
304 'listing tags using a name as pattern must print that one matching' '
305 git tag -l a1 > actual &&
306 test_cmp expect actual
309 cat >expect <<EOF
310 v1.0
312 test_expect_success \
313 'listing tags using a name as pattern must print that one matching' '
314 git tag -l v1.0 > actual &&
315 test_cmp expect actual
318 cat >expect <<EOF
319 v1.0.1
320 v1.1.3
322 test_expect_success \
323 'listing tags with ? in the pattern should print those matching' '
324 git tag -l "v1.?.?" > actual &&
325 test_cmp expect actual
328 >expect
329 test_expect_success \
330 'listing tags using v.* should print nothing because none have v.' '
331 git tag -l "v.*" > actual &&
332 test_cmp expect actual
335 cat >expect <<EOF
336 v0.2.1
337 v1.0
338 v1.0.1
339 v1.1.3
341 test_expect_success \
342 'listing tags using v* should print only those having v' '
343 git tag -l "v*" > actual &&
344 test_cmp expect actual
347 test_expect_success 'tag -l can accept multiple patterns' '
348 git tag -l "v1*" "v0*" >actual &&
349 test_cmp expect actual
352 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
353 # could leave you with the impression that "-l <pattern> -l <pattern>"
354 # was how we wanted to accept multiple patterns.
356 # This test should not imply that this is a sane thing to support. but
357 # since the documentation was worded like it was let's at least find
358 # out if we're going to break this long-documented form of taking
359 # multiple patterns.
360 test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
361 git tag -l "v1*" -l "v0*" >actual &&
362 test_cmp expect actual
365 test_expect_success 'listing tags in column' '
366 COLUMNS=41 git tag -l --column=row >actual &&
367 cat >expected <<\EOF &&
368 a1 aa1 cba t210 t211
369 v0.2.1 v1.0 v1.0.1 v1.1.3
371 test_cmp expected actual
374 test_expect_success 'listing tags in column with column.*' '
375 test_config column.tag row &&
376 test_config column.ui dense &&
377 COLUMNS=40 git tag -l >actual &&
378 cat >expected <<\EOF &&
379 a1 aa1 cba t210 t211
380 v0.2.1 v1.0 v1.0.1 v1.1.3
382 test_cmp expected actual
385 test_expect_success 'listing tag with -n --column should fail' '
386 test_must_fail git tag --column -n
389 test_expect_success 'listing tags -n in column with column.ui ignored' '
390 test_config column.ui "row dense" &&
391 COLUMNS=40 git tag -l -n >actual &&
392 cat >expected <<\EOF &&
393 a1 Foo
394 aa1 Foo
395 cba Foo
396 t210 Foo
397 t211 Foo
398 v0.2.1 Foo
399 v1.0 Foo
400 v1.0.1 Foo
401 v1.1.3 Foo
403 test_cmp expected actual
406 # creating and verifying lightweight tags:
408 test_expect_success \
409 'a non-annotated tag created without parameters should point to HEAD' '
410 git tag non-annotated-tag &&
411 test $(git cat-file -t non-annotated-tag) = commit &&
412 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
415 test_expect_success 'trying to verify an unknown tag should fail' \
416 'test_must_fail git tag -v unknown-tag'
418 test_expect_success \
419 'trying to verify a non-annotated and non-signed tag should fail' \
420 'test_must_fail git tag -v non-annotated-tag'
422 test_expect_success \
423 'trying to verify many non-annotated or unknown tags, should fail' \
424 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
426 # creating annotated tags:
428 get_tag_msg () {
429 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
432 # run test_tick before committing always gives the time in that timezone
433 get_tag_header () {
434 cat <<EOF
435 object $2
436 type $3
437 tag $1
438 tagger C O Mitter <committer@example.com> $4 -0700
443 commit=$(git rev-parse HEAD)
444 time=$test_tick
446 get_tag_header annotated-tag $commit commit $time >expect
447 echo "A message" >>expect
448 test_expect_success \
449 'creating an annotated tag with -m message should succeed' '
450 git tag -m "A message" annotated-tag &&
451 get_tag_msg annotated-tag >actual &&
452 test_cmp expect actual
455 get_tag_header annotated-tag-edit $commit commit $time >expect
456 echo "An edited message" >>expect
457 test_expect_success 'set up editor' '
458 write_script fakeeditor <<-\EOF
459 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
460 mv "$1-" "$1"
463 test_expect_success \
464 'creating an annotated tag with -m message --edit should succeed' '
465 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
466 get_tag_msg annotated-tag-edit >actual &&
467 test_cmp expect actual
470 cat >msgfile <<EOF
471 Another message
472 in a file.
474 get_tag_header file-annotated-tag $commit commit $time >expect
475 cat msgfile >>expect
476 test_expect_success \
477 'creating an annotated tag with -F messagefile should succeed' '
478 git tag -F msgfile file-annotated-tag &&
479 get_tag_msg file-annotated-tag >actual &&
480 test_cmp expect actual
483 get_tag_header file-annotated-tag-edit $commit commit $time >expect
484 sed -e "s/Another message/Another edited message/g" msgfile >>expect
485 test_expect_success 'set up editor' '
486 write_script fakeeditor <<-\EOF
487 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
488 mv "$1-" "$1"
491 test_expect_success \
492 'creating an annotated tag with -F messagefile --edit should succeed' '
493 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
494 get_tag_msg file-annotated-tag-edit >actual &&
495 test_cmp expect actual
498 cat >inputmsg <<EOF
499 A message from the
500 standard input
502 get_tag_header stdin-annotated-tag $commit commit $time >expect
503 cat inputmsg >>expect
504 test_expect_success 'creating an annotated tag with -F - should succeed' '
505 git tag -F - stdin-annotated-tag <inputmsg &&
506 get_tag_msg stdin-annotated-tag >actual &&
507 test_cmp expect actual
510 test_expect_success \
511 'trying to create a tag with a non-existing -F file should fail' '
512 ! test -f nonexistingfile &&
513 ! tag_exists notag &&
514 test_must_fail git tag -F nonexistingfile notag &&
515 ! tag_exists notag
518 test_expect_success \
519 'trying to create tags giving both -m or -F options should fail' '
520 echo "message file 1" >msgfile1 &&
521 echo "message file 2" >msgfile2 &&
522 ! tag_exists msgtag &&
523 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
524 ! tag_exists msgtag &&
525 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
526 ! tag_exists msgtag &&
527 test_must_fail git tag -m "message 1" -F msgfile1 \
528 -m "message 2" msgtag &&
529 ! tag_exists msgtag
532 # blank and empty messages:
534 get_tag_header empty-annotated-tag $commit commit $time >expect
535 test_expect_success \
536 'creating a tag with an empty -m message should succeed' '
537 git tag -m "" empty-annotated-tag &&
538 get_tag_msg empty-annotated-tag >actual &&
539 test_cmp expect actual
542 >emptyfile
543 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
544 test_expect_success \
545 'creating a tag with an empty -F messagefile should succeed' '
546 git tag -F emptyfile emptyfile-annotated-tag &&
547 get_tag_msg emptyfile-annotated-tag >actual &&
548 test_cmp expect actual
551 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
552 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
553 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
554 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
555 get_tag_header blanks-annotated-tag $commit commit $time >expect
556 cat >>expect <<EOF
557 Leading blank lines
559 Repeated blank lines
561 Trailing spaces
563 Trailing blank lines
565 test_expect_success \
566 'extra blanks in the message for an annotated tag should be removed' '
567 git tag -F blanksfile blanks-annotated-tag &&
568 get_tag_msg blanks-annotated-tag >actual &&
569 test_cmp expect actual
572 get_tag_header blank-annotated-tag $commit commit $time >expect
573 test_expect_success \
574 'creating a tag with blank -m message with spaces should succeed' '
575 git tag -m " " blank-annotated-tag &&
576 get_tag_msg blank-annotated-tag >actual &&
577 test_cmp expect actual
580 echo ' ' >blankfile
581 echo '' >>blankfile
582 echo ' ' >>blankfile
583 get_tag_header blankfile-annotated-tag $commit commit $time >expect
584 test_expect_success \
585 'creating a tag with blank -F messagefile with spaces should succeed' '
586 git tag -F blankfile blankfile-annotated-tag &&
587 get_tag_msg blankfile-annotated-tag >actual &&
588 test_cmp expect actual
591 printf ' ' >blanknonlfile
592 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
593 test_expect_success \
594 'creating a tag with -F file of spaces and no newline should succeed' '
595 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
596 get_tag_msg blanknonlfile-annotated-tag >actual &&
597 test_cmp expect actual
600 # messages with commented lines:
602 cat >commentsfile <<EOF
603 # A comment
605 ############
606 The message.
607 ############
608 One line.
611 # commented lines
612 # commented lines
614 Another line.
615 # comments
617 Last line.
619 get_tag_header comments-annotated-tag $commit commit $time >expect
620 cat >>expect <<EOF
621 The message.
622 One line.
624 Another line.
626 Last line.
628 test_expect_success \
629 'creating a tag using a -F messagefile with #comments should succeed' '
630 git tag -F commentsfile comments-annotated-tag &&
631 get_tag_msg comments-annotated-tag >actual &&
632 test_cmp expect actual
635 get_tag_header comment-annotated-tag $commit commit $time >expect
636 test_expect_success \
637 'creating a tag with a #comment in the -m message should succeed' '
638 git tag -m "#comment" comment-annotated-tag &&
639 get_tag_msg comment-annotated-tag >actual &&
640 test_cmp expect actual
643 echo '#comment' >commentfile
644 echo '' >>commentfile
645 echo '####' >>commentfile
646 get_tag_header commentfile-annotated-tag $commit commit $time >expect
647 test_expect_success \
648 'creating a tag with #comments in the -F messagefile should succeed' '
649 git tag -F commentfile commentfile-annotated-tag &&
650 get_tag_msg commentfile-annotated-tag >actual &&
651 test_cmp expect actual
654 printf '#comment' >commentnonlfile
655 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
656 test_expect_success \
657 'creating a tag with a file of #comment and no newline should succeed' '
658 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
659 get_tag_msg commentnonlfile-annotated-tag >actual &&
660 test_cmp expect actual
663 # listing messages for annotated non-signed tags:
665 test_expect_success \
666 'listing the one-line message of a non-signed tag should succeed' '
667 git tag -m "A msg" tag-one-line &&
669 echo "tag-one-line" >expect &&
670 git tag -l | grep "^tag-one-line" >actual &&
671 test_cmp expect actual &&
672 git tag -n0 -l | grep "^tag-one-line" >actual &&
673 test_cmp expect actual &&
674 git tag -n0 -l tag-one-line >actual &&
675 test_cmp expect actual &&
677 git tag -n0 | grep "^tag-one-line" >actual &&
678 test_cmp expect actual &&
679 git tag -n0 tag-one-line >actual &&
680 test_cmp expect actual &&
682 echo "tag-one-line A msg" >expect &&
683 git tag -n1 -l | grep "^tag-one-line" >actual &&
684 test_cmp expect actual &&
685 git tag -n -l | grep "^tag-one-line" >actual &&
686 test_cmp expect actual &&
687 git tag -n1 -l tag-one-line >actual &&
688 test_cmp expect actual &&
689 git tag -n2 -l tag-one-line >actual &&
690 test_cmp expect actual &&
691 git tag -n999 -l tag-one-line >actual &&
692 test_cmp expect actual
695 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
696 >expect &&
697 git tag -n 100 >actual &&
698 test_cmp expect actual &&
700 git tag -m "A msg" 100 &&
701 echo "100 A msg" >expect &&
702 git tag -n 100 >actual &&
703 test_cmp expect actual
706 test_expect_success \
707 'listing the zero-lines message of a non-signed tag should succeed' '
708 git tag -m "" tag-zero-lines &&
710 echo "tag-zero-lines" >expect &&
711 git tag -l | grep "^tag-zero-lines" >actual &&
712 test_cmp expect actual &&
713 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
714 test_cmp expect actual &&
715 git tag -n0 -l tag-zero-lines >actual &&
716 test_cmp expect actual &&
718 echo "tag-zero-lines " >expect &&
719 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
720 test_cmp expect actual &&
721 git tag -n -l | grep "^tag-zero-lines" >actual &&
722 test_cmp expect actual &&
723 git tag -n1 -l tag-zero-lines >actual &&
724 test_cmp expect actual &&
725 git tag -n2 -l tag-zero-lines >actual &&
726 test_cmp expect actual &&
727 git tag -n999 -l tag-zero-lines >actual &&
728 test_cmp expect actual
731 echo 'tag line one' >annotagmsg
732 echo 'tag line two' >>annotagmsg
733 echo 'tag line three' >>annotagmsg
734 test_expect_success \
735 'listing many message lines of a non-signed tag should succeed' '
736 git tag -F annotagmsg tag-lines &&
738 echo "tag-lines" >expect &&
739 git tag -l | grep "^tag-lines" >actual &&
740 test_cmp expect actual &&
741 git tag -n0 -l | grep "^tag-lines" >actual &&
742 test_cmp expect actual &&
743 git tag -n0 -l tag-lines >actual &&
744 test_cmp expect actual &&
746 echo "tag-lines tag line one" >expect &&
747 git tag -n1 -l | grep "^tag-lines" >actual &&
748 test_cmp expect actual &&
749 git tag -n -l | grep "^tag-lines" >actual &&
750 test_cmp expect actual &&
751 git tag -n1 -l tag-lines >actual &&
752 test_cmp expect actual &&
754 echo " tag line two" >>expect &&
755 git tag -n2 -l | grep "^ *tag.line" >actual &&
756 test_cmp expect actual &&
757 git tag -n2 -l tag-lines >actual &&
758 test_cmp expect actual &&
760 echo " tag line three" >>expect &&
761 git tag -n3 -l | grep "^ *tag.line" >actual &&
762 test_cmp expect actual &&
763 git tag -n3 -l tag-lines >actual &&
764 test_cmp expect actual &&
765 git tag -n4 -l | grep "^ *tag.line" >actual &&
766 test_cmp expect actual &&
767 git tag -n4 -l tag-lines >actual &&
768 test_cmp expect actual &&
769 git tag -n99 -l | grep "^ *tag.line" >actual &&
770 test_cmp expect actual &&
771 git tag -n99 -l tag-lines >actual &&
772 test_cmp expect actual
775 test_expect_success 'annotations for blobs are empty' '
776 blob=$(git hash-object -w --stdin <<-\EOF
777 Blob paragraph 1.
779 Blob paragraph 2.
781 ) &&
782 git tag tag-blob $blob &&
783 echo "tag-blob " >expect &&
784 git tag -n1 -l tag-blob >actual &&
785 test_cmp expect actual
788 # trying to verify annotated non-signed tags:
790 test_expect_success GPG \
791 'trying to verify an annotated non-signed tag should fail' '
792 tag_exists annotated-tag &&
793 test_must_fail git tag -v annotated-tag
796 test_expect_success GPG \
797 'trying to verify a file-annotated non-signed tag should fail' '
798 tag_exists file-annotated-tag &&
799 test_must_fail git tag -v file-annotated-tag
802 test_expect_success GPG \
803 'trying to verify two annotated non-signed tags should fail' '
804 tag_exists annotated-tag file-annotated-tag &&
805 test_must_fail git tag -v annotated-tag file-annotated-tag
808 # creating and verifying signed tags:
810 get_tag_header signed-tag $commit commit $time >expect
811 echo 'A signed tag message' >>expect
812 echo '-----BEGIN PGP SIGNATURE-----' >>expect
813 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
814 git tag -s -m "A signed tag message" signed-tag &&
815 get_tag_msg signed-tag >actual &&
816 test_cmp expect actual
819 get_tag_header u-signed-tag $commit commit $time >expect
820 echo 'Another message' >>expect
821 echo '-----BEGIN PGP SIGNATURE-----' >>expect
822 test_expect_success GPG 'sign with a given key id' '
824 git tag -u committer@example.com -m "Another message" u-signed-tag &&
825 get_tag_msg u-signed-tag >actual &&
826 test_cmp expect actual
830 test_expect_success GPG 'sign with an unknown id (1)' '
832 test_must_fail git tag -u author@example.com \
833 -m "Another message" o-signed-tag
837 test_expect_success GPG 'sign with an unknown id (2)' '
839 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
843 cat >fakeeditor <<'EOF'
844 #!/bin/sh
845 test -n "$1" && exec >"$1"
846 echo A signed tag message
847 echo from a fake editor.
849 chmod +x fakeeditor
851 get_tag_header implied-sign $commit commit $time >expect
852 ./fakeeditor >>expect
853 echo '-----BEGIN PGP SIGNATURE-----' >>expect
854 test_expect_success GPG '-u implies signed tag' '
855 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
856 get_tag_msg implied-sign >actual &&
857 test_cmp expect actual
860 cat >sigmsgfile <<EOF
861 Another signed tag
862 message in a file.
864 get_tag_header file-signed-tag $commit commit $time >expect
865 cat sigmsgfile >>expect
866 echo '-----BEGIN PGP SIGNATURE-----' >>expect
867 test_expect_success GPG \
868 'creating a signed tag with -F messagefile should succeed' '
869 git tag -s -F sigmsgfile file-signed-tag &&
870 get_tag_msg file-signed-tag >actual &&
871 test_cmp expect actual
874 cat >siginputmsg <<EOF
875 A signed tag message from
876 the standard input
878 get_tag_header stdin-signed-tag $commit commit $time >expect
879 cat siginputmsg >>expect
880 echo '-----BEGIN PGP SIGNATURE-----' >>expect
881 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
882 git tag -s -F - stdin-signed-tag <siginputmsg &&
883 get_tag_msg stdin-signed-tag >actual &&
884 test_cmp expect actual
887 get_tag_header implied-annotate $commit commit $time >expect
888 ./fakeeditor >>expect
889 echo '-----BEGIN PGP SIGNATURE-----' >>expect
890 test_expect_success GPG '-s implies annotated tag' '
891 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
892 get_tag_msg implied-annotate >actual &&
893 test_cmp expect actual
896 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
897 echo "A message" >>expect
898 echo '-----BEGIN PGP SIGNATURE-----' >>expect
899 test_expect_success GPG \
900 'git tag -s implied if configured with tag.forcesignannotated' \
901 'test_config tag.forcesignannotated true &&
902 git tag -m "A message" forcesignannotated-implied-sign &&
903 get_tag_msg forcesignannotated-implied-sign >actual &&
904 test_cmp expect actual
907 test_expect_success GPG \
908 'lightweight with no message when configured with tag.forcesignannotated' \
909 'test_config tag.forcesignannotated true &&
910 git tag forcesignannotated-lightweight &&
911 tag_exists forcesignannotated-lightweight &&
912 test_must_fail git tag -v forcesignannotated-no-message
915 get_tag_header forcesignannotated-annotate $commit commit $time >expect
916 echo "A message" >>expect
917 test_expect_success GPG \
918 'git tag -a disable configured tag.forcesignannotated' \
919 'test_config tag.forcesignannotated true &&
920 git tag -a -m "A message" forcesignannotated-annotate &&
921 get_tag_msg forcesignannotated-annotate >actual &&
922 test_cmp expect actual &&
923 test_must_fail git tag -v forcesignannotated-annotate
926 get_tag_header forcesignannotated-disabled $commit commit $time >expect
927 echo "A message" >>expect
928 echo '-----BEGIN PGP SIGNATURE-----' >>expect
929 test_expect_success GPG \
930 'git tag --sign enable GPG sign' \
931 'test_config tag.forcesignannotated false &&
932 git tag --sign -m "A message" forcesignannotated-disabled &&
933 get_tag_msg forcesignannotated-disabled >actual &&
934 test_cmp expect actual
937 test_expect_success GPG \
938 'trying to create a signed tag with non-existing -F file should fail' '
939 ! test -f nonexistingfile &&
940 ! tag_exists nosigtag &&
941 test_must_fail git tag -s -F nonexistingfile nosigtag &&
942 ! tag_exists nosigtag
945 test_expect_success GPG 'verifying a signed tag should succeed' \
946 'git tag -v signed-tag'
948 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
949 'git tag -v signed-tag file-signed-tag'
951 test_expect_success GPG \
952 'verifying many signed and non-signed tags should fail' '
953 test_must_fail git tag -v signed-tag annotated-tag &&
954 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
955 test_must_fail git tag -v annotated-tag \
956 file-signed-tag file-annotated-tag &&
957 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
960 test_expect_success GPG 'verifying a forged tag should fail' '
961 forged=$(git cat-file tag signed-tag |
962 sed -e "s/signed-tag/forged-tag/" |
963 git mktag) &&
964 git tag forged-tag $forged &&
965 test_must_fail git tag -v forged-tag
968 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
969 cat >expect <<-\EOF &&
970 tagname : signed-tag
972 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
973 test_cmp expect actual
976 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
977 >expect &&
978 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
979 test_cmp expect actual
982 # blank and empty messages for signed tags:
984 get_tag_header empty-signed-tag $commit commit $time >expect
985 echo '-----BEGIN PGP SIGNATURE-----' >>expect
986 test_expect_success GPG \
987 'creating a signed tag with an empty -m message should succeed' '
988 git tag -s -m "" empty-signed-tag &&
989 get_tag_msg empty-signed-tag >actual &&
990 test_cmp expect actual &&
991 git tag -v empty-signed-tag
994 >sigemptyfile
995 get_tag_header emptyfile-signed-tag $commit commit $time >expect
996 echo '-----BEGIN PGP SIGNATURE-----' >>expect
997 test_expect_success GPG \
998 'creating a signed tag with an empty -F messagefile should succeed' '
999 git tag -s -F sigemptyfile emptyfile-signed-tag &&
1000 get_tag_msg emptyfile-signed-tag >actual &&
1001 test_cmp expect actual &&
1002 git tag -v emptyfile-signed-tag
1005 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1006 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1007 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1008 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1009 get_tag_header blanks-signed-tag $commit commit $time >expect
1010 cat >>expect <<EOF
1011 Leading blank lines
1013 Repeated blank lines
1015 Trailing spaces
1017 Trailing blank lines
1019 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1020 test_expect_success GPG \
1021 'extra blanks in the message for a signed tag should be removed' '
1022 git tag -s -F sigblanksfile blanks-signed-tag &&
1023 get_tag_msg blanks-signed-tag >actual &&
1024 test_cmp expect actual &&
1025 git tag -v blanks-signed-tag
1028 get_tag_header blank-signed-tag $commit commit $time >expect
1029 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1030 test_expect_success GPG \
1031 'creating a signed tag with a blank -m message should succeed' '
1032 git tag -s -m " " blank-signed-tag &&
1033 get_tag_msg blank-signed-tag >actual &&
1034 test_cmp expect actual &&
1035 git tag -v blank-signed-tag
1038 echo ' ' >sigblankfile
1039 echo '' >>sigblankfile
1040 echo ' ' >>sigblankfile
1041 get_tag_header blankfile-signed-tag $commit commit $time >expect
1042 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1043 test_expect_success GPG \
1044 'creating a signed tag with blank -F file with spaces should succeed' '
1045 git tag -s -F sigblankfile blankfile-signed-tag &&
1046 get_tag_msg blankfile-signed-tag >actual &&
1047 test_cmp expect actual &&
1048 git tag -v blankfile-signed-tag
1051 printf ' ' >sigblanknonlfile
1052 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1053 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1054 test_expect_success GPG \
1055 'creating a signed tag with spaces and no newline should succeed' '
1056 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1057 get_tag_msg blanknonlfile-signed-tag >actual &&
1058 test_cmp expect actual &&
1059 git tag -v blanknonlfile-signed-tag
1062 test_expect_success GPG 'signed tag with embedded PGP message' '
1063 cat >msg <<-\EOF &&
1064 -----BEGIN PGP MESSAGE-----
1066 this is not a real PGP message
1067 -----END PGP MESSAGE-----
1069 git tag -s -F msg confusing-pgp-message &&
1070 git tag -v confusing-pgp-message
1073 # messages with commented lines for signed tags:
1075 cat >sigcommentsfile <<EOF
1076 # A comment
1078 ############
1079 The message.
1080 ############
1081 One line.
1084 # commented lines
1085 # commented lines
1087 Another line.
1088 # comments
1090 Last line.
1092 get_tag_header comments-signed-tag $commit commit $time >expect
1093 cat >>expect <<EOF
1094 The message.
1095 One line.
1097 Another line.
1099 Last line.
1101 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1102 test_expect_success GPG \
1103 'creating a signed tag with a -F file with #comments should succeed' '
1104 git tag -s -F sigcommentsfile comments-signed-tag &&
1105 get_tag_msg comments-signed-tag >actual &&
1106 test_cmp expect actual &&
1107 git tag -v comments-signed-tag
1110 get_tag_header comment-signed-tag $commit commit $time >expect
1111 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1112 test_expect_success GPG \
1113 'creating a signed tag with #commented -m message should succeed' '
1114 git tag -s -m "#comment" comment-signed-tag &&
1115 get_tag_msg comment-signed-tag >actual &&
1116 test_cmp expect actual &&
1117 git tag -v comment-signed-tag
1120 echo '#comment' >sigcommentfile
1121 echo '' >>sigcommentfile
1122 echo '####' >>sigcommentfile
1123 get_tag_header commentfile-signed-tag $commit commit $time >expect
1124 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1125 test_expect_success GPG \
1126 'creating a signed tag with #commented -F messagefile should succeed' '
1127 git tag -s -F sigcommentfile commentfile-signed-tag &&
1128 get_tag_msg commentfile-signed-tag >actual &&
1129 test_cmp expect actual &&
1130 git tag -v commentfile-signed-tag
1133 printf '#comment' >sigcommentnonlfile
1134 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1135 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1136 test_expect_success GPG \
1137 'creating a signed tag with a #comment and no newline should succeed' '
1138 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1139 get_tag_msg commentnonlfile-signed-tag >actual &&
1140 test_cmp expect actual &&
1141 git tag -v commentnonlfile-signed-tag
1144 # listing messages for signed tags:
1146 test_expect_success GPG \
1147 'listing the one-line message of a signed tag should succeed' '
1148 git tag -s -m "A message line signed" stag-one-line &&
1150 echo "stag-one-line" >expect &&
1151 git tag -l | grep "^stag-one-line" >actual &&
1152 test_cmp expect actual &&
1153 git tag -n0 -l | grep "^stag-one-line" >actual &&
1154 test_cmp expect actual &&
1155 git tag -n0 -l stag-one-line >actual &&
1156 test_cmp expect actual &&
1158 echo "stag-one-line A message line signed" >expect &&
1159 git tag -n1 -l | grep "^stag-one-line" >actual &&
1160 test_cmp expect actual &&
1161 git tag -n -l | grep "^stag-one-line" >actual &&
1162 test_cmp expect actual &&
1163 git tag -n1 -l stag-one-line >actual &&
1164 test_cmp expect actual &&
1165 git tag -n2 -l stag-one-line >actual &&
1166 test_cmp expect actual &&
1167 git tag -n999 -l stag-one-line >actual &&
1168 test_cmp expect actual
1171 test_expect_success GPG \
1172 'listing the zero-lines message of a signed tag should succeed' '
1173 git tag -s -m "" stag-zero-lines &&
1175 echo "stag-zero-lines" >expect &&
1176 git tag -l | grep "^stag-zero-lines" >actual &&
1177 test_cmp expect actual &&
1178 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1179 test_cmp expect actual &&
1180 git tag -n0 -l stag-zero-lines >actual &&
1181 test_cmp expect actual &&
1183 echo "stag-zero-lines " >expect &&
1184 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1185 test_cmp expect actual &&
1186 git tag -n -l | grep "^stag-zero-lines" >actual &&
1187 test_cmp expect actual &&
1188 git tag -n1 -l stag-zero-lines >actual &&
1189 test_cmp expect actual &&
1190 git tag -n2 -l stag-zero-lines >actual &&
1191 test_cmp expect actual &&
1192 git tag -n999 -l stag-zero-lines >actual &&
1193 test_cmp expect actual
1196 echo 'stag line one' >sigtagmsg
1197 echo 'stag line two' >>sigtagmsg
1198 echo 'stag line three' >>sigtagmsg
1199 test_expect_success GPG \
1200 'listing many message lines of a signed tag should succeed' '
1201 git tag -s -F sigtagmsg stag-lines &&
1203 echo "stag-lines" >expect &&
1204 git tag -l | grep "^stag-lines" >actual &&
1205 test_cmp expect actual &&
1206 git tag -n0 -l | grep "^stag-lines" >actual &&
1207 test_cmp expect actual &&
1208 git tag -n0 -l stag-lines >actual &&
1209 test_cmp expect actual &&
1211 echo "stag-lines stag line one" >expect &&
1212 git tag -n1 -l | grep "^stag-lines" >actual &&
1213 test_cmp expect actual &&
1214 git tag -n -l | grep "^stag-lines" >actual &&
1215 test_cmp expect actual &&
1216 git tag -n1 -l stag-lines >actual &&
1217 test_cmp expect actual &&
1219 echo " stag line two" >>expect &&
1220 git tag -n2 -l | grep "^ *stag.line" >actual &&
1221 test_cmp expect actual &&
1222 git tag -n2 -l stag-lines >actual &&
1223 test_cmp expect actual &&
1225 echo " stag line three" >>expect &&
1226 git tag -n3 -l | grep "^ *stag.line" >actual &&
1227 test_cmp expect actual &&
1228 git tag -n3 -l stag-lines >actual &&
1229 test_cmp expect actual &&
1230 git tag -n4 -l | grep "^ *stag.line" >actual &&
1231 test_cmp expect actual &&
1232 git tag -n4 -l stag-lines >actual &&
1233 test_cmp expect actual &&
1234 git tag -n99 -l | grep "^ *stag.line" >actual &&
1235 test_cmp expect actual &&
1236 git tag -n99 -l stag-lines >actual &&
1237 test_cmp expect actual
1240 # tags pointing to objects different from commits:
1242 tree=$(git rev-parse HEAD^{tree})
1243 blob=$(git rev-parse HEAD:foo)
1244 tag=$(git rev-parse signed-tag 2>/dev/null)
1246 get_tag_header tree-signed-tag $tree tree $time >expect
1247 echo "A message for a tree" >>expect
1248 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1249 test_expect_success GPG \
1250 'creating a signed tag pointing to a tree should succeed' '
1251 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1252 get_tag_msg tree-signed-tag >actual &&
1253 test_cmp expect actual
1256 get_tag_header blob-signed-tag $blob blob $time >expect
1257 echo "A message for a blob" >>expect
1258 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1259 test_expect_success GPG \
1260 'creating a signed tag pointing to a blob should succeed' '
1261 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1262 get_tag_msg blob-signed-tag >actual &&
1263 test_cmp expect actual
1266 get_tag_header tag-signed-tag $tag tag $time >expect
1267 echo "A message for another tag" >>expect
1268 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1269 test_expect_success GPG \
1270 'creating a signed tag pointing to another tag should succeed' '
1271 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1272 get_tag_msg tag-signed-tag >actual &&
1273 test_cmp expect actual
1276 # usage with rfc1991 signatures
1277 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1278 echo "RFC1991 signed tag" >>expect
1279 echo '-----BEGIN PGP MESSAGE-----' >>expect
1280 test_expect_success GPG,RFC1991 \
1281 'creating a signed tag with rfc1991' '
1282 echo "rfc1991" >gpghome/gpg.conf &&
1283 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1284 get_tag_msg rfc1991-signed-tag >actual &&
1285 test_cmp expect actual
1288 cat >fakeeditor <<'EOF'
1289 #!/bin/sh
1290 cp "$1" actual
1292 chmod +x fakeeditor
1294 test_expect_success GPG,RFC1991 \
1295 'reediting a signed tag body omits signature' '
1296 echo "rfc1991" >gpghome/gpg.conf &&
1297 echo "RFC1991 signed tag" >expect &&
1298 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1299 test_cmp expect actual
1302 test_expect_success GPG,RFC1991 \
1303 'verifying rfc1991 signature' '
1304 echo "rfc1991" >gpghome/gpg.conf &&
1305 git tag -v rfc1991-signed-tag
1308 test_expect_success GPG,RFC1991 \
1309 'list tag with rfc1991 signature' '
1310 echo "rfc1991" >gpghome/gpg.conf &&
1311 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1312 git tag -l -n1 rfc1991-signed-tag >actual &&
1313 test_cmp expect actual &&
1314 git tag -l -n2 rfc1991-signed-tag >actual &&
1315 test_cmp expect actual &&
1316 git tag -l -n999 rfc1991-signed-tag >actual &&
1317 test_cmp expect actual
1320 rm -f gpghome/gpg.conf
1322 test_expect_success GPG,RFC1991 \
1323 'verifying rfc1991 signature without --rfc1991' '
1324 git tag -v rfc1991-signed-tag
1327 test_expect_success GPG,RFC1991 \
1328 'list tag with rfc1991 signature without --rfc1991' '
1329 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1330 git tag -l -n1 rfc1991-signed-tag >actual &&
1331 test_cmp expect actual &&
1332 git tag -l -n2 rfc1991-signed-tag >actual &&
1333 test_cmp expect actual &&
1334 git tag -l -n999 rfc1991-signed-tag >actual &&
1335 test_cmp expect actual
1338 test_expect_success GPG,RFC1991 \
1339 'reediting a signed tag body omits signature' '
1340 echo "RFC1991 signed tag" >expect &&
1341 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1342 test_cmp expect actual
1345 # try to sign with bad user.signingkey
1346 test_expect_success GPG \
1347 'git tag -s fails if gpg is misconfigured (bad key)' \
1348 'test_config user.signingkey BobTheMouse &&
1349 test_must_fail git tag -s -m tail tag-gpg-failure'
1351 # try to produce invalid signature
1352 test_expect_success GPG \
1353 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1354 'test_config gpg.program echo &&
1355 test_must_fail git tag -s -m tail tag-gpg-failure'
1358 # try to verify without gpg:
1360 rm -rf gpghome
1361 test_expect_success GPG \
1362 'verify signed tag fails when public key is not present' \
1363 'test_must_fail git tag -v signed-tag'
1365 test_expect_success \
1366 'git tag -a fails if tag annotation is empty' '
1367 ! (GIT_EDITOR=cat git tag -a initial-comment)
1370 test_expect_success \
1371 'message in editor has initial comment' '
1372 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1375 test_expect_success 'message in editor has initial comment: first line' '
1376 # check the first line --- should be empty
1377 echo >first.expect &&
1378 sed -e 1q <actual >first.actual &&
1379 test_i18ncmp first.expect first.actual
1382 test_expect_success \
1383 'message in editor has initial comment: remainder' '
1384 # remove commented lines from the remainder -- should be empty
1385 >rest.expect &&
1386 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1387 test_cmp rest.expect rest.actual
1390 get_tag_header reuse $commit commit $time >expect
1391 echo "An annotation to be reused" >> expect
1392 test_expect_success \
1393 'overwriting an annoted tag should use its previous body' '
1394 git tag -a -m "An annotation to be reused" reuse &&
1395 GIT_EDITOR=true git tag -f -a reuse &&
1396 get_tag_msg reuse >actual &&
1397 test_cmp expect actual
1400 test_expect_success 'filename for the message is relative to cwd' '
1401 mkdir subdir &&
1402 echo "Tag message in top directory" >msgfile-5 &&
1403 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1405 cd subdir &&
1406 git tag -a -F msgfile-5 tag-from-subdir
1407 ) &&
1408 git cat-file tag tag-from-subdir | grep "in sub directory"
1411 test_expect_success 'filename for the message is relative to cwd' '
1412 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1414 cd subdir &&
1415 git tag -a -F msgfile-6 tag-from-subdir-2
1416 ) &&
1417 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1420 # create a few more commits to test --contains
1422 hash1=$(git rev-parse HEAD)
1424 test_expect_success 'creating second commit and tag' '
1425 echo foo-2.0 >foo &&
1426 git add foo &&
1427 git commit -m second &&
1428 git tag v2.0
1431 hash2=$(git rev-parse HEAD)
1433 test_expect_success 'creating third commit without tag' '
1434 echo foo-dev >foo &&
1435 git add foo &&
1436 git commit -m third
1439 hash3=$(git rev-parse HEAD)
1441 # simple linear checks of --continue
1443 cat > expected <<EOF
1444 v0.2.1
1445 v1.0
1446 v1.0.1
1447 v1.1.3
1448 v2.0
1451 test_expect_success 'checking that first commit is in all tags (hash)' "
1452 git tag -l --contains $hash1 v* >actual &&
1453 test_cmp expected actual
1456 # other ways of specifying the commit
1457 test_expect_success 'checking that first commit is in all tags (tag)' "
1458 git tag -l --contains v1.0 v* >actual &&
1459 test_cmp expected actual
1462 test_expect_success 'checking that first commit is in all tags (relative)' "
1463 git tag -l --contains HEAD~2 v* >actual &&
1464 test_cmp expected actual
1467 # All the --contains tests above, but with --no-contains
1468 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1469 >expected &&
1470 git tag -l --no-contains $hash1 v* >actual &&
1471 test_cmp expected actual
1474 test_expect_success 'checking that first commit is in all tags (tag)' "
1475 git tag -l --no-contains v1.0 v* >actual &&
1476 test_cmp expected actual
1479 test_expect_success 'checking that first commit is in all tags (relative)' "
1480 git tag -l --no-contains HEAD~2 v* >actual &&
1481 test_cmp expected actual
1484 cat > expected <<EOF
1485 v2.0
1488 test_expect_success 'checking that second commit only has one tag' "
1489 git tag -l --contains $hash2 v* >actual &&
1490 test_cmp expected actual
1493 cat > expected <<EOF
1494 v0.2.1
1495 v1.0
1496 v1.0.1
1497 v1.1.3
1500 test_expect_success 'inverse of the last test, with --no-contains' "
1501 git tag -l --no-contains $hash2 v* >actual &&
1502 test_cmp expected actual
1505 cat > expected <<EOF
1508 test_expect_success 'checking that third commit has no tags' "
1509 git tag -l --contains $hash3 v* >actual &&
1510 test_cmp expected actual
1513 cat > expected <<EOF
1514 v0.2.1
1515 v1.0
1516 v1.0.1
1517 v1.1.3
1518 v2.0
1521 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1522 git tag -l --no-contains $hash3 v* >actual &&
1523 test_cmp expected actual
1526 # how about a simple merge?
1528 test_expect_success 'creating simple branch' '
1529 git branch stable v2.0 &&
1530 git checkout stable &&
1531 echo foo-3.0 > foo &&
1532 git commit foo -m fourth &&
1533 git tag v3.0
1536 hash4=$(git rev-parse HEAD)
1538 cat > expected <<EOF
1539 v3.0
1542 test_expect_success 'checking that branch head only has one tag' "
1543 git tag -l --contains $hash4 v* >actual &&
1544 test_cmp expected actual
1547 cat > expected <<EOF
1548 v0.2.1
1549 v1.0
1550 v1.0.1
1551 v1.1.3
1552 v2.0
1555 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1556 git tag -l --no-contains $hash4 v* >actual &&
1557 test_cmp expected actual
1560 test_expect_success 'merging original branch into this branch' '
1561 git merge --strategy=ours master &&
1562 git tag v4.0
1565 cat > expected <<EOF
1566 v4.0
1569 test_expect_success 'checking that original branch head has one tag now' "
1570 git tag -l --contains $hash3 v* >actual &&
1571 test_cmp expected actual
1574 cat > expected <<EOF
1575 v0.2.1
1576 v1.0
1577 v1.0.1
1578 v1.1.3
1579 v2.0
1580 v3.0
1583 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1584 git tag -l --no-contains $hash3 v* >actual &&
1585 test_cmp expected actual
1588 cat > expected <<EOF
1589 v0.2.1
1590 v1.0
1591 v1.0.1
1592 v1.1.3
1593 v2.0
1594 v3.0
1595 v4.0
1598 test_expect_success 'checking that initial commit is in all tags' "
1599 git tag -l --contains $hash1 v* >actual &&
1600 test_cmp expected actual
1603 test_expect_success 'checking that --contains can be used in non-list mode' '
1604 git tag --contains $hash1 v* >actual &&
1605 test_cmp expected actual
1608 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1609 >expected &&
1610 git tag -l --no-contains $hash1 v* >actual &&
1611 test_cmp expected actual
1614 # mixing modes and options:
1616 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1617 test_must_fail git tag -a &&
1618 test_must_fail git tag -a -l &&
1619 test_must_fail git tag -s &&
1620 test_must_fail git tag -s -l &&
1621 test_must_fail git tag -m &&
1622 test_must_fail git tag -m -l &&
1623 test_must_fail git tag -m "hlagh" &&
1624 test_must_fail git tag -m "hlagh" -l &&
1625 test_must_fail git tag -F &&
1626 test_must_fail git tag -F -l &&
1627 test_must_fail git tag -f &&
1628 test_must_fail git tag -f -l &&
1629 test_must_fail git tag -a -s -m -F &&
1630 test_must_fail git tag -a -s -m -F -l &&
1631 test_must_fail git tag -l -v &&
1632 test_must_fail git tag -l -d &&
1633 test_must_fail git tag -l -v -d &&
1634 test_must_fail git tag -n 100 -v &&
1635 test_must_fail git tag -l -m msg &&
1636 test_must_fail git tag -l -F some file &&
1637 test_must_fail git tag -v -s &&
1638 test_must_fail git tag --contains tag-tree &&
1639 test_must_fail git tag --contains tag-blob &&
1640 test_must_fail git tag --no-contains tag-tree &&
1641 test_must_fail git tag --no-contains tag-blob &&
1642 test_must_fail git tag --contains --no-contains &&
1643 test_must_fail git tag --no-with HEAD &&
1644 test_must_fail git tag --no-without HEAD
1647 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1649 test_expect_success "mixing incompatible modes with $option is forbidden" "
1650 test_must_fail git tag -d $option HEAD &&
1651 test_must_fail git tag -d $option HEAD some-tag &&
1652 test_must_fail git tag -v $option HEAD
1654 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1655 git tag -n $option HEAD HEAD &&
1656 git tag $option HEAD HEAD &&
1657 git tag $option
1659 done
1661 # check points-at
1663 test_expect_success '--points-at can be used in non-list mode' '
1664 echo v4.0 >expect &&
1665 git tag --points-at=v4.0 "v*" >actual &&
1666 test_cmp expect actual
1669 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1670 echo v4.0 >expect &&
1671 git tag --points-at >actual &&
1672 test_cmp expect actual
1675 test_expect_success '--points-at finds lightweight tags' '
1676 echo v4.0 >expect &&
1677 git tag --points-at v4.0 >actual &&
1678 test_cmp expect actual
1681 test_expect_success '--points-at finds annotated tags of commits' '
1682 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1683 echo annotated-v4.0 >expect &&
1684 git tag -l --points-at v4.0 "annotated*" >actual &&
1685 test_cmp expect actual
1688 test_expect_success '--points-at finds annotated tags of tags' '
1689 git tag -m "describing the v4.0 tag object" \
1690 annotated-again-v4.0 annotated-v4.0 &&
1691 cat >expect <<-\EOF &&
1692 annotated-again-v4.0
1693 annotated-v4.0
1695 git tag --points-at=annotated-v4.0 >actual &&
1696 test_cmp expect actual
1699 test_expect_success 'multiple --points-at are OR-ed together' '
1700 cat >expect <<-\EOF &&
1701 v2.0
1702 v3.0
1704 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1705 test_cmp expect actual
1708 test_expect_success 'lexical sort' '
1709 git tag foo1.3 &&
1710 git tag foo1.6 &&
1711 git tag foo1.10 &&
1712 git tag -l --sort=refname "foo*" >actual &&
1713 cat >expect <<-\EOF &&
1714 foo1.10
1715 foo1.3
1716 foo1.6
1718 test_cmp expect actual
1721 test_expect_success 'version sort' '
1722 git tag -l --sort=version:refname "foo*" >actual &&
1723 cat >expect <<-\EOF &&
1724 foo1.3
1725 foo1.6
1726 foo1.10
1728 test_cmp expect actual
1731 test_expect_success 'reverse version sort' '
1732 git tag -l --sort=-version:refname "foo*" >actual &&
1733 cat >expect <<-\EOF &&
1734 foo1.10
1735 foo1.6
1736 foo1.3
1738 test_cmp expect actual
1741 test_expect_success 'reverse lexical sort' '
1742 git tag -l --sort=-refname "foo*" >actual &&
1743 cat >expect <<-\EOF &&
1744 foo1.6
1745 foo1.3
1746 foo1.10
1748 test_cmp expect actual
1751 test_expect_success 'configured lexical sort' '
1752 test_config tag.sort "v:refname" &&
1753 git tag -l "foo*" >actual &&
1754 cat >expect <<-\EOF &&
1755 foo1.3
1756 foo1.6
1757 foo1.10
1759 test_cmp expect actual
1762 test_expect_success 'option override configured sort' '
1763 test_config tag.sort "v:refname" &&
1764 git tag -l --sort=-refname "foo*" >actual &&
1765 cat >expect <<-\EOF &&
1766 foo1.6
1767 foo1.3
1768 foo1.10
1770 test_cmp expect actual
1773 test_expect_success 'invalid sort parameter on command line' '
1774 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1777 test_expect_success 'invalid sort parameter in configuratoin' '
1778 test_config tag.sort "v:notvalid" &&
1779 test_must_fail git tag -l "foo*"
1782 test_expect_success 'version sort with prerelease reordering' '
1783 test_config versionsort.prereleaseSuffix -rc &&
1784 git tag foo1.6-rc1 &&
1785 git tag foo1.6-rc2 &&
1786 git tag -l --sort=version:refname "foo*" >actual &&
1787 cat >expect <<-\EOF &&
1788 foo1.3
1789 foo1.6-rc1
1790 foo1.6-rc2
1791 foo1.6
1792 foo1.10
1794 test_cmp expect actual
1797 test_expect_success 'reverse version sort with prerelease reordering' '
1798 test_config versionsort.prereleaseSuffix -rc &&
1799 git tag -l --sort=-version:refname "foo*" >actual &&
1800 cat >expect <<-\EOF &&
1801 foo1.10
1802 foo1.6
1803 foo1.6-rc2
1804 foo1.6-rc1
1805 foo1.3
1807 test_cmp expect actual
1810 test_expect_success 'version sort with prerelease reordering and common leading character' '
1811 test_config versionsort.prereleaseSuffix -before &&
1812 git tag foo1.7-before1 &&
1813 git tag foo1.7 &&
1814 git tag foo1.7-after1 &&
1815 git tag -l --sort=version:refname "foo1.7*" >actual &&
1816 cat >expect <<-\EOF &&
1817 foo1.7-before1
1818 foo1.7
1819 foo1.7-after1
1821 test_cmp expect actual
1824 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1825 test_config versionsort.prereleaseSuffix -before &&
1826 git config --add versionsort.prereleaseSuffix -after &&
1827 git tag -l --sort=version:refname "foo1.7*" >actual &&
1828 cat >expect <<-\EOF &&
1829 foo1.7-before1
1830 foo1.7-after1
1831 foo1.7
1833 test_cmp expect actual
1836 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1837 test_config versionsort.prereleaseSuffix -bar &&
1838 git config --add versionsort.prereleaseSuffix -foo-baz &&
1839 git config --add versionsort.prereleaseSuffix -foo-bar &&
1840 git tag foo1.8-foo-bar &&
1841 git tag foo1.8-foo-baz &&
1842 git tag foo1.8 &&
1843 git tag -l --sort=version:refname "foo1.8*" >actual &&
1844 cat >expect <<-\EOF &&
1845 foo1.8-foo-baz
1846 foo1.8-foo-bar
1847 foo1.8
1849 test_cmp expect actual
1852 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1853 test_config versionsort.prereleaseSuffix -pre &&
1854 git config --add versionsort.prereleaseSuffix -prerelease &&
1855 git tag foo1.9-pre1 &&
1856 git tag foo1.9-pre2 &&
1857 git tag foo1.9-prerelease1 &&
1858 git tag -l --sort=version:refname "foo1.9*" >actual &&
1859 cat >expect <<-\EOF &&
1860 foo1.9-pre1
1861 foo1.9-pre2
1862 foo1.9-prerelease1
1864 test_cmp expect actual
1867 test_expect_success 'version sort with general suffix reordering' '
1868 test_config versionsort.suffix -alpha &&
1869 git config --add versionsort.suffix -beta &&
1870 git config --add versionsort.suffix "" &&
1871 git config --add versionsort.suffix -gamma &&
1872 git config --add versionsort.suffix -delta &&
1873 git tag foo1.10-alpha &&
1874 git tag foo1.10-beta &&
1875 git tag foo1.10-gamma &&
1876 git tag foo1.10-delta &&
1877 git tag foo1.10-unlisted-suffix &&
1878 git tag -l --sort=version:refname "foo1.10*" >actual &&
1879 cat >expect <<-\EOF &&
1880 foo1.10-alpha
1881 foo1.10-beta
1882 foo1.10
1883 foo1.10-unlisted-suffix
1884 foo1.10-gamma
1885 foo1.10-delta
1887 test_cmp expect actual
1890 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1891 test_config versionsort.suffix -before &&
1892 test_config versionsort.prereleaseSuffix -after &&
1893 git tag -l --sort=version:refname "foo1.7*" >actual &&
1894 cat >expect <<-\EOF &&
1895 foo1.7-before1
1896 foo1.7
1897 foo1.7-after1
1899 test_cmp expect actual
1902 test_expect_success 'version sort with very long prerelease suffix' '
1903 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1904 git tag -l --sort=version:refname
1907 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1908 >expect &&
1909 i=1 &&
1910 while test $i -lt 8000
1912 echo "commit refs/heads/master
1913 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1914 data <<EOF
1915 commit #$i
1916 EOF"
1917 test $i = 1 && echo "from refs/heads/master^0"
1918 i=$(($i + 1))
1919 done | git fast-import &&
1920 git checkout master &&
1921 git tag far-far-away HEAD^ &&
1922 run_with_limited_stack git tag --contains HEAD >actual &&
1923 test_cmp expect actual &&
1924 run_with_limited_stack git tag --no-contains HEAD >actual &&
1925 test_line_count "-gt" 10 actual
1928 test_expect_success '--format should list tags as per format given' '
1929 cat >expect <<-\EOF &&
1930 refname : refs/tags/v1.0
1931 refname : refs/tags/v1.0.1
1932 refname : refs/tags/v1.1.3
1934 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1935 test_cmp expect actual
1938 test_expect_success "set up color tests" '
1939 echo "<RED>v1.0<RESET>" >expect.color &&
1940 echo "v1.0" >expect.bare &&
1941 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1944 test_expect_success '%(color) omitted without tty' '
1945 TERM=vt100 git tag $color_args >actual.raw &&
1946 test_decode_color <actual.raw >actual &&
1947 test_cmp expect.bare actual
1950 test_expect_success TTY '%(color) present with tty' '
1951 test_terminal git tag $color_args >actual.raw &&
1952 test_decode_color <actual.raw >actual &&
1953 test_cmp expect.color actual
1956 test_expect_success '--color overrides auto-color' '
1957 git tag --color $color_args >actual.raw &&
1958 test_decode_color <actual.raw >actual &&
1959 test_cmp expect.color actual
1962 test_expect_success 'color.ui=always overrides auto-color' '
1963 git -c color.ui=always tag $color_args >actual.raw &&
1964 test_decode_color <actual.raw >actual &&
1965 test_cmp expect.color actual
1968 test_expect_success 'setup --merged test tags' '
1969 git tag mergetest-1 HEAD~2 &&
1970 git tag mergetest-2 HEAD~1 &&
1971 git tag mergetest-3 HEAD
1974 test_expect_success '--merged can be used in non-list mode' '
1975 cat >expect <<-\EOF &&
1976 mergetest-1
1977 mergetest-2
1979 git tag --merged=mergetest-2 "mergetest*" >actual &&
1980 test_cmp expect actual
1983 test_expect_success '--merged is incompatible with --no-merged' '
1984 test_must_fail git tag --merged HEAD --no-merged HEAD
1987 test_expect_success '--merged shows merged tags' '
1988 cat >expect <<-\EOF &&
1989 mergetest-1
1990 mergetest-2
1992 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1993 test_cmp expect actual
1996 test_expect_success '--no-merged show unmerged tags' '
1997 cat >expect <<-\EOF &&
1998 mergetest-3
2000 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2001 test_cmp expect actual
2004 test_expect_success '--no-merged can be used in non-list mode' '
2005 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2006 test_cmp expect actual
2009 test_expect_success 'ambiguous branch/tags not marked' '
2010 git tag ambiguous &&
2011 git branch ambiguous &&
2012 echo ambiguous >expect &&
2013 git tag -l ambiguous >actual &&
2014 test_cmp expect actual
2017 test_expect_success '--contains combined with --no-contains' '
2019 git init no-contains &&
2020 cd no-contains &&
2021 test_commit v0.1 &&
2022 test_commit v0.2 &&
2023 test_commit v0.3 &&
2024 test_commit v0.4 &&
2025 test_commit v0.5 &&
2026 cat >expected <<-\EOF &&
2027 v0.2
2028 v0.3
2029 v0.4
2031 git tag --contains v0.2 --no-contains v0.5 >actual &&
2032 test_cmp expected actual
2036 # As the docs say, list tags which contain a specified *commit*. We
2037 # don't recurse down to tags for trees or blobs pointed to by *those*
2038 # commits.
2039 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2040 cd no-contains &&
2041 blob=$(git rev-parse v0.3:v0.3.t) &&
2042 tree=$(git rev-parse v0.3^{tree}) &&
2043 git tag tag-blob $blob &&
2044 git tag tag-tree $tree &&
2045 git tag --contains v0.3 >actual &&
2046 cat >expected <<-\EOF &&
2047 v0.3
2048 v0.4
2049 v0.5
2051 test_cmp expected actual &&
2052 git tag --no-contains v0.3 >actual &&
2053 cat >expected <<-\EOF &&
2054 v0.1
2055 v0.2
2057 test_cmp expected actual
2060 test_done