packfile: allow find_pack_entry to handle arbitrary repositories
[alt-git.git] / t / t7004-tag.sh
bloba9af2de9960b345878ac0f85c33b1efd3e038d28
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=40 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 cat >msgfile <<EOF
456 Another message
457 in a file.
459 get_tag_header file-annotated-tag $commit commit $time >expect
460 cat msgfile >>expect
461 test_expect_success \
462 'creating an annotated tag with -F messagefile should succeed' '
463 git tag -F msgfile file-annotated-tag &&
464 get_tag_msg file-annotated-tag >actual &&
465 test_cmp expect actual
468 cat >inputmsg <<EOF
469 A message from the
470 standard input
472 get_tag_header stdin-annotated-tag $commit commit $time >expect
473 cat inputmsg >>expect
474 test_expect_success 'creating an annotated tag with -F - should succeed' '
475 git tag -F - stdin-annotated-tag <inputmsg &&
476 get_tag_msg stdin-annotated-tag >actual &&
477 test_cmp expect actual
480 test_expect_success \
481 'trying to create a tag with a non-existing -F file should fail' '
482 ! test -f nonexistingfile &&
483 ! tag_exists notag &&
484 test_must_fail git tag -F nonexistingfile notag &&
485 ! tag_exists notag
488 test_expect_success \
489 'trying to create tags giving both -m or -F options should fail' '
490 echo "message file 1" >msgfile1 &&
491 echo "message file 2" >msgfile2 &&
492 ! tag_exists msgtag &&
493 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
494 ! tag_exists msgtag &&
495 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
496 ! tag_exists msgtag &&
497 test_must_fail git tag -m "message 1" -F msgfile1 \
498 -m "message 2" msgtag &&
499 ! tag_exists msgtag
502 # blank and empty messages:
504 get_tag_header empty-annotated-tag $commit commit $time >expect
505 test_expect_success \
506 'creating a tag with an empty -m message should succeed' '
507 git tag -m "" empty-annotated-tag &&
508 get_tag_msg empty-annotated-tag >actual &&
509 test_cmp expect actual
512 >emptyfile
513 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
514 test_expect_success \
515 'creating a tag with an empty -F messagefile should succeed' '
516 git tag -F emptyfile emptyfile-annotated-tag &&
517 get_tag_msg emptyfile-annotated-tag >actual &&
518 test_cmp expect actual
521 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
522 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
523 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
524 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
525 get_tag_header blanks-annotated-tag $commit commit $time >expect
526 cat >>expect <<EOF
527 Leading blank lines
529 Repeated blank lines
531 Trailing spaces
533 Trailing blank lines
535 test_expect_success \
536 'extra blanks in the message for an annotated tag should be removed' '
537 git tag -F blanksfile blanks-annotated-tag &&
538 get_tag_msg blanks-annotated-tag >actual &&
539 test_cmp expect actual
542 get_tag_header blank-annotated-tag $commit commit $time >expect
543 test_expect_success \
544 'creating a tag with blank -m message with spaces should succeed' '
545 git tag -m " " blank-annotated-tag &&
546 get_tag_msg blank-annotated-tag >actual &&
547 test_cmp expect actual
550 echo ' ' >blankfile
551 echo '' >>blankfile
552 echo ' ' >>blankfile
553 get_tag_header blankfile-annotated-tag $commit commit $time >expect
554 test_expect_success \
555 'creating a tag with blank -F messagefile with spaces should succeed' '
556 git tag -F blankfile blankfile-annotated-tag &&
557 get_tag_msg blankfile-annotated-tag >actual &&
558 test_cmp expect actual
561 printf ' ' >blanknonlfile
562 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
563 test_expect_success \
564 'creating a tag with -F file of spaces and no newline should succeed' '
565 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
566 get_tag_msg blanknonlfile-annotated-tag >actual &&
567 test_cmp expect actual
570 # messages with commented lines:
572 cat >commentsfile <<EOF
573 # A comment
575 ############
576 The message.
577 ############
578 One line.
581 # commented lines
582 # commented lines
584 Another line.
585 # comments
587 Last line.
589 get_tag_header comments-annotated-tag $commit commit $time >expect
590 cat >>expect <<EOF
591 The message.
592 One line.
594 Another line.
596 Last line.
598 test_expect_success \
599 'creating a tag using a -F messagefile with #comments should succeed' '
600 git tag -F commentsfile comments-annotated-tag &&
601 get_tag_msg comments-annotated-tag >actual &&
602 test_cmp expect actual
605 get_tag_header comment-annotated-tag $commit commit $time >expect
606 test_expect_success \
607 'creating a tag with a #comment in the -m message should succeed' '
608 git tag -m "#comment" comment-annotated-tag &&
609 get_tag_msg comment-annotated-tag >actual &&
610 test_cmp expect actual
613 echo '#comment' >commentfile
614 echo '' >>commentfile
615 echo '####' >>commentfile
616 get_tag_header commentfile-annotated-tag $commit commit $time >expect
617 test_expect_success \
618 'creating a tag with #comments in the -F messagefile should succeed' '
619 git tag -F commentfile commentfile-annotated-tag &&
620 get_tag_msg commentfile-annotated-tag >actual &&
621 test_cmp expect actual
624 printf '#comment' >commentnonlfile
625 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
626 test_expect_success \
627 'creating a tag with a file of #comment and no newline should succeed' '
628 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
629 get_tag_msg commentnonlfile-annotated-tag >actual &&
630 test_cmp expect actual
633 # listing messages for annotated non-signed tags:
635 test_expect_success \
636 'listing the one-line message of a non-signed tag should succeed' '
637 git tag -m "A msg" tag-one-line &&
639 echo "tag-one-line" >expect &&
640 git tag -l | grep "^tag-one-line" >actual &&
641 test_cmp expect actual &&
642 git tag -n0 -l | grep "^tag-one-line" >actual &&
643 test_cmp expect actual &&
644 git tag -n0 -l tag-one-line >actual &&
645 test_cmp expect actual &&
647 git tag -n0 | grep "^tag-one-line" >actual &&
648 test_cmp expect actual &&
649 git tag -n0 tag-one-line >actual &&
650 test_cmp expect actual &&
652 echo "tag-one-line A msg" >expect &&
653 git tag -n1 -l | grep "^tag-one-line" >actual &&
654 test_cmp expect actual &&
655 git tag -n -l | grep "^tag-one-line" >actual &&
656 test_cmp expect actual &&
657 git tag -n1 -l tag-one-line >actual &&
658 test_cmp expect actual &&
659 git tag -n2 -l tag-one-line >actual &&
660 test_cmp expect actual &&
661 git tag -n999 -l tag-one-line >actual &&
662 test_cmp expect actual
665 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
666 >expect &&
667 git tag -n 100 >actual &&
668 test_cmp expect actual &&
670 git tag -m "A msg" 100 &&
671 echo "100 A msg" >expect &&
672 git tag -n 100 >actual &&
673 test_cmp expect actual
676 test_expect_success \
677 'listing the zero-lines message of a non-signed tag should succeed' '
678 git tag -m "" tag-zero-lines &&
680 echo "tag-zero-lines" >expect &&
681 git tag -l | grep "^tag-zero-lines" >actual &&
682 test_cmp expect actual &&
683 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
684 test_cmp expect actual &&
685 git tag -n0 -l tag-zero-lines >actual &&
686 test_cmp expect actual &&
688 echo "tag-zero-lines " >expect &&
689 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
690 test_cmp expect actual &&
691 git tag -n -l | grep "^tag-zero-lines" >actual &&
692 test_cmp expect actual &&
693 git tag -n1 -l tag-zero-lines >actual &&
694 test_cmp expect actual &&
695 git tag -n2 -l tag-zero-lines >actual &&
696 test_cmp expect actual &&
697 git tag -n999 -l tag-zero-lines >actual &&
698 test_cmp expect actual
701 echo 'tag line one' >annotagmsg
702 echo 'tag line two' >>annotagmsg
703 echo 'tag line three' >>annotagmsg
704 test_expect_success \
705 'listing many message lines of a non-signed tag should succeed' '
706 git tag -F annotagmsg tag-lines &&
708 echo "tag-lines" >expect &&
709 git tag -l | grep "^tag-lines" >actual &&
710 test_cmp expect actual &&
711 git tag -n0 -l | grep "^tag-lines" >actual &&
712 test_cmp expect actual &&
713 git tag -n0 -l tag-lines >actual &&
714 test_cmp expect actual &&
716 echo "tag-lines tag line one" >expect &&
717 git tag -n1 -l | grep "^tag-lines" >actual &&
718 test_cmp expect actual &&
719 git tag -n -l | grep "^tag-lines" >actual &&
720 test_cmp expect actual &&
721 git tag -n1 -l tag-lines >actual &&
722 test_cmp expect actual &&
724 echo " tag line two" >>expect &&
725 git tag -n2 -l | grep "^ *tag.line" >actual &&
726 test_cmp expect actual &&
727 git tag -n2 -l tag-lines >actual &&
728 test_cmp expect actual &&
730 echo " tag line three" >>expect &&
731 git tag -n3 -l | grep "^ *tag.line" >actual &&
732 test_cmp expect actual &&
733 git tag -n3 -l tag-lines >actual &&
734 test_cmp expect actual &&
735 git tag -n4 -l | grep "^ *tag.line" >actual &&
736 test_cmp expect actual &&
737 git tag -n4 -l tag-lines >actual &&
738 test_cmp expect actual &&
739 git tag -n99 -l | grep "^ *tag.line" >actual &&
740 test_cmp expect actual &&
741 git tag -n99 -l tag-lines >actual &&
742 test_cmp expect actual
745 test_expect_success 'annotations for blobs are empty' '
746 blob=$(git hash-object -w --stdin <<-\EOF
747 Blob paragraph 1.
749 Blob paragraph 2.
751 ) &&
752 git tag tag-blob $blob &&
753 echo "tag-blob " >expect &&
754 git tag -n1 -l tag-blob >actual &&
755 test_cmp expect actual
758 # trying to verify annotated non-signed tags:
760 test_expect_success GPG \
761 'trying to verify an annotated non-signed tag should fail' '
762 tag_exists annotated-tag &&
763 test_must_fail git tag -v annotated-tag
766 test_expect_success GPG \
767 'trying to verify a file-annotated non-signed tag should fail' '
768 tag_exists file-annotated-tag &&
769 test_must_fail git tag -v file-annotated-tag
772 test_expect_success GPG \
773 'trying to verify two annotated non-signed tags should fail' '
774 tag_exists annotated-tag file-annotated-tag &&
775 test_must_fail git tag -v annotated-tag file-annotated-tag
778 # creating and verifying signed tags:
780 get_tag_header signed-tag $commit commit $time >expect
781 echo 'A signed tag message' >>expect
782 echo '-----BEGIN PGP SIGNATURE-----' >>expect
783 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
784 git tag -s -m "A signed tag message" signed-tag &&
785 get_tag_msg signed-tag >actual &&
786 test_cmp expect actual
789 get_tag_header u-signed-tag $commit commit $time >expect
790 echo 'Another message' >>expect
791 echo '-----BEGIN PGP SIGNATURE-----' >>expect
792 test_expect_success GPG 'sign with a given key id' '
794 git tag -u committer@example.com -m "Another message" u-signed-tag &&
795 get_tag_msg u-signed-tag >actual &&
796 test_cmp expect actual
800 test_expect_success GPG 'sign with an unknown id (1)' '
802 test_must_fail git tag -u author@example.com \
803 -m "Another message" o-signed-tag
807 test_expect_success GPG 'sign with an unknown id (2)' '
809 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
813 cat >fakeeditor <<'EOF'
814 #!/bin/sh
815 test -n "$1" && exec >"$1"
816 echo A signed tag message
817 echo from a fake editor.
819 chmod +x fakeeditor
821 get_tag_header implied-sign $commit commit $time >expect
822 ./fakeeditor >>expect
823 echo '-----BEGIN PGP SIGNATURE-----' >>expect
824 test_expect_success GPG '-u implies signed tag' '
825 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
826 get_tag_msg implied-sign >actual &&
827 test_cmp expect actual
830 cat >sigmsgfile <<EOF
831 Another signed tag
832 message in a file.
834 get_tag_header file-signed-tag $commit commit $time >expect
835 cat sigmsgfile >>expect
836 echo '-----BEGIN PGP SIGNATURE-----' >>expect
837 test_expect_success GPG \
838 'creating a signed tag with -F messagefile should succeed' '
839 git tag -s -F sigmsgfile file-signed-tag &&
840 get_tag_msg file-signed-tag >actual &&
841 test_cmp expect actual
844 cat >siginputmsg <<EOF
845 A signed tag message from
846 the standard input
848 get_tag_header stdin-signed-tag $commit commit $time >expect
849 cat siginputmsg >>expect
850 echo '-----BEGIN PGP SIGNATURE-----' >>expect
851 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
852 git tag -s -F - stdin-signed-tag <siginputmsg &&
853 get_tag_msg stdin-signed-tag >actual &&
854 test_cmp expect actual
857 get_tag_header implied-annotate $commit commit $time >expect
858 ./fakeeditor >>expect
859 echo '-----BEGIN PGP SIGNATURE-----' >>expect
860 test_expect_success GPG '-s implies annotated tag' '
861 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
862 get_tag_msg implied-annotate >actual &&
863 test_cmp expect actual
866 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
867 echo "A message" >>expect
868 echo '-----BEGIN PGP SIGNATURE-----' >>expect
869 test_expect_success GPG \
870 'git tag -s implied if configured with tag.forcesignannotated' \
871 'test_config tag.forcesignannotated true &&
872 git tag -m "A message" forcesignannotated-implied-sign &&
873 get_tag_msg forcesignannotated-implied-sign >actual &&
874 test_cmp expect actual
877 test_expect_success GPG \
878 'lightweight with no message when configured with tag.forcesignannotated' \
879 'test_config tag.forcesignannotated true &&
880 git tag forcesignannotated-lightweight &&
881 tag_exists forcesignannotated-lightweight &&
882 test_must_fail git tag -v forcesignannotated-no-message
885 get_tag_header forcesignannotated-annotate $commit commit $time >expect
886 echo "A message" >>expect
887 test_expect_success GPG \
888 'git tag -a disable configured tag.forcesignannotated' \
889 'test_config tag.forcesignannotated true &&
890 git tag -a -m "A message" forcesignannotated-annotate &&
891 get_tag_msg forcesignannotated-annotate >actual &&
892 test_cmp expect actual &&
893 test_must_fail git tag -v forcesignannotated-annotate
896 get_tag_header forcesignannotated-disabled $commit commit $time >expect
897 echo "A message" >>expect
898 echo '-----BEGIN PGP SIGNATURE-----' >>expect
899 test_expect_success GPG \
900 'git tag --sign enable GPG sign' \
901 'test_config tag.forcesignannotated false &&
902 git tag --sign -m "A message" forcesignannotated-disabled &&
903 get_tag_msg forcesignannotated-disabled >actual &&
904 test_cmp expect actual
907 test_expect_success GPG \
908 'trying to create a signed tag with non-existing -F file should fail' '
909 ! test -f nonexistingfile &&
910 ! tag_exists nosigtag &&
911 test_must_fail git tag -s -F nonexistingfile nosigtag &&
912 ! tag_exists nosigtag
915 test_expect_success GPG 'verifying a signed tag should succeed' \
916 'git tag -v signed-tag'
918 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
919 'git tag -v signed-tag file-signed-tag'
921 test_expect_success GPG \
922 'verifying many signed and non-signed tags should fail' '
923 test_must_fail git tag -v signed-tag annotated-tag &&
924 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
925 test_must_fail git tag -v annotated-tag \
926 file-signed-tag file-annotated-tag &&
927 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
930 test_expect_success GPG 'verifying a forged tag should fail' '
931 forged=$(git cat-file tag signed-tag |
932 sed -e "s/signed-tag/forged-tag/" |
933 git mktag) &&
934 git tag forged-tag $forged &&
935 test_must_fail git tag -v forged-tag
938 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
939 cat >expect <<-\EOF &&
940 tagname : signed-tag
942 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
943 test_cmp expect actual
946 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
947 >expect &&
948 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
949 test_cmp expect actual
952 # blank and empty messages for signed tags:
954 get_tag_header empty-signed-tag $commit commit $time >expect
955 echo '-----BEGIN PGP SIGNATURE-----' >>expect
956 test_expect_success GPG \
957 'creating a signed tag with an empty -m message should succeed' '
958 git tag -s -m "" empty-signed-tag &&
959 get_tag_msg empty-signed-tag >actual &&
960 test_cmp expect actual &&
961 git tag -v empty-signed-tag
964 >sigemptyfile
965 get_tag_header emptyfile-signed-tag $commit commit $time >expect
966 echo '-----BEGIN PGP SIGNATURE-----' >>expect
967 test_expect_success GPG \
968 'creating a signed tag with an empty -F messagefile should succeed' '
969 git tag -s -F sigemptyfile emptyfile-signed-tag &&
970 get_tag_msg emptyfile-signed-tag >actual &&
971 test_cmp expect actual &&
972 git tag -v emptyfile-signed-tag
975 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
976 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
977 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
978 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
979 get_tag_header blanks-signed-tag $commit commit $time >expect
980 cat >>expect <<EOF
981 Leading blank lines
983 Repeated blank lines
985 Trailing spaces
987 Trailing blank lines
989 echo '-----BEGIN PGP SIGNATURE-----' >>expect
990 test_expect_success GPG \
991 'extra blanks in the message for a signed tag should be removed' '
992 git tag -s -F sigblanksfile blanks-signed-tag &&
993 get_tag_msg blanks-signed-tag >actual &&
994 test_cmp expect actual &&
995 git tag -v blanks-signed-tag
998 get_tag_header blank-signed-tag $commit commit $time >expect
999 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1000 test_expect_success GPG \
1001 'creating a signed tag with a blank -m message should succeed' '
1002 git tag -s -m " " blank-signed-tag &&
1003 get_tag_msg blank-signed-tag >actual &&
1004 test_cmp expect actual &&
1005 git tag -v blank-signed-tag
1008 echo ' ' >sigblankfile
1009 echo '' >>sigblankfile
1010 echo ' ' >>sigblankfile
1011 get_tag_header blankfile-signed-tag $commit commit $time >expect
1012 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1013 test_expect_success GPG \
1014 'creating a signed tag with blank -F file with spaces should succeed' '
1015 git tag -s -F sigblankfile blankfile-signed-tag &&
1016 get_tag_msg blankfile-signed-tag >actual &&
1017 test_cmp expect actual &&
1018 git tag -v blankfile-signed-tag
1021 printf ' ' >sigblanknonlfile
1022 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1023 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1024 test_expect_success GPG \
1025 'creating a signed tag with spaces and no newline should succeed' '
1026 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1027 get_tag_msg blanknonlfile-signed-tag >actual &&
1028 test_cmp expect actual &&
1029 git tag -v signed-tag
1032 # messages with commented lines for signed tags:
1034 cat >sigcommentsfile <<EOF
1035 # A comment
1037 ############
1038 The message.
1039 ############
1040 One line.
1043 # commented lines
1044 # commented lines
1046 Another line.
1047 # comments
1049 Last line.
1051 get_tag_header comments-signed-tag $commit commit $time >expect
1052 cat >>expect <<EOF
1053 The message.
1054 One line.
1056 Another line.
1058 Last line.
1060 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1061 test_expect_success GPG \
1062 'creating a signed tag with a -F file with #comments should succeed' '
1063 git tag -s -F sigcommentsfile comments-signed-tag &&
1064 get_tag_msg comments-signed-tag >actual &&
1065 test_cmp expect actual &&
1066 git tag -v comments-signed-tag
1069 get_tag_header comment-signed-tag $commit commit $time >expect
1070 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1071 test_expect_success GPG \
1072 'creating a signed tag with #commented -m message should succeed' '
1073 git tag -s -m "#comment" comment-signed-tag &&
1074 get_tag_msg comment-signed-tag >actual &&
1075 test_cmp expect actual &&
1076 git tag -v comment-signed-tag
1079 echo '#comment' >sigcommentfile
1080 echo '' >>sigcommentfile
1081 echo '####' >>sigcommentfile
1082 get_tag_header commentfile-signed-tag $commit commit $time >expect
1083 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1084 test_expect_success GPG \
1085 'creating a signed tag with #commented -F messagefile should succeed' '
1086 git tag -s -F sigcommentfile commentfile-signed-tag &&
1087 get_tag_msg commentfile-signed-tag >actual &&
1088 test_cmp expect actual &&
1089 git tag -v commentfile-signed-tag
1092 printf '#comment' >sigcommentnonlfile
1093 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1094 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1095 test_expect_success GPG \
1096 'creating a signed tag with a #comment and no newline should succeed' '
1097 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1098 get_tag_msg commentnonlfile-signed-tag >actual &&
1099 test_cmp expect actual &&
1100 git tag -v commentnonlfile-signed-tag
1103 # listing messages for signed tags:
1105 test_expect_success GPG \
1106 'listing the one-line message of a signed tag should succeed' '
1107 git tag -s -m "A message line signed" stag-one-line &&
1109 echo "stag-one-line" >expect &&
1110 git tag -l | grep "^stag-one-line" >actual &&
1111 test_cmp expect actual &&
1112 git tag -n0 -l | grep "^stag-one-line" >actual &&
1113 test_cmp expect actual &&
1114 git tag -n0 -l stag-one-line >actual &&
1115 test_cmp expect actual &&
1117 echo "stag-one-line A message line signed" >expect &&
1118 git tag -n1 -l | grep "^stag-one-line" >actual &&
1119 test_cmp expect actual &&
1120 git tag -n -l | grep "^stag-one-line" >actual &&
1121 test_cmp expect actual &&
1122 git tag -n1 -l stag-one-line >actual &&
1123 test_cmp expect actual &&
1124 git tag -n2 -l stag-one-line >actual &&
1125 test_cmp expect actual &&
1126 git tag -n999 -l stag-one-line >actual &&
1127 test_cmp expect actual
1130 test_expect_success GPG \
1131 'listing the zero-lines message of a signed tag should succeed' '
1132 git tag -s -m "" stag-zero-lines &&
1134 echo "stag-zero-lines" >expect &&
1135 git tag -l | grep "^stag-zero-lines" >actual &&
1136 test_cmp expect actual &&
1137 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1138 test_cmp expect actual &&
1139 git tag -n0 -l stag-zero-lines >actual &&
1140 test_cmp expect actual &&
1142 echo "stag-zero-lines " >expect &&
1143 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1144 test_cmp expect actual &&
1145 git tag -n -l | grep "^stag-zero-lines" >actual &&
1146 test_cmp expect actual &&
1147 git tag -n1 -l stag-zero-lines >actual &&
1148 test_cmp expect actual &&
1149 git tag -n2 -l stag-zero-lines >actual &&
1150 test_cmp expect actual &&
1151 git tag -n999 -l stag-zero-lines >actual &&
1152 test_cmp expect actual
1155 echo 'stag line one' >sigtagmsg
1156 echo 'stag line two' >>sigtagmsg
1157 echo 'stag line three' >>sigtagmsg
1158 test_expect_success GPG \
1159 'listing many message lines of a signed tag should succeed' '
1160 git tag -s -F sigtagmsg stag-lines &&
1162 echo "stag-lines" >expect &&
1163 git tag -l | grep "^stag-lines" >actual &&
1164 test_cmp expect actual &&
1165 git tag -n0 -l | grep "^stag-lines" >actual &&
1166 test_cmp expect actual &&
1167 git tag -n0 -l stag-lines >actual &&
1168 test_cmp expect actual &&
1170 echo "stag-lines stag line one" >expect &&
1171 git tag -n1 -l | grep "^stag-lines" >actual &&
1172 test_cmp expect actual &&
1173 git tag -n -l | grep "^stag-lines" >actual &&
1174 test_cmp expect actual &&
1175 git tag -n1 -l stag-lines >actual &&
1176 test_cmp expect actual &&
1178 echo " stag line two" >>expect &&
1179 git tag -n2 -l | grep "^ *stag.line" >actual &&
1180 test_cmp expect actual &&
1181 git tag -n2 -l stag-lines >actual &&
1182 test_cmp expect actual &&
1184 echo " stag line three" >>expect &&
1185 git tag -n3 -l | grep "^ *stag.line" >actual &&
1186 test_cmp expect actual &&
1187 git tag -n3 -l stag-lines >actual &&
1188 test_cmp expect actual &&
1189 git tag -n4 -l | grep "^ *stag.line" >actual &&
1190 test_cmp expect actual &&
1191 git tag -n4 -l stag-lines >actual &&
1192 test_cmp expect actual &&
1193 git tag -n99 -l | grep "^ *stag.line" >actual &&
1194 test_cmp expect actual &&
1195 git tag -n99 -l stag-lines >actual &&
1196 test_cmp expect actual
1199 # tags pointing to objects different from commits:
1201 tree=$(git rev-parse HEAD^{tree})
1202 blob=$(git rev-parse HEAD:foo)
1203 tag=$(git rev-parse signed-tag 2>/dev/null)
1205 get_tag_header tree-signed-tag $tree tree $time >expect
1206 echo "A message for a tree" >>expect
1207 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1208 test_expect_success GPG \
1209 'creating a signed tag pointing to a tree should succeed' '
1210 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1211 get_tag_msg tree-signed-tag >actual &&
1212 test_cmp expect actual
1215 get_tag_header blob-signed-tag $blob blob $time >expect
1216 echo "A message for a blob" >>expect
1217 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1218 test_expect_success GPG \
1219 'creating a signed tag pointing to a blob should succeed' '
1220 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1221 get_tag_msg blob-signed-tag >actual &&
1222 test_cmp expect actual
1225 get_tag_header tag-signed-tag $tag tag $time >expect
1226 echo "A message for another tag" >>expect
1227 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1228 test_expect_success GPG \
1229 'creating a signed tag pointing to another tag should succeed' '
1230 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1231 get_tag_msg tag-signed-tag >actual &&
1232 test_cmp expect actual
1235 # usage with rfc1991 signatures
1236 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1237 echo "RFC1991 signed tag" >>expect
1238 echo '-----BEGIN PGP MESSAGE-----' >>expect
1239 test_expect_success GPG,RFC1991 \
1240 'creating a signed tag with rfc1991' '
1241 echo "rfc1991" >gpghome/gpg.conf &&
1242 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1243 get_tag_msg rfc1991-signed-tag >actual &&
1244 test_cmp expect actual
1247 cat >fakeeditor <<'EOF'
1248 #!/bin/sh
1249 cp "$1" actual
1251 chmod +x fakeeditor
1253 test_expect_success GPG,RFC1991 \
1254 'reediting a signed tag body omits signature' '
1255 echo "rfc1991" >gpghome/gpg.conf &&
1256 echo "RFC1991 signed tag" >expect &&
1257 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1258 test_cmp expect actual
1261 test_expect_success GPG,RFC1991 \
1262 'verifying rfc1991 signature' '
1263 echo "rfc1991" >gpghome/gpg.conf &&
1264 git tag -v rfc1991-signed-tag
1267 test_expect_success GPG,RFC1991 \
1268 'list tag with rfc1991 signature' '
1269 echo "rfc1991" >gpghome/gpg.conf &&
1270 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1271 git tag -l -n1 rfc1991-signed-tag >actual &&
1272 test_cmp expect actual &&
1273 git tag -l -n2 rfc1991-signed-tag >actual &&
1274 test_cmp expect actual &&
1275 git tag -l -n999 rfc1991-signed-tag >actual &&
1276 test_cmp expect actual
1279 rm -f gpghome/gpg.conf
1281 test_expect_success GPG,RFC1991 \
1282 'verifying rfc1991 signature without --rfc1991' '
1283 git tag -v rfc1991-signed-tag
1286 test_expect_success GPG,RFC1991 \
1287 'list tag with rfc1991 signature without --rfc1991' '
1288 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1289 git tag -l -n1 rfc1991-signed-tag >actual &&
1290 test_cmp expect actual &&
1291 git tag -l -n2 rfc1991-signed-tag >actual &&
1292 test_cmp expect actual &&
1293 git tag -l -n999 rfc1991-signed-tag >actual &&
1294 test_cmp expect actual
1297 test_expect_success GPG,RFC1991 \
1298 'reediting a signed tag body omits signature' '
1299 echo "RFC1991 signed tag" >expect &&
1300 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1301 test_cmp expect actual
1304 # try to sign with bad user.signingkey
1305 test_expect_success GPG \
1306 'git tag -s fails if gpg is misconfigured (bad key)' \
1307 'test_config user.signingkey BobTheMouse &&
1308 test_must_fail git tag -s -m tail tag-gpg-failure'
1310 # try to produce invalid signature
1311 test_expect_success GPG \
1312 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1313 'test_config gpg.program echo &&
1314 test_must_fail git tag -s -m tail tag-gpg-failure'
1317 # try to verify without gpg:
1319 rm -rf gpghome
1320 test_expect_success GPG \
1321 'verify signed tag fails when public key is not present' \
1322 'test_must_fail git tag -v signed-tag'
1324 test_expect_success \
1325 'git tag -a fails if tag annotation is empty' '
1326 ! (GIT_EDITOR=cat git tag -a initial-comment)
1329 test_expect_success \
1330 'message in editor has initial comment' '
1331 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1334 test_expect_success 'message in editor has initial comment: first line' '
1335 # check the first line --- should be empty
1336 echo >first.expect &&
1337 sed -e 1q <actual >first.actual &&
1338 test_i18ncmp first.expect first.actual
1341 test_expect_success \
1342 'message in editor has initial comment: remainder' '
1343 # remove commented lines from the remainder -- should be empty
1344 >rest.expect &&
1345 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1346 test_cmp rest.expect rest.actual
1349 get_tag_header reuse $commit commit $time >expect
1350 echo "An annotation to be reused" >> expect
1351 test_expect_success \
1352 'overwriting an annoted tag should use its previous body' '
1353 git tag -a -m "An annotation to be reused" reuse &&
1354 GIT_EDITOR=true git tag -f -a reuse &&
1355 get_tag_msg reuse >actual &&
1356 test_cmp expect actual
1359 test_expect_success 'filename for the message is relative to cwd' '
1360 mkdir subdir &&
1361 echo "Tag message in top directory" >msgfile-5 &&
1362 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1364 cd subdir &&
1365 git tag -a -F msgfile-5 tag-from-subdir
1366 ) &&
1367 git cat-file tag tag-from-subdir | grep "in sub directory"
1370 test_expect_success 'filename for the message is relative to cwd' '
1371 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1373 cd subdir &&
1374 git tag -a -F msgfile-6 tag-from-subdir-2
1375 ) &&
1376 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1379 # create a few more commits to test --contains
1381 hash1=$(git rev-parse HEAD)
1383 test_expect_success 'creating second commit and tag' '
1384 echo foo-2.0 >foo &&
1385 git add foo &&
1386 git commit -m second &&
1387 git tag v2.0
1390 hash2=$(git rev-parse HEAD)
1392 test_expect_success 'creating third commit without tag' '
1393 echo foo-dev >foo &&
1394 git add foo &&
1395 git commit -m third
1398 hash3=$(git rev-parse HEAD)
1400 # simple linear checks of --continue
1402 cat > expected <<EOF
1403 v0.2.1
1404 v1.0
1405 v1.0.1
1406 v1.1.3
1407 v2.0
1410 test_expect_success 'checking that first commit is in all tags (hash)' "
1411 git tag -l --contains $hash1 v* >actual &&
1412 test_cmp expected actual
1415 # other ways of specifying the commit
1416 test_expect_success 'checking that first commit is in all tags (tag)' "
1417 git tag -l --contains v1.0 v* >actual &&
1418 test_cmp expected actual
1421 test_expect_success 'checking that first commit is in all tags (relative)' "
1422 git tag -l --contains HEAD~2 v* >actual &&
1423 test_cmp expected actual
1426 # All the --contains tests above, but with --no-contains
1427 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1428 >expected &&
1429 git tag -l --no-contains $hash1 v* >actual &&
1430 test_cmp expected actual
1433 test_expect_success 'checking that first commit is in all tags (tag)' "
1434 git tag -l --no-contains v1.0 v* >actual &&
1435 test_cmp expected actual
1438 test_expect_success 'checking that first commit is in all tags (relative)' "
1439 git tag -l --no-contains HEAD~2 v* >actual &&
1440 test_cmp expected actual
1443 cat > expected <<EOF
1444 v2.0
1447 test_expect_success 'checking that second commit only has one tag' "
1448 git tag -l --contains $hash2 v* >actual &&
1449 test_cmp expected actual
1452 cat > expected <<EOF
1453 v0.2.1
1454 v1.0
1455 v1.0.1
1456 v1.1.3
1459 test_expect_success 'inverse of the last test, with --no-contains' "
1460 git tag -l --no-contains $hash2 v* >actual &&
1461 test_cmp expected actual
1464 cat > expected <<EOF
1467 test_expect_success 'checking that third commit has no tags' "
1468 git tag -l --contains $hash3 v* >actual &&
1469 test_cmp expected actual
1472 cat > expected <<EOF
1473 v0.2.1
1474 v1.0
1475 v1.0.1
1476 v1.1.3
1477 v2.0
1480 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1481 git tag -l --no-contains $hash3 v* >actual &&
1482 test_cmp expected actual
1485 # how about a simple merge?
1487 test_expect_success 'creating simple branch' '
1488 git branch stable v2.0 &&
1489 git checkout stable &&
1490 echo foo-3.0 > foo &&
1491 git commit foo -m fourth &&
1492 git tag v3.0
1495 hash4=$(git rev-parse HEAD)
1497 cat > expected <<EOF
1498 v3.0
1501 test_expect_success 'checking that branch head only has one tag' "
1502 git tag -l --contains $hash4 v* >actual &&
1503 test_cmp expected actual
1506 cat > expected <<EOF
1507 v0.2.1
1508 v1.0
1509 v1.0.1
1510 v1.1.3
1511 v2.0
1514 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1515 git tag -l --no-contains $hash4 v* >actual &&
1516 test_cmp expected actual
1519 test_expect_success 'merging original branch into this branch' '
1520 git merge --strategy=ours master &&
1521 git tag v4.0
1524 cat > expected <<EOF
1525 v4.0
1528 test_expect_success 'checking that original branch head has one tag now' "
1529 git tag -l --contains $hash3 v* >actual &&
1530 test_cmp expected actual
1533 cat > expected <<EOF
1534 v0.2.1
1535 v1.0
1536 v1.0.1
1537 v1.1.3
1538 v2.0
1539 v3.0
1542 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1543 git tag -l --no-contains $hash3 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
1553 v3.0
1554 v4.0
1557 test_expect_success 'checking that initial commit is in all tags' "
1558 git tag -l --contains $hash1 v* >actual &&
1559 test_cmp expected actual
1562 test_expect_success 'checking that --contains can be used in non-list mode' '
1563 git tag --contains $hash1 v* >actual &&
1564 test_cmp expected actual
1567 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1568 >expected &&
1569 git tag -l --no-contains $hash1 v* >actual &&
1570 test_cmp expected actual
1573 # mixing modes and options:
1575 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1576 test_must_fail git tag -a &&
1577 test_must_fail git tag -a -l &&
1578 test_must_fail git tag -s &&
1579 test_must_fail git tag -s -l &&
1580 test_must_fail git tag -m &&
1581 test_must_fail git tag -m -l &&
1582 test_must_fail git tag -m "hlagh" &&
1583 test_must_fail git tag -m "hlagh" -l &&
1584 test_must_fail git tag -F &&
1585 test_must_fail git tag -F -l &&
1586 test_must_fail git tag -f &&
1587 test_must_fail git tag -f -l &&
1588 test_must_fail git tag -a -s -m -F &&
1589 test_must_fail git tag -a -s -m -F -l &&
1590 test_must_fail git tag -l -v &&
1591 test_must_fail git tag -l -d &&
1592 test_must_fail git tag -l -v -d &&
1593 test_must_fail git tag -n 100 -v &&
1594 test_must_fail git tag -l -m msg &&
1595 test_must_fail git tag -l -F some file &&
1596 test_must_fail git tag -v -s &&
1597 test_must_fail git tag --contains tag-tree &&
1598 test_must_fail git tag --contains tag-blob &&
1599 test_must_fail git tag --no-contains tag-tree &&
1600 test_must_fail git tag --no-contains tag-blob &&
1601 test_must_fail git tag --contains --no-contains &&
1602 test_must_fail git tag --no-with HEAD &&
1603 test_must_fail git tag --no-without HEAD
1606 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1608 test_expect_success "mixing incompatible modes with $option is forbidden" "
1609 test_must_fail git tag -d $option HEAD &&
1610 test_must_fail git tag -d $option HEAD some-tag &&
1611 test_must_fail git tag -v $option HEAD
1613 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1614 git tag -n $option HEAD HEAD &&
1615 git tag $option HEAD HEAD &&
1616 git tag $option
1618 done
1620 # check points-at
1622 test_expect_success '--points-at can be used in non-list mode' '
1623 echo v4.0 >expect &&
1624 git tag --points-at=v4.0 "v*" >actual &&
1625 test_cmp expect actual
1628 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1629 echo v4.0 >expect &&
1630 git tag --points-at >actual &&
1631 test_cmp expect actual
1634 test_expect_success '--points-at finds lightweight tags' '
1635 echo v4.0 >expect &&
1636 git tag --points-at v4.0 >actual &&
1637 test_cmp expect actual
1640 test_expect_success '--points-at finds annotated tags of commits' '
1641 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1642 echo annotated-v4.0 >expect &&
1643 git tag -l --points-at v4.0 "annotated*" >actual &&
1644 test_cmp expect actual
1647 test_expect_success '--points-at finds annotated tags of tags' '
1648 git tag -m "describing the v4.0 tag object" \
1649 annotated-again-v4.0 annotated-v4.0 &&
1650 cat >expect <<-\EOF &&
1651 annotated-again-v4.0
1652 annotated-v4.0
1654 git tag --points-at=annotated-v4.0 >actual &&
1655 test_cmp expect actual
1658 test_expect_success 'multiple --points-at are OR-ed together' '
1659 cat >expect <<-\EOF &&
1660 v2.0
1661 v3.0
1663 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1664 test_cmp expect actual
1667 test_expect_success 'lexical sort' '
1668 git tag foo1.3 &&
1669 git tag foo1.6 &&
1670 git tag foo1.10 &&
1671 git tag -l --sort=refname "foo*" >actual &&
1672 cat >expect <<-\EOF &&
1673 foo1.10
1674 foo1.3
1675 foo1.6
1677 test_cmp expect actual
1680 test_expect_success 'version sort' '
1681 git tag -l --sort=version:refname "foo*" >actual &&
1682 cat >expect <<-\EOF &&
1683 foo1.3
1684 foo1.6
1685 foo1.10
1687 test_cmp expect actual
1690 test_expect_success 'reverse version sort' '
1691 git tag -l --sort=-version:refname "foo*" >actual &&
1692 cat >expect <<-\EOF &&
1693 foo1.10
1694 foo1.6
1695 foo1.3
1697 test_cmp expect actual
1700 test_expect_success 'reverse lexical sort' '
1701 git tag -l --sort=-refname "foo*" >actual &&
1702 cat >expect <<-\EOF &&
1703 foo1.6
1704 foo1.3
1705 foo1.10
1707 test_cmp expect actual
1710 test_expect_success 'configured lexical sort' '
1711 test_config tag.sort "v:refname" &&
1712 git tag -l "foo*" >actual &&
1713 cat >expect <<-\EOF &&
1714 foo1.3
1715 foo1.6
1716 foo1.10
1718 test_cmp expect actual
1721 test_expect_success 'option override configured sort' '
1722 test_config tag.sort "v:refname" &&
1723 git tag -l --sort=-refname "foo*" >actual &&
1724 cat >expect <<-\EOF &&
1725 foo1.6
1726 foo1.3
1727 foo1.10
1729 test_cmp expect actual
1732 test_expect_success 'invalid sort parameter on command line' '
1733 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1736 test_expect_success 'invalid sort parameter in configuratoin' '
1737 test_config tag.sort "v:notvalid" &&
1738 test_must_fail git tag -l "foo*"
1741 test_expect_success 'version sort with prerelease reordering' '
1742 test_config versionsort.prereleaseSuffix -rc &&
1743 git tag foo1.6-rc1 &&
1744 git tag foo1.6-rc2 &&
1745 git tag -l --sort=version:refname "foo*" >actual &&
1746 cat >expect <<-\EOF &&
1747 foo1.3
1748 foo1.6-rc1
1749 foo1.6-rc2
1750 foo1.6
1751 foo1.10
1753 test_cmp expect actual
1756 test_expect_success 'reverse version sort with prerelease reordering' '
1757 test_config versionsort.prereleaseSuffix -rc &&
1758 git tag -l --sort=-version:refname "foo*" >actual &&
1759 cat >expect <<-\EOF &&
1760 foo1.10
1761 foo1.6
1762 foo1.6-rc2
1763 foo1.6-rc1
1764 foo1.3
1766 test_cmp expect actual
1769 test_expect_success 'version sort with prerelease reordering and common leading character' '
1770 test_config versionsort.prereleaseSuffix -before &&
1771 git tag foo1.7-before1 &&
1772 git tag foo1.7 &&
1773 git tag foo1.7-after1 &&
1774 git tag -l --sort=version:refname "foo1.7*" >actual &&
1775 cat >expect <<-\EOF &&
1776 foo1.7-before1
1777 foo1.7
1778 foo1.7-after1
1780 test_cmp expect actual
1783 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1784 test_config versionsort.prereleaseSuffix -before &&
1785 git config --add versionsort.prereleaseSuffix -after &&
1786 git tag -l --sort=version:refname "foo1.7*" >actual &&
1787 cat >expect <<-\EOF &&
1788 foo1.7-before1
1789 foo1.7-after1
1790 foo1.7
1792 test_cmp expect actual
1795 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1796 test_config versionsort.prereleaseSuffix -bar &&
1797 git config --add versionsort.prereleaseSuffix -foo-baz &&
1798 git config --add versionsort.prereleaseSuffix -foo-bar &&
1799 git tag foo1.8-foo-bar &&
1800 git tag foo1.8-foo-baz &&
1801 git tag foo1.8 &&
1802 git tag -l --sort=version:refname "foo1.8*" >actual &&
1803 cat >expect <<-\EOF &&
1804 foo1.8-foo-baz
1805 foo1.8-foo-bar
1806 foo1.8
1808 test_cmp expect actual
1811 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1812 test_config versionsort.prereleaseSuffix -pre &&
1813 git config --add versionsort.prereleaseSuffix -prerelease &&
1814 git tag foo1.9-pre1 &&
1815 git tag foo1.9-pre2 &&
1816 git tag foo1.9-prerelease1 &&
1817 git tag -l --sort=version:refname "foo1.9*" >actual &&
1818 cat >expect <<-\EOF &&
1819 foo1.9-pre1
1820 foo1.9-pre2
1821 foo1.9-prerelease1
1823 test_cmp expect actual
1826 test_expect_success 'version sort with general suffix reordering' '
1827 test_config versionsort.suffix -alpha &&
1828 git config --add versionsort.suffix -beta &&
1829 git config --add versionsort.suffix "" &&
1830 git config --add versionsort.suffix -gamma &&
1831 git config --add versionsort.suffix -delta &&
1832 git tag foo1.10-alpha &&
1833 git tag foo1.10-beta &&
1834 git tag foo1.10-gamma &&
1835 git tag foo1.10-delta &&
1836 git tag foo1.10-unlisted-suffix &&
1837 git tag -l --sort=version:refname "foo1.10*" >actual &&
1838 cat >expect <<-\EOF &&
1839 foo1.10-alpha
1840 foo1.10-beta
1841 foo1.10
1842 foo1.10-unlisted-suffix
1843 foo1.10-gamma
1844 foo1.10-delta
1846 test_cmp expect actual
1849 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1850 test_config versionsort.suffix -before &&
1851 test_config versionsort.prereleaseSuffix -after &&
1852 git tag -l --sort=version:refname "foo1.7*" >actual &&
1853 cat >expect <<-\EOF &&
1854 foo1.7-before1
1855 foo1.7
1856 foo1.7-after1
1858 test_cmp expect actual
1861 test_expect_success 'version sort with very long prerelease suffix' '
1862 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1863 git tag -l --sort=version:refname
1866 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1867 >expect &&
1868 i=1 &&
1869 while test $i -lt 8000
1871 echo "commit refs/heads/master
1872 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1873 data <<EOF
1874 commit #$i
1875 EOF"
1876 test $i = 1 && echo "from refs/heads/master^0"
1877 i=$(($i + 1))
1878 done | git fast-import &&
1879 git checkout master &&
1880 git tag far-far-away HEAD^ &&
1881 run_with_limited_stack git tag --contains HEAD >actual &&
1882 test_cmp expect actual &&
1883 run_with_limited_stack git tag --no-contains HEAD >actual &&
1884 test_line_count "-gt" 10 actual
1887 test_expect_success '--format should list tags as per format given' '
1888 cat >expect <<-\EOF &&
1889 refname : refs/tags/v1.0
1890 refname : refs/tags/v1.0.1
1891 refname : refs/tags/v1.1.3
1893 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1894 test_cmp expect actual
1897 test_expect_success "set up color tests" '
1898 echo "<RED>v1.0<RESET>" >expect.color &&
1899 echo "v1.0" >expect.bare &&
1900 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1903 test_expect_success '%(color) omitted without tty' '
1904 TERM=vt100 git tag $color_args >actual.raw &&
1905 test_decode_color <actual.raw >actual &&
1906 test_cmp expect.bare actual
1909 test_expect_success TTY '%(color) present with tty' '
1910 test_terminal git tag $color_args >actual.raw &&
1911 test_decode_color <actual.raw >actual &&
1912 test_cmp expect.color actual
1915 test_expect_success '--color overrides auto-color' '
1916 git tag --color $color_args >actual.raw &&
1917 test_decode_color <actual.raw >actual &&
1918 test_cmp expect.color actual
1921 test_expect_success 'color.ui=always overrides auto-color' '
1922 git -c color.ui=always tag $color_args >actual.raw &&
1923 test_decode_color <actual.raw >actual &&
1924 test_cmp expect.color actual
1927 test_expect_success 'setup --merged test tags' '
1928 git tag mergetest-1 HEAD~2 &&
1929 git tag mergetest-2 HEAD~1 &&
1930 git tag mergetest-3 HEAD
1933 test_expect_success '--merged can be used in non-list mode' '
1934 cat >expect <<-\EOF &&
1935 mergetest-1
1936 mergetest-2
1938 git tag --merged=mergetest-2 "mergetest*" >actual &&
1939 test_cmp expect actual
1942 test_expect_success '--merged is incompatible with --no-merged' '
1943 test_must_fail git tag --merged HEAD --no-merged HEAD
1946 test_expect_success '--merged shows merged tags' '
1947 cat >expect <<-\EOF &&
1948 mergetest-1
1949 mergetest-2
1951 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1952 test_cmp expect actual
1955 test_expect_success '--no-merged show unmerged tags' '
1956 cat >expect <<-\EOF &&
1957 mergetest-3
1959 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1960 test_cmp expect actual
1963 test_expect_success '--no-merged can be used in non-list mode' '
1964 git tag --no-merged=mergetest-2 mergetest-* >actual &&
1965 test_cmp expect actual
1968 test_expect_success 'ambiguous branch/tags not marked' '
1969 git tag ambiguous &&
1970 git branch ambiguous &&
1971 echo ambiguous >expect &&
1972 git tag -l ambiguous >actual &&
1973 test_cmp expect actual
1976 test_expect_success '--contains combined with --no-contains' '
1978 git init no-contains &&
1979 cd no-contains &&
1980 test_commit v0.1 &&
1981 test_commit v0.2 &&
1982 test_commit v0.3 &&
1983 test_commit v0.4 &&
1984 test_commit v0.5 &&
1985 cat >expected <<-\EOF &&
1986 v0.2
1987 v0.3
1988 v0.4
1990 git tag --contains v0.2 --no-contains v0.5 >actual &&
1991 test_cmp expected actual
1995 # As the docs say, list tags which contain a specified *commit*. We
1996 # don't recurse down to tags for trees or blobs pointed to by *those*
1997 # commits.
1998 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
1999 cd no-contains &&
2000 blob=$(git rev-parse v0.3:v0.3.t) &&
2001 tree=$(git rev-parse v0.3^{tree}) &&
2002 git tag tag-blob $blob &&
2003 git tag tag-tree $tree &&
2004 git tag --contains v0.3 >actual &&
2005 cat >expected <<-\EOF &&
2006 v0.3
2007 v0.4
2008 v0.5
2010 test_cmp expected actual &&
2011 git tag --no-contains v0.3 >actual &&
2012 cat >expected <<-\EOF &&
2013 v0.1
2014 v0.2
2016 test_cmp expected actual
2019 test_done