builtin/show: do not prune by pathspec
[git/mjg.git] / t / t7004-tag.sh
blobfa6336edf98350566fd754c9d8d252d27af45e6e
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 . ./test-lib.sh
14 . "$TEST_DIRECTORY"/lib-gpg.sh
15 . "$TEST_DIRECTORY"/lib-terminal.sh
17 # creating and listing lightweight tags:
19 tag_exists () {
20 git show-ref --quiet --verify refs/tags/"$1"
23 test_expect_success 'setup' '
24 test_oid_cache <<-EOM
25 othersigheader sha1:gpgsig-sha256
26 othersigheader sha256:gpgsig
27 EOM
30 test_expect_success 'listing all tags in an empty tree should succeed' '
31 git tag -l &&
32 git tag
35 test_expect_success 'listing all tags in an empty tree should output nothing' '
36 test $(git tag -l | wc -l) -eq 0 &&
37 test $(git tag | wc -l) -eq 0
40 test_expect_success 'sort tags, ignore case' '
42 git init sort &&
43 cd sort &&
44 test_commit initial &&
45 git tag tag-one &&
46 git tag TAG-two &&
47 git tag -l >actual &&
48 cat >expected <<-\EOF &&
49 TAG-two
50 initial
51 tag-one
52 EOF
53 test_cmp expected actual &&
54 git tag -l -i >actual &&
55 cat >expected <<-\EOF &&
56 initial
57 tag-one
58 TAG-two
59 EOF
60 test_cmp expected actual
64 test_expect_success 'looking for a tag in an empty tree should fail' \
65 '! (tag_exists mytag)'
67 test_expect_success 'creating a tag in an empty tree should fail' '
68 test_must_fail git tag mynotag &&
69 ! tag_exists mynotag
72 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
73 test_must_fail git tag mytaghead HEAD &&
74 ! tag_exists mytaghead
77 test_expect_success 'creating a tag for an unknown revision should fail' '
78 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
79 ! tag_exists mytagnorev
82 # commit used in the tests, test_tick is also called here to freeze the date:
83 test_expect_success 'creating a tag using default HEAD should succeed' '
84 test_config core.logAllRefUpdates true &&
85 test_tick &&
86 echo foo >foo &&
87 git add foo &&
88 git commit -m Foo &&
89 git tag mytag &&
90 test_must_fail git reflog exists refs/tags/mytag
93 test_expect_success 'creating a tag with --create-reflog should create reflog' '
94 git log -1 \
95 --format="format:tag: tagging %h (%s, %cd)%n" \
96 --date=format:%Y-%m-%d >expected &&
97 test_when_finished "git tag -d tag_with_reflog1" &&
98 git tag --create-reflog tag_with_reflog1 &&
99 git reflog exists refs/tags/tag_with_reflog1 &&
100 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual &&
101 test_cmp expected actual
104 test_expect_success 'annotated tag with --create-reflog has correct message' '
105 git log -1 \
106 --format="format:tag: tagging %h (%s, %cd)%n" \
107 --date=format:%Y-%m-%d >expected &&
108 test_when_finished "git tag -d tag_with_reflog2" &&
109 git tag -m "annotated tag" --create-reflog tag_with_reflog2 &&
110 git reflog exists refs/tags/tag_with_reflog2 &&
111 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 | sed -e "s/^.* //" >actual &&
112 test_cmp expected actual
115 test_expect_success '--create-reflog does not create reflog on failure' '
116 test_must_fail git tag --create-reflog mytag &&
117 test_must_fail git reflog exists refs/tags/mytag
120 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
121 test_when_finished "git tag -d tag_with_reflog3" &&
122 test_config core.logAllRefUpdates always &&
123 git tag tag_with_reflog3 &&
124 git reflog exists refs/tags/tag_with_reflog3
127 test_expect_success 'listing all tags if one exists should succeed' '
128 git tag -l &&
129 git tag
132 cat >expect <<EOF
133 mytag
135 test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
136 git tag -l -l >actual &&
137 test_cmp expect actual &&
138 git tag --list --list >actual &&
139 test_cmp expect actual &&
140 git tag --list -l --list >actual &&
141 test_cmp expect actual
144 test_expect_success 'listing all tags if one exists should output that tag' '
145 test $(git tag -l) = mytag &&
146 test $(git tag) = mytag
149 # pattern matching:
151 test_expect_success 'listing a tag using a matching pattern should succeed' \
152 'git tag -l mytag'
154 test_expect_success 'listing a tag with --ignore-case' \
155 'test $(git tag -l --ignore-case MYTAG) = mytag'
157 test_expect_success \
158 'listing a tag using a matching pattern should output that tag' \
159 'test $(git tag -l mytag) = mytag'
161 test_expect_success \
162 'listing tags using a non-matching pattern should succeed' \
163 'git tag -l xxx'
165 test_expect_success \
166 'listing tags using a non-matching pattern should output nothing' \
167 'test $(git tag -l xxx | wc -l) -eq 0'
169 # special cases for creating tags:
171 test_expect_success \
172 'trying to create a tag with the name of one existing should fail' \
173 'test_must_fail git tag mytag'
175 test_expect_success \
176 'trying to create a tag with a non-valid name should fail' '
177 test $(git tag -l | wc -l) -eq 1 &&
178 test_must_fail git tag "" &&
179 test_must_fail git tag .othertag &&
180 test_must_fail git tag "other tag" &&
181 test_must_fail git tag "othertag^" &&
182 test_must_fail git tag "other~tag" &&
183 test $(git tag -l | wc -l) -eq 1
186 test_expect_success 'creating a tag using HEAD directly should succeed' '
187 git tag myhead HEAD &&
188 tag_exists myhead
191 test_expect_success '--force can create a tag with the name of one existing' '
192 tag_exists mytag &&
193 git tag --force mytag &&
194 tag_exists mytag'
196 test_expect_success '--force is moot with a non-existing tag name' '
197 test_when_finished git tag -d newtag forcetag &&
198 git tag newtag >expect &&
199 git tag --force forcetag >actual &&
200 test_cmp expect actual
203 # deleting tags:
205 test_expect_success 'trying to delete an unknown tag should fail' '
206 ! tag_exists unknown-tag &&
207 test_must_fail git tag -d unknown-tag
210 cat >expect <<EOF
211 myhead
212 mytag
214 test_expect_success \
215 'trying to delete tags without params should succeed and do nothing' '
216 git tag -l > actual && test_cmp expect actual &&
217 git tag -d &&
218 git tag -l > actual && test_cmp expect actual
221 test_expect_success \
222 'deleting two existing tags in one command should succeed' '
223 tag_exists mytag &&
224 tag_exists myhead &&
225 git tag -d mytag myhead &&
226 ! tag_exists mytag &&
227 ! tag_exists myhead
230 test_expect_success \
231 'creating a tag with the name of another deleted one should succeed' '
232 ! tag_exists mytag &&
233 git tag mytag &&
234 tag_exists mytag
237 test_expect_success \
238 'trying to delete two tags, existing and not, should fail in the 2nd' '
239 tag_exists mytag &&
240 ! tag_exists nonexistingtag &&
241 test_must_fail git tag -d mytag nonexistingtag &&
242 ! tag_exists mytag &&
243 ! tag_exists nonexistingtag
246 test_expect_success 'trying to delete an already deleted tag should fail' \
247 'test_must_fail git tag -d mytag'
249 # listing various tags with pattern matching:
251 cat >expect <<EOF
255 t210
256 t211
257 v0.2.1
258 v1.0
259 v1.0.1
260 v1.1.3
262 test_expect_success 'listing all tags should print them ordered' '
263 git tag v1.0.1 &&
264 git tag t211 &&
265 git tag aa1 &&
266 git tag v0.2.1 &&
267 git tag v1.1.3 &&
268 git tag cba &&
269 git tag a1 &&
270 git tag v1.0 &&
271 git tag t210 &&
272 git tag -l > actual &&
273 test_cmp expect actual &&
274 git tag > actual &&
275 test_cmp expect actual
278 cat >expect <<EOF
283 test_expect_success \
284 'listing tags with substring as pattern must print those matching' '
285 rm *a* &&
286 git tag -l "*a*" > current &&
287 test_cmp expect current
290 cat >expect <<EOF
291 v0.2.1
292 v1.0.1
294 test_expect_success \
295 'listing tags with a suffix as pattern must print those matching' '
296 git tag -l "*.1" > actual &&
297 test_cmp expect actual
300 cat >expect <<EOF
301 t210
302 t211
304 test_expect_success \
305 'listing tags with a prefix as pattern must print those matching' '
306 git tag -l "t21*" > actual &&
307 test_cmp expect actual
310 cat >expect <<EOF
313 test_expect_success \
314 'listing tags using a name as pattern must print that one matching' '
315 git tag -l a1 > actual &&
316 test_cmp expect actual
319 cat >expect <<EOF
320 v1.0
322 test_expect_success \
323 'listing tags using a name as pattern must print that one matching' '
324 git tag -l v1.0 > actual &&
325 test_cmp expect actual
328 cat >expect <<EOF
329 v1.0.1
330 v1.1.3
332 test_expect_success \
333 'listing tags with ? in the pattern should print those matching' '
334 git tag -l "v1.?.?" > actual &&
335 test_cmp expect actual
338 test_expect_success \
339 'listing tags using v.* should print nothing because none have v.' '
340 git tag -l "v.*" > actual &&
341 test_must_be_empty actual
344 cat >expect <<EOF
345 v0.2.1
346 v1.0
347 v1.0.1
348 v1.1.3
350 test_expect_success \
351 'listing tags using v* should print only those having v' '
352 git tag -l "v*" > actual &&
353 test_cmp expect actual
356 test_expect_success 'tag -l can accept multiple patterns' '
357 git tag -l "v1*" "v0*" >actual &&
358 test_cmp expect actual
361 # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
362 # could leave you with the impression that "-l <pattern> -l <pattern>"
363 # was how we wanted to accept multiple patterns.
365 # This test should not imply that this is a sane thing to support. but
366 # since the documentation was worded like it was let's at least find
367 # out if we're going to break this long-documented form of taking
368 # multiple patterns.
369 test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
370 git tag -l "v1*" -l "v0*" >actual &&
371 test_cmp expect actual
374 test_expect_success 'listing tags in column' '
375 COLUMNS=41 git tag -l --column=row >actual &&
376 cat >expected <<\EOF &&
377 a1 aa1 cba t210 t211
378 v0.2.1 v1.0 v1.0.1 v1.1.3
380 test_cmp expected actual
383 test_expect_success 'listing tags in column with column.*' '
384 test_config column.tag row &&
385 test_config column.ui dense &&
386 COLUMNS=40 git tag -l >actual &&
387 cat >expected <<\EOF &&
388 a1 aa1 cba t210 t211
389 v0.2.1 v1.0 v1.0.1 v1.1.3
391 test_cmp expected actual
394 test_expect_success 'listing tag with -n --column should fail' '
395 test_must_fail git tag --column -n
398 test_expect_success 'listing tags -n in column with column.ui ignored' '
399 test_config column.ui "row dense" &&
400 COLUMNS=40 git tag -l -n >actual &&
401 cat >expected <<\EOF &&
402 a1 Foo
403 aa1 Foo
404 cba Foo
405 t210 Foo
406 t211 Foo
407 v0.2.1 Foo
408 v1.0 Foo
409 v1.0.1 Foo
410 v1.1.3 Foo
412 test_cmp expected actual
415 # creating and verifying lightweight tags:
417 test_expect_success \
418 'a non-annotated tag created without parameters should point to HEAD' '
419 git tag non-annotated-tag &&
420 test $(git cat-file -t non-annotated-tag) = commit &&
421 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
424 test_expect_success 'trying to verify an unknown tag should fail' \
425 'test_must_fail git tag -v unknown-tag'
427 test_expect_success \
428 'trying to verify a non-annotated and non-signed tag should fail' \
429 'test_must_fail git tag -v non-annotated-tag'
431 test_expect_success \
432 'trying to verify many non-annotated or unknown tags, should fail' \
433 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
435 # creating annotated tags:
437 get_tag_msg () {
438 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
441 # run test_tick before committing always gives the time in that timezone
442 get_tag_header () {
443 cat <<EOF
444 object $2
445 type $3
446 tag $1
447 tagger C O Mitter <committer@example.com> $4 -0700
452 commit=$(git rev-parse HEAD)
453 time=$test_tick
455 get_tag_header annotated-tag $commit commit $time >expect
456 echo "A message" >>expect
457 test_expect_success \
458 'creating an annotated tag with -m message should succeed' '
459 git tag -m "A message" annotated-tag &&
460 get_tag_msg annotated-tag >actual &&
461 test_cmp expect actual
464 get_tag_header annotated-tag-edit $commit commit $time >expect
465 echo "An edited message" >>expect
466 test_expect_success 'set up editor' '
467 write_script fakeeditor <<-\EOF
468 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
469 mv "$1-" "$1"
472 test_expect_success \
473 'creating an annotated tag with -m message --edit should succeed' '
474 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
475 get_tag_msg annotated-tag-edit >actual &&
476 test_cmp expect actual
479 cat >msgfile <<EOF
480 Another message
481 in a file.
483 get_tag_header file-annotated-tag $commit commit $time >expect
484 cat msgfile >>expect
485 test_expect_success \
486 'creating an annotated tag with -F messagefile should succeed' '
487 git tag -F msgfile file-annotated-tag &&
488 get_tag_msg file-annotated-tag >actual &&
489 test_cmp expect actual
492 get_tag_header file-annotated-tag-edit $commit commit $time >expect
493 sed -e "s/Another message/Another edited message/g" msgfile >>expect
494 test_expect_success 'set up editor' '
495 write_script fakeeditor <<-\EOF
496 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
497 mv "$1-" "$1"
500 test_expect_success \
501 'creating an annotated tag with -F messagefile --edit should succeed' '
502 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
503 get_tag_msg file-annotated-tag-edit >actual &&
504 test_cmp expect actual
507 cat >inputmsg <<EOF
508 A message from the
509 standard input
511 get_tag_header stdin-annotated-tag $commit commit $time >expect
512 cat inputmsg >>expect
513 test_expect_success 'creating an annotated tag with -F - should succeed' '
514 git tag -F - stdin-annotated-tag <inputmsg &&
515 get_tag_msg stdin-annotated-tag >actual &&
516 test_cmp expect actual
519 test_expect_success \
520 'trying to create a tag with a non-existing -F file should fail' '
521 ! test -f nonexistingfile &&
522 ! tag_exists notag &&
523 test_must_fail git tag -F nonexistingfile notag &&
524 ! tag_exists notag
527 test_expect_success \
528 'trying to create tags giving both -m or -F options should fail' '
529 echo "message file 1" >msgfile1 &&
530 ! tag_exists msgtag &&
531 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
532 ! tag_exists msgtag &&
533 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
534 ! tag_exists msgtag &&
535 test_must_fail git tag -m "message 1" -F msgfile1 \
536 -m "message 2" msgtag &&
537 ! tag_exists msgtag
540 # blank and empty messages:
542 get_tag_header empty-annotated-tag $commit commit $time >expect
543 test_expect_success \
544 'creating a tag with an empty -m message should succeed' '
545 git tag -m "" empty-annotated-tag &&
546 get_tag_msg empty-annotated-tag >actual &&
547 test_cmp expect actual
550 >emptyfile
551 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
552 test_expect_success \
553 'creating a tag with an empty -F messagefile should succeed' '
554 git tag -F emptyfile emptyfile-annotated-tag &&
555 get_tag_msg emptyfile-annotated-tag >actual &&
556 test_cmp expect actual
559 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
560 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
561 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
562 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
563 get_tag_header blanks-annotated-tag $commit commit $time >expect
564 cat >>expect <<EOF
565 Leading blank lines
567 Repeated blank lines
569 Trailing spaces
571 Trailing blank lines
573 test_expect_success \
574 'extra blanks in the message for an annotated tag should be removed' '
575 git tag -F blanksfile blanks-annotated-tag &&
576 get_tag_msg blanks-annotated-tag >actual &&
577 test_cmp expect actual
580 get_tag_header blank-annotated-tag $commit commit $time >expect
581 test_expect_success \
582 'creating a tag with blank -m message with spaces should succeed' '
583 git tag -m " " blank-annotated-tag &&
584 get_tag_msg blank-annotated-tag >actual &&
585 test_cmp expect actual
588 echo ' ' >blankfile
589 echo '' >>blankfile
590 echo ' ' >>blankfile
591 get_tag_header blankfile-annotated-tag $commit commit $time >expect
592 test_expect_success \
593 'creating a tag with blank -F messagefile with spaces should succeed' '
594 git tag -F blankfile blankfile-annotated-tag &&
595 get_tag_msg blankfile-annotated-tag >actual &&
596 test_cmp expect actual
599 printf ' ' >blanknonlfile
600 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
601 test_expect_success \
602 'creating a tag with -F file of spaces and no newline should succeed' '
603 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
604 get_tag_msg blanknonlfile-annotated-tag >actual &&
605 test_cmp expect actual
608 # messages with commented lines:
610 cat >commentsfile <<EOF
611 # A comment
613 ############
614 The message.
615 ############
616 One line.
619 # commented lines
620 # commented lines
622 Another line.
623 # comments
625 Last line.
627 get_tag_header comments-annotated-tag $commit commit $time >expect
628 cat >>expect <<EOF
629 The message.
630 One line.
632 Another line.
634 Last line.
636 test_expect_success \
637 'creating a tag using a -F messagefile with #comments should succeed' '
638 git tag -F commentsfile comments-annotated-tag &&
639 get_tag_msg comments-annotated-tag >actual &&
640 test_cmp expect actual
643 get_tag_header comment-annotated-tag $commit commit $time >expect
644 test_expect_success \
645 'creating a tag with a #comment in the -m message should succeed' '
646 git tag -m "#comment" comment-annotated-tag &&
647 get_tag_msg comment-annotated-tag >actual &&
648 test_cmp expect actual
651 echo '#comment' >commentfile
652 echo '' >>commentfile
653 echo '####' >>commentfile
654 get_tag_header commentfile-annotated-tag $commit commit $time >expect
655 test_expect_success \
656 'creating a tag with #comments in the -F messagefile should succeed' '
657 git tag -F commentfile commentfile-annotated-tag &&
658 get_tag_msg commentfile-annotated-tag >actual &&
659 test_cmp expect actual
662 printf '#comment' >commentnonlfile
663 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
664 test_expect_success \
665 'creating a tag with a file of #comment and no newline should succeed' '
666 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
667 get_tag_msg commentnonlfile-annotated-tag >actual &&
668 test_cmp expect actual
671 # trailers
673 test_expect_success 'create tag with -m and --trailer' '
674 get_tag_header tag-with-inline-message-and-trailers $commit commit $time >expect &&
675 cat >>expect <<-\EOF &&
676 create tag with trailers
678 my-trailer: here
679 alt-trailer: there
681 git tag -m "create tag with trailers" \
682 --trailer my-trailer=here \
683 --trailer alt-trailer=there \
684 tag-with-inline-message-and-trailers &&
685 get_tag_msg tag-with-inline-message-and-trailers >actual &&
686 test_cmp expect actual
689 test_expect_success 'list tag extracting trailers' '
690 cat >expect <<-\EOF &&
691 my-trailer: here
692 alt-trailer: there
695 git tag --list --format="%(trailers)" tag-with-inline-message-and-trailers >actual &&
696 test_cmp expect actual
699 test_expect_success 'create tag with -F and --trailer' '
700 echo "create tag from message file using --trailer" >messagefilewithnotrailers &&
701 get_tag_header tag-with-file-message-and-trailers $commit commit $time >expect &&
702 cat >>expect <<-\EOF &&
703 create tag from message file using --trailer
705 my-trailer: here
706 alt-trailer: there
708 git tag -F messagefilewithnotrailers \
709 --trailer my-trailer=here \
710 --trailer alt-trailer=there \
711 tag-with-file-message-and-trailers &&
712 get_tag_msg tag-with-file-message-and-trailers >actual &&
713 test_cmp expect actual
716 test_expect_success 'create tag with -m and --trailer and --edit' '
717 write_script fakeeditor <<-\EOF &&
718 sed -e "1s/^/EDITED: /g" <"$1" >"$1-"
719 mv "$1-" "$1"
721 get_tag_header tag-with-edited-inline-message-and-trailers $commit commit $time >expect &&
722 cat >>expect <<-\EOF &&
723 EDITED: create tag with trailers
725 my-trailer: here
726 alt-trailer: there
728 GIT_EDITOR=./fakeeditor git tag --edit \
729 -m "create tag with trailers" \
730 --trailer my-trailer=here \
731 --trailer alt-trailer=there \
732 tag-with-edited-inline-message-and-trailers &&
733 get_tag_msg tag-with-edited-inline-message-and-trailers >actual &&
734 test_cmp expect actual
737 test_expect_success 'create tag with -F and --trailer and --edit' '
738 echo "create tag from message file using --trailer" >messagefilewithnotrailers &&
739 get_tag_header tag-with-edited-file-message-and-trailers $commit commit $time >expect &&
740 cat >>expect <<-\EOF &&
741 EDITED: create tag from message file using --trailer
743 my-trailer: here
744 alt-trailer: there
746 GIT_EDITOR=./fakeeditor git tag --edit \
747 -F messagefilewithnotrailers \
748 --trailer my-trailer=here \
749 --trailer alt-trailer=there \
750 tag-with-edited-file-message-and-trailers &&
751 get_tag_msg tag-with-edited-file-message-and-trailers >actual &&
752 test_cmp expect actual
755 test_expect_success 'create annotated tag and force editor when only --trailer is given' '
756 write_script fakeeditor <<-\EOF &&
757 echo "add a line" >"$1-"
758 cat <"$1" >>"$1-"
759 mv "$1-" "$1"
761 get_tag_header tag-with-trailers-and-no-message $commit commit $time >expect &&
762 cat >>expect <<-\EOF &&
763 add a line
765 my-trailer: here
766 alt-trailer: there
768 GIT_EDITOR=./fakeeditor git tag \
769 --trailer my-trailer=here \
770 --trailer alt-trailer=there \
771 tag-with-trailers-and-no-message &&
772 get_tag_msg tag-with-trailers-and-no-message >actual &&
773 test_cmp expect actual
776 test_expect_success 'bad editor causes panic when only --trailer is given' '
777 test_must_fail env GIT_EDITOR=false git tag --trailer my-trailer=here tag-will-not-exist
780 # listing messages for annotated non-signed tags:
782 test_expect_success \
783 'listing the one-line message of a non-signed tag should succeed' '
784 git tag -m "A msg" tag-one-line &&
786 echo "tag-one-line" >expect &&
787 git tag -l | grep "^tag-one-line" >actual &&
788 test_cmp expect actual &&
789 git tag -n0 -l | grep "^tag-one-line" >actual &&
790 test_cmp expect actual &&
791 git tag -n0 -l tag-one-line >actual &&
792 test_cmp expect actual &&
794 git tag -n0 | grep "^tag-one-line" >actual &&
795 test_cmp expect actual &&
796 git tag -n0 tag-one-line >actual &&
797 test_cmp expect actual &&
799 echo "tag-one-line A msg" >expect &&
800 git tag -n1 -l | grep "^tag-one-line" >actual &&
801 test_cmp expect actual &&
802 git tag -n -l | grep "^tag-one-line" >actual &&
803 test_cmp expect actual &&
804 git tag -n1 -l tag-one-line >actual &&
805 test_cmp expect actual &&
806 git tag -n2 -l tag-one-line >actual &&
807 test_cmp expect actual &&
808 git tag -n999 -l tag-one-line >actual &&
809 test_cmp expect actual
812 test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
813 git tag -n 100 >actual &&
814 test_must_be_empty actual &&
816 git tag -m "A msg" 100 &&
817 echo "100 A msg" >expect &&
818 git tag -n 100 >actual &&
819 test_cmp expect actual
822 test_expect_success \
823 'listing the zero-lines message of a non-signed tag should succeed' '
824 git tag -m "" tag-zero-lines &&
826 echo "tag-zero-lines" >expect &&
827 git tag -l | grep "^tag-zero-lines" >actual &&
828 test_cmp expect actual &&
829 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
830 test_cmp expect actual &&
831 git tag -n0 -l tag-zero-lines >actual &&
832 test_cmp expect actual &&
834 echo "tag-zero-lines " >expect &&
835 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
836 test_cmp expect actual &&
837 git tag -n -l | grep "^tag-zero-lines" >actual &&
838 test_cmp expect actual &&
839 git tag -n1 -l tag-zero-lines >actual &&
840 test_cmp expect actual &&
841 git tag -n2 -l tag-zero-lines >actual &&
842 test_cmp expect actual &&
843 git tag -n999 -l tag-zero-lines >actual &&
844 test_cmp expect actual
847 echo 'tag line one' >annotagmsg
848 echo 'tag line two' >>annotagmsg
849 echo 'tag line three' >>annotagmsg
850 test_expect_success \
851 'listing many message lines of a non-signed tag should succeed' '
852 git tag -F annotagmsg tag-lines &&
854 echo "tag-lines" >expect &&
855 git tag -l | grep "^tag-lines" >actual &&
856 test_cmp expect actual &&
857 git tag -n0 -l | grep "^tag-lines" >actual &&
858 test_cmp expect actual &&
859 git tag -n0 -l tag-lines >actual &&
860 test_cmp expect actual &&
862 echo "tag-lines tag line one" >expect &&
863 git tag -n1 -l | grep "^tag-lines" >actual &&
864 test_cmp expect actual &&
865 git tag -n -l | grep "^tag-lines" >actual &&
866 test_cmp expect actual &&
867 git tag -n1 -l tag-lines >actual &&
868 test_cmp expect actual &&
870 echo " tag line two" >>expect &&
871 git tag -n2 -l | grep "^ *tag.line" >actual &&
872 test_cmp expect actual &&
873 git tag -n2 -l tag-lines >actual &&
874 test_cmp expect actual &&
876 echo " tag line three" >>expect &&
877 git tag -n3 -l | grep "^ *tag.line" >actual &&
878 test_cmp expect actual &&
879 git tag -n3 -l tag-lines >actual &&
880 test_cmp expect actual &&
881 git tag -n4 -l | grep "^ *tag.line" >actual &&
882 test_cmp expect actual &&
883 git tag -n4 -l tag-lines >actual &&
884 test_cmp expect actual &&
885 git tag -n99 -l | grep "^ *tag.line" >actual &&
886 test_cmp expect actual &&
887 git tag -n99 -l tag-lines >actual &&
888 test_cmp expect actual
891 test_expect_success 'annotations for blobs are empty' '
892 blob=$(git hash-object -w --stdin <<-\EOF
893 Blob paragraph 1.
895 Blob paragraph 2.
897 ) &&
898 git tag tag-blob $blob &&
899 echo "tag-blob " >expect &&
900 git tag -n1 -l tag-blob >actual &&
901 test_cmp expect actual
904 # Run this before doing any signing, so the test has the same results
905 # regardless of the GPG prereq.
906 test_expect_success 'git tag --format with ahead-behind' '
907 test_when_finished git reset --hard tag-one-line &&
908 git commit --allow-empty -m "left" &&
909 git tag -a -m left tag-left &&
910 git reset --hard HEAD~1 &&
911 git commit --allow-empty -m "right" &&
912 git tag -a -m left tag-right &&
914 # Use " !" at the end to demonstrate whitespace
915 # around empty ahead-behind token for tag-blob.
916 cat >expect <<-EOF &&
917 refs/tags/tag-blob !
918 refs/tags/tag-left 1 1 !
919 refs/tags/tag-lines 0 1 !
920 refs/tags/tag-one-line 0 1 !
921 refs/tags/tag-right 0 0 !
922 refs/tags/tag-with-edited-file-message-and-trailers 0 1 !
923 refs/tags/tag-with-edited-inline-message-and-trailers 0 1 !
924 refs/tags/tag-with-file-message-and-trailers 0 1 !
925 refs/tags/tag-with-inline-message-and-trailers 0 1 !
926 refs/tags/tag-with-trailers-and-no-message 0 1 !
927 refs/tags/tag-zero-lines 0 1 !
929 git tag -l --format="%(refname) %(ahead-behind:HEAD) !" >actual 2>err &&
930 grep "refs/tags/tag" actual >actual.focus &&
931 test_cmp expect actual.focus &&
933 # Error reported for tags that point to non-commits.
934 grep "error: object [0-9a-f]* is a blob, not a commit" err
937 # trying to verify annotated non-signed tags:
939 test_expect_success GPG \
940 'trying to verify an annotated non-signed tag should fail' '
941 tag_exists annotated-tag &&
942 test_must_fail git tag -v annotated-tag
945 test_expect_success GPG \
946 'trying to verify a file-annotated non-signed tag should fail' '
947 tag_exists file-annotated-tag &&
948 test_must_fail git tag -v file-annotated-tag
951 test_expect_success GPG \
952 'trying to verify two annotated non-signed tags should fail' '
953 tag_exists annotated-tag file-annotated-tag &&
954 test_must_fail git tag -v annotated-tag file-annotated-tag
957 # creating and verifying signed tags:
959 get_tag_header signed-tag $commit commit $time >expect
960 echo 'A signed tag message' >>expect
961 echo '-----BEGIN PGP SIGNATURE-----' >>expect
962 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
963 git tag -s -m "A signed tag message" signed-tag &&
964 get_tag_msg signed-tag >actual &&
965 test_cmp expect actual
968 get_tag_header u-signed-tag $commit commit $time >expect
969 echo 'Another message' >>expect
970 echo '-----BEGIN PGP SIGNATURE-----' >>expect
971 test_expect_success GPG 'sign with a given key id' '
973 git tag -u committer@example.com -m "Another message" u-signed-tag &&
974 get_tag_msg u-signed-tag >actual &&
975 test_cmp expect actual
979 test_expect_success GPG 'sign with an unknown id (1)' '
981 test_must_fail git tag -u author@example.com \
982 -m "Another message" o-signed-tag
986 test_expect_success GPG 'sign with an unknown id (2)' '
988 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
992 cat >fakeeditor <<'EOF'
993 #!/bin/sh
994 test -n "$1" && exec >"$1"
995 echo A signed tag message
996 echo from a fake editor.
998 chmod +x fakeeditor
1000 get_tag_header implied-sign $commit commit $time >expect
1001 ./fakeeditor >>expect
1002 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1003 test_expect_success GPG '-u implies signed tag' '
1004 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
1005 get_tag_msg implied-sign >actual &&
1006 test_cmp expect actual
1009 cat >sigmsgfile <<EOF
1010 Another signed tag
1011 message in a file.
1013 get_tag_header file-signed-tag $commit commit $time >expect
1014 cat sigmsgfile >>expect
1015 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1016 test_expect_success GPG \
1017 'creating a signed tag with -F messagefile should succeed' '
1018 git tag -s -F sigmsgfile file-signed-tag &&
1019 get_tag_msg file-signed-tag >actual &&
1020 test_cmp expect actual
1023 cat >siginputmsg <<EOF
1024 A signed tag message from
1025 the standard input
1027 get_tag_header stdin-signed-tag $commit commit $time >expect
1028 cat siginputmsg >>expect
1029 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1030 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
1031 git tag -s -F - stdin-signed-tag <siginputmsg &&
1032 get_tag_msg stdin-signed-tag >actual &&
1033 test_cmp expect actual
1036 get_tag_header implied-annotate $commit commit $time >expect
1037 ./fakeeditor >>expect
1038 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1039 test_expect_success GPG '-s implies annotated tag' '
1040 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
1041 get_tag_msg implied-annotate >actual &&
1042 test_cmp expect actual
1045 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
1046 echo "A message" >>expect
1047 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1048 test_expect_success GPG \
1049 'git tag -s implied if configured with tag.forcesignannotated' \
1050 'test_config tag.forcesignannotated true &&
1051 git tag -m "A message" forcesignannotated-implied-sign &&
1052 get_tag_msg forcesignannotated-implied-sign >actual &&
1053 test_cmp expect actual
1056 test_expect_success GPG \
1057 'lightweight with no message when configured with tag.forcesignannotated' \
1058 'test_config tag.forcesignannotated true &&
1059 git tag forcesignannotated-lightweight &&
1060 tag_exists forcesignannotated-lightweight &&
1061 test_must_fail git tag -v forcesignannotated-no-message
1064 get_tag_header forcesignannotated-annotate $commit commit $time >expect
1065 echo "A message" >>expect
1066 test_expect_success GPG \
1067 'git tag -a disable configured tag.forcesignannotated' \
1068 'test_config tag.forcesignannotated true &&
1069 git tag -a -m "A message" forcesignannotated-annotate &&
1070 get_tag_msg forcesignannotated-annotate >actual &&
1071 test_cmp expect actual &&
1072 test_must_fail git tag -v forcesignannotated-annotate
1075 get_tag_header forcesignannotated-disabled $commit commit $time >expect
1076 echo "A message" >>expect
1077 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1078 test_expect_success GPG \
1079 'git tag --sign enable GPG sign' \
1080 'test_config tag.forcesignannotated false &&
1081 git tag --sign -m "A message" forcesignannotated-disabled &&
1082 get_tag_msg forcesignannotated-disabled >actual &&
1083 test_cmp expect actual
1086 get_tag_header gpgsign-enabled $commit commit $time >expect
1087 echo "A message" >>expect
1088 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1089 test_expect_success GPG \
1090 'git tag configured tag.gpgsign enables GPG sign' \
1091 'test_config tag.gpgsign true &&
1092 git tag -m "A message" gpgsign-enabled &&
1093 get_tag_msg gpgsign-enabled>actual &&
1094 test_cmp expect actual
1097 get_tag_header no-sign $commit commit $time >expect
1098 echo "A message" >>expect
1099 test_expect_success GPG \
1100 'git tag --no-sign configured tag.gpgsign skip GPG sign' \
1101 'test_config tag.gpgsign true &&
1102 git tag -a --no-sign -m "A message" no-sign &&
1103 get_tag_msg no-sign>actual &&
1104 test_cmp expect actual
1107 test_expect_success GPG \
1108 'trying to create a signed tag with non-existing -F file should fail' '
1109 ! test -f nonexistingfile &&
1110 ! tag_exists nosigtag &&
1111 test_must_fail git tag -s -F nonexistingfile nosigtag &&
1112 ! tag_exists nosigtag
1115 test_expect_success GPG 'verifying a signed tag should succeed' \
1116 'git tag -v signed-tag'
1118 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
1119 'git tag -v signed-tag file-signed-tag'
1121 test_expect_success GPG \
1122 'verifying many signed and non-signed tags should fail' '
1123 test_must_fail git tag -v signed-tag annotated-tag &&
1124 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
1125 test_must_fail git tag -v annotated-tag \
1126 file-signed-tag file-annotated-tag &&
1127 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
1130 test_expect_success GPG 'verifying a forged tag should fail' '
1131 forged=$(git cat-file tag signed-tag |
1132 sed -e "s/signed-tag/forged-tag/" |
1133 git mktag) &&
1134 git tag forged-tag $forged &&
1135 test_must_fail git tag -v forged-tag
1138 test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
1139 cat >expect <<-\EOF &&
1140 tagname : signed-tag
1142 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
1143 test_cmp expect actual
1146 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
1147 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
1148 test_must_be_empty actual
1151 # blank and empty messages for signed tags:
1153 get_tag_header empty-signed-tag $commit commit $time >expect
1154 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1155 test_expect_success GPG \
1156 'creating a signed tag with an empty -m message should succeed' '
1157 git tag -s -m "" empty-signed-tag &&
1158 get_tag_msg empty-signed-tag >actual &&
1159 test_cmp expect actual &&
1160 git tag -v empty-signed-tag
1163 >sigemptyfile
1164 get_tag_header emptyfile-signed-tag $commit commit $time >expect
1165 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1166 test_expect_success GPG \
1167 'creating a signed tag with an empty -F messagefile should succeed' '
1168 git tag -s -F sigemptyfile emptyfile-signed-tag &&
1169 get_tag_msg emptyfile-signed-tag >actual &&
1170 test_cmp expect actual &&
1171 git tag -v emptyfile-signed-tag
1174 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1175 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1176 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1177 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1178 get_tag_header blanks-signed-tag $commit commit $time >expect
1179 cat >>expect <<EOF
1180 Leading blank lines
1182 Repeated blank lines
1184 Trailing spaces
1186 Trailing blank lines
1188 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1189 test_expect_success GPG \
1190 'extra blanks in the message for a signed tag should be removed' '
1191 git tag -s -F sigblanksfile blanks-signed-tag &&
1192 get_tag_msg blanks-signed-tag >actual &&
1193 test_cmp expect actual &&
1194 git tag -v blanks-signed-tag
1197 get_tag_header blank-signed-tag $commit commit $time >expect
1198 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1199 test_expect_success GPG \
1200 'creating a signed tag with a blank -m message should succeed' '
1201 git tag -s -m " " blank-signed-tag &&
1202 get_tag_msg blank-signed-tag >actual &&
1203 test_cmp expect actual &&
1204 git tag -v blank-signed-tag
1207 echo ' ' >sigblankfile
1208 echo '' >>sigblankfile
1209 echo ' ' >>sigblankfile
1210 get_tag_header blankfile-signed-tag $commit commit $time >expect
1211 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1212 test_expect_success GPG \
1213 'creating a signed tag with blank -F file with spaces should succeed' '
1214 git tag -s -F sigblankfile blankfile-signed-tag &&
1215 get_tag_msg blankfile-signed-tag >actual &&
1216 test_cmp expect actual &&
1217 git tag -v blankfile-signed-tag
1220 printf ' ' >sigblanknonlfile
1221 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1222 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1223 test_expect_success GPG \
1224 'creating a signed tag with spaces and no newline should succeed' '
1225 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1226 get_tag_msg blanknonlfile-signed-tag >actual &&
1227 test_cmp expect actual &&
1228 git tag -v blanknonlfile-signed-tag
1231 test_expect_success GPG 'signed tag with embedded PGP message' '
1232 cat >msg <<-\EOF &&
1233 -----BEGIN PGP MESSAGE-----
1235 this is not a real PGP message
1236 -----END PGP MESSAGE-----
1238 git tag -s -F msg confusing-pgp-message &&
1239 git tag -v confusing-pgp-message
1242 # messages with commented lines for signed tags:
1244 cat >sigcommentsfile <<EOF
1245 # A comment
1247 ############
1248 The message.
1249 ############
1250 One line.
1253 # commented lines
1254 # commented lines
1256 Another line.
1257 # comments
1259 Last line.
1261 get_tag_header comments-signed-tag $commit commit $time >expect
1262 cat >>expect <<EOF
1263 The message.
1264 One line.
1266 Another line.
1268 Last line.
1270 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1271 test_expect_success GPG \
1272 'creating a signed tag with a -F file with #comments should succeed' '
1273 git tag -s -F sigcommentsfile comments-signed-tag &&
1274 get_tag_msg comments-signed-tag >actual &&
1275 test_cmp expect actual &&
1276 git tag -v comments-signed-tag
1279 get_tag_header comment-signed-tag $commit commit $time >expect
1280 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1281 test_expect_success GPG \
1282 'creating a signed tag with #commented -m message should succeed' '
1283 git tag -s -m "#comment" comment-signed-tag &&
1284 get_tag_msg comment-signed-tag >actual &&
1285 test_cmp expect actual &&
1286 git tag -v comment-signed-tag
1289 echo '#comment' >sigcommentfile
1290 echo '' >>sigcommentfile
1291 echo '####' >>sigcommentfile
1292 get_tag_header commentfile-signed-tag $commit commit $time >expect
1293 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1294 test_expect_success GPG \
1295 'creating a signed tag with #commented -F messagefile should succeed' '
1296 git tag -s -F sigcommentfile commentfile-signed-tag &&
1297 get_tag_msg commentfile-signed-tag >actual &&
1298 test_cmp expect actual &&
1299 git tag -v commentfile-signed-tag
1302 printf '#comment' >sigcommentnonlfile
1303 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1304 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1305 test_expect_success GPG \
1306 'creating a signed tag with a #comment and no newline should succeed' '
1307 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1308 get_tag_msg commentnonlfile-signed-tag >actual &&
1309 test_cmp expect actual &&
1310 git tag -v commentnonlfile-signed-tag
1313 # listing messages for signed tags:
1315 test_expect_success GPG \
1316 'listing the one-line message of a signed tag should succeed' '
1317 git tag -s -m "A message line signed" stag-one-line &&
1319 echo "stag-one-line" >expect &&
1320 git tag -l | grep "^stag-one-line" >actual &&
1321 test_cmp expect actual &&
1322 git tag -n0 -l | grep "^stag-one-line" >actual &&
1323 test_cmp expect actual &&
1324 git tag -n0 -l stag-one-line >actual &&
1325 test_cmp expect actual &&
1327 echo "stag-one-line A message line signed" >expect &&
1328 git tag -n1 -l | grep "^stag-one-line" >actual &&
1329 test_cmp expect actual &&
1330 git tag -n -l | grep "^stag-one-line" >actual &&
1331 test_cmp expect actual &&
1332 git tag -n1 -l stag-one-line >actual &&
1333 test_cmp expect actual &&
1334 git tag -n2 -l stag-one-line >actual &&
1335 test_cmp expect actual &&
1336 git tag -n999 -l stag-one-line >actual &&
1337 test_cmp expect actual
1340 test_expect_success GPG \
1341 'listing the zero-lines message of a signed tag should succeed' '
1342 git tag -s -m "" stag-zero-lines &&
1344 echo "stag-zero-lines" >expect &&
1345 git tag -l | grep "^stag-zero-lines" >actual &&
1346 test_cmp expect actual &&
1347 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1348 test_cmp expect actual &&
1349 git tag -n0 -l stag-zero-lines >actual &&
1350 test_cmp expect actual &&
1352 echo "stag-zero-lines " >expect &&
1353 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1354 test_cmp expect actual &&
1355 git tag -n -l | grep "^stag-zero-lines" >actual &&
1356 test_cmp expect actual &&
1357 git tag -n1 -l stag-zero-lines >actual &&
1358 test_cmp expect actual &&
1359 git tag -n2 -l stag-zero-lines >actual &&
1360 test_cmp expect actual &&
1361 git tag -n999 -l stag-zero-lines >actual &&
1362 test_cmp expect actual
1365 echo 'stag line one' >sigtagmsg
1366 echo 'stag line two' >>sigtagmsg
1367 echo 'stag line three' >>sigtagmsg
1368 test_expect_success GPG \
1369 'listing many message lines of a signed tag should succeed' '
1370 git tag -s -F sigtagmsg stag-lines &&
1372 echo "stag-lines" >expect &&
1373 git tag -l | grep "^stag-lines" >actual &&
1374 test_cmp expect actual &&
1375 git tag -n0 -l | grep "^stag-lines" >actual &&
1376 test_cmp expect actual &&
1377 git tag -n0 -l stag-lines >actual &&
1378 test_cmp expect actual &&
1380 echo "stag-lines stag line one" >expect &&
1381 git tag -n1 -l | grep "^stag-lines" >actual &&
1382 test_cmp expect actual &&
1383 git tag -n -l | grep "^stag-lines" >actual &&
1384 test_cmp expect actual &&
1385 git tag -n1 -l stag-lines >actual &&
1386 test_cmp expect actual &&
1388 echo " stag line two" >>expect &&
1389 git tag -n2 -l | grep "^ *stag.line" >actual &&
1390 test_cmp expect actual &&
1391 git tag -n2 -l stag-lines >actual &&
1392 test_cmp expect actual &&
1394 echo " stag line three" >>expect &&
1395 git tag -n3 -l | grep "^ *stag.line" >actual &&
1396 test_cmp expect actual &&
1397 git tag -n3 -l stag-lines >actual &&
1398 test_cmp expect actual &&
1399 git tag -n4 -l | grep "^ *stag.line" >actual &&
1400 test_cmp expect actual &&
1401 git tag -n4 -l stag-lines >actual &&
1402 test_cmp expect actual &&
1403 git tag -n99 -l | grep "^ *stag.line" >actual &&
1404 test_cmp expect actual &&
1405 git tag -n99 -l stag-lines >actual &&
1406 test_cmp expect actual
1409 # tags pointing to objects different from commits:
1411 tree=$(git rev-parse HEAD^{tree})
1412 blob=$(git rev-parse HEAD:foo)
1413 tag=$(git rev-parse signed-tag 2>/dev/null)
1415 get_tag_header tree-signed-tag $tree tree $time >expect
1416 echo "A message for a tree" >>expect
1417 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1418 test_expect_success GPG \
1419 'creating a signed tag pointing to a tree should succeed' '
1420 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1421 get_tag_msg tree-signed-tag >actual &&
1422 test_cmp expect actual
1425 get_tag_header blob-signed-tag $blob blob $time >expect
1426 echo "A message for a blob" >>expect
1427 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1428 test_expect_success GPG \
1429 'creating a signed tag pointing to a blob should succeed' '
1430 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1431 get_tag_msg blob-signed-tag >actual &&
1432 test_cmp expect actual
1435 get_tag_header tag-signed-tag $tag tag $time >expect
1436 echo "A message for another tag" >>expect
1437 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1438 test_expect_success GPG \
1439 'creating a signed tag pointing to another tag should succeed' '
1440 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1441 get_tag_msg tag-signed-tag >actual &&
1442 test_cmp expect actual
1445 # usage with rfc1991 signatures
1446 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1447 echo "RFC1991 signed tag" >>expect
1448 echo '-----BEGIN PGP MESSAGE-----' >>expect
1449 test_expect_success GPG,RFC1991 \
1450 'creating a signed tag with rfc1991' '
1451 echo "rfc1991" >gpghome/gpg.conf &&
1452 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1453 get_tag_msg rfc1991-signed-tag >actual &&
1454 test_cmp expect actual
1457 cat >fakeeditor <<'EOF'
1458 #!/bin/sh
1459 cp "$1" actual
1461 chmod +x fakeeditor
1463 test_expect_success GPG,RFC1991 \
1464 'reediting a signed tag body omits signature' '
1465 echo "rfc1991" >gpghome/gpg.conf &&
1466 echo "RFC1991 signed tag" >expect &&
1467 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1468 test_cmp expect actual
1471 test_expect_success GPG,RFC1991 \
1472 'verifying rfc1991 signature' '
1473 echo "rfc1991" >gpghome/gpg.conf &&
1474 git tag -v rfc1991-signed-tag
1477 test_expect_success GPG,RFC1991 \
1478 'list tag with rfc1991 signature' '
1479 echo "rfc1991" >gpghome/gpg.conf &&
1480 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1481 git tag -l -n1 rfc1991-signed-tag >actual &&
1482 test_cmp expect actual &&
1483 git tag -l -n2 rfc1991-signed-tag >actual &&
1484 test_cmp expect actual &&
1485 git tag -l -n999 rfc1991-signed-tag >actual &&
1486 test_cmp expect actual
1489 rm -f gpghome/gpg.conf
1491 test_expect_success GPG,RFC1991 \
1492 'verifying rfc1991 signature without --rfc1991' '
1493 git tag -v rfc1991-signed-tag
1496 test_expect_success GPG,RFC1991 \
1497 'list tag with rfc1991 signature without --rfc1991' '
1498 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1499 git tag -l -n1 rfc1991-signed-tag >actual &&
1500 test_cmp expect actual &&
1501 git tag -l -n2 rfc1991-signed-tag >actual &&
1502 test_cmp expect actual &&
1503 git tag -l -n999 rfc1991-signed-tag >actual &&
1504 test_cmp expect actual
1507 test_expect_success GPG,RFC1991 \
1508 'reediting a signed tag body omits signature' '
1509 echo "RFC1991 signed tag" >expect &&
1510 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1511 test_cmp expect actual
1514 # try to sign with bad user.signingkey
1515 test_expect_success GPG \
1516 'git tag -s fails if gpg is misconfigured (bad key)' \
1517 'test_config user.signingkey BobTheMouse &&
1518 test_must_fail git tag -s -m tail tag-gpg-failure'
1520 # try to produce invalid signature
1521 test_expect_success GPG \
1522 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1523 'test_config gpg.program echo &&
1524 test_must_fail git tag -s -m tail tag-gpg-failure'
1526 # try to produce invalid signature
1527 test_expect_success GPG 'git verifies tag is valid with double signature' '
1528 git tag -s -m tail tag-gpg-double-sig &&
1529 git cat-file tag tag-gpg-double-sig >tag &&
1530 othersigheader=$(test_oid othersigheader) &&
1531 sed -ne "/^\$/q;p" tag >new-tag &&
1532 cat <<-EOM >>new-tag &&
1533 $othersigheader -----BEGIN PGP SIGNATURE-----
1534 someinvaliddata
1535 -----END PGP SIGNATURE-----
1537 sed -e "1,/^tagger/d" tag >>new-tag &&
1538 new_tag=$(git hash-object -t tag -w new-tag) &&
1539 git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1540 git verify-tag tag-gpg-double-sig &&
1541 git fsck
1544 # try to sign with bad user.signingkey
1545 test_expect_success GPGSM \
1546 'git tag -s fails if gpgsm is misconfigured (bad key)' \
1547 'test_config user.signingkey BobTheMouse &&
1548 test_config gpg.format x509 &&
1549 test_must_fail git tag -s -m tail tag-gpg-failure'
1551 # try to produce invalid signature
1552 test_expect_success GPGSM \
1553 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1554 'test_config gpg.x509.program echo &&
1555 test_config gpg.format x509 &&
1556 test_must_fail git tag -s -m tail tag-gpg-failure'
1558 # try to verify without gpg:
1560 rm -rf gpghome
1561 test_expect_success GPG \
1562 'verify signed tag fails when public key is not present' \
1563 'test_must_fail git tag -v signed-tag'
1565 test_expect_success \
1566 'git tag -a fails if tag annotation is empty' '
1567 ! (GIT_EDITOR=cat git tag -a initial-comment)
1570 test_expect_success \
1571 'message in editor has initial comment' '
1572 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1575 test_expect_success 'message in editor has initial comment: first line' '
1576 # check the first line --- should be empty
1577 echo >first.expect &&
1578 sed -e 1q <actual >first.actual &&
1579 test_cmp first.expect first.actual
1582 test_expect_success \
1583 'message in editor has initial comment: remainder' '
1584 # remove commented lines from the remainder -- should be empty
1585 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1586 test_must_be_empty rest.actual
1589 get_tag_header reuse $commit commit $time >expect
1590 echo "An annotation to be reused" >> expect
1591 test_expect_success \
1592 'overwriting an annotated tag should use its previous body' '
1593 git tag -a -m "An annotation to be reused" reuse &&
1594 GIT_EDITOR=true git tag -f -a reuse &&
1595 get_tag_msg reuse >actual &&
1596 test_cmp expect actual
1599 test_expect_success 'filename for the message is relative to cwd' '
1600 mkdir subdir &&
1601 echo "Tag message in top directory" >msgfile-5 &&
1602 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1604 cd subdir &&
1605 git tag -a -F msgfile-5 tag-from-subdir
1606 ) &&
1607 git cat-file tag tag-from-subdir | grep "in sub directory"
1610 test_expect_success 'filename for the message is relative to cwd' '
1611 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1613 cd subdir &&
1614 git tag -a -F msgfile-6 tag-from-subdir-2
1615 ) &&
1616 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1619 # create a few more commits to test --contains
1621 hash1=$(git rev-parse HEAD)
1623 test_expect_success 'creating second commit and tag' '
1624 echo foo-2.0 >foo &&
1625 git add foo &&
1626 git commit -m second &&
1627 git tag v2.0
1630 hash2=$(git rev-parse HEAD)
1632 test_expect_success 'creating third commit without tag' '
1633 echo foo-dev >foo &&
1634 git add foo &&
1635 git commit -m third
1638 hash3=$(git rev-parse HEAD)
1640 # simple linear checks of --continue
1642 cat > expected <<EOF
1643 v0.2.1
1644 v1.0
1645 v1.0.1
1646 v1.1.3
1647 v2.0
1650 test_expect_success 'checking that first commit is in all tags (hash)' "
1651 git tag -l --contains $hash1 v* >actual &&
1652 test_cmp expected actual
1655 # other ways of specifying the commit
1656 test_expect_success 'checking that first commit is in all tags (tag)' "
1657 git tag -l --contains v1.0 v* >actual &&
1658 test_cmp expected actual
1661 test_expect_success 'checking that first commit is in all tags (relative)' "
1662 git tag -l --contains HEAD~2 v* >actual &&
1663 test_cmp expected actual
1666 # All the --contains tests above, but with --no-contains
1667 test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1668 git tag -l --no-contains $hash1 v* >actual &&
1669 test_must_be_empty actual
1672 test_expect_success 'checking that first commit is in all tags (tag)' "
1673 git tag -l --no-contains v1.0 v* >actual &&
1674 test_must_be_empty actual
1677 test_expect_success 'checking that first commit is in all tags (relative)' "
1678 git tag -l --no-contains HEAD~2 v* >actual &&
1679 test_must_be_empty actual
1682 cat > expected <<EOF
1683 v2.0
1686 test_expect_success 'checking that second commit only has one tag' "
1687 git tag -l --contains $hash2 v* >actual &&
1688 test_cmp expected actual
1691 cat > expected <<EOF
1692 v0.2.1
1693 v1.0
1694 v1.0.1
1695 v1.1.3
1698 test_expect_success 'inverse of the last test, with --no-contains' "
1699 git tag -l --no-contains $hash2 v* >actual &&
1700 test_cmp expected actual
1703 test_expect_success 'checking that third commit has no tags' "
1704 git tag -l --contains $hash3 v* >actual &&
1705 test_must_be_empty actual
1708 cat > expected <<EOF
1709 v0.2.1
1710 v1.0
1711 v1.0.1
1712 v1.1.3
1713 v2.0
1716 test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1717 git tag -l --no-contains $hash3 v* >actual &&
1718 test_cmp expected actual
1721 # how about a simple merge?
1723 test_expect_success 'creating simple branch' '
1724 git branch stable v2.0 &&
1725 git checkout stable &&
1726 echo foo-3.0 > foo &&
1727 git commit foo -m fourth &&
1728 git tag v3.0
1731 hash4=$(git rev-parse HEAD)
1733 cat > expected <<EOF
1734 v3.0
1737 test_expect_success 'checking that branch head only has one tag' "
1738 git tag -l --contains $hash4 v* >actual &&
1739 test_cmp expected actual
1742 cat > expected <<EOF
1743 v0.2.1
1744 v1.0
1745 v1.0.1
1746 v1.1.3
1747 v2.0
1750 test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1751 git tag -l --no-contains $hash4 v* >actual &&
1752 test_cmp expected actual
1755 test_expect_success 'merging original branch into this branch' '
1756 git merge --strategy=ours main &&
1757 git tag v4.0
1760 cat > expected <<EOF
1761 v4.0
1764 test_expect_success 'checking that original branch head has one tag now' "
1765 git tag -l --contains $hash3 v* >actual &&
1766 test_cmp expected actual
1769 cat > expected <<EOF
1770 v0.2.1
1771 v1.0
1772 v1.0.1
1773 v1.1.3
1774 v2.0
1775 v3.0
1778 test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1779 git tag -l --no-contains $hash3 v* >actual &&
1780 test_cmp expected actual
1783 cat > expected <<EOF
1784 v0.2.1
1785 v1.0
1786 v1.0.1
1787 v1.1.3
1788 v2.0
1789 v3.0
1790 v4.0
1793 test_expect_success 'checking that initial commit is in all tags' "
1794 git tag -l --contains $hash1 v* >actual &&
1795 test_cmp expected actual
1798 test_expect_success 'checking that --contains can be used in non-list mode' '
1799 git tag --contains $hash1 v* >actual &&
1800 test_cmp expected actual
1803 test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1804 git tag -l --no-contains $hash1 v* >actual &&
1805 test_must_be_empty actual
1808 # mixing modes and options:
1810 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1811 test_must_fail git tag -a &&
1812 test_must_fail git tag -a -l &&
1813 test_must_fail git tag -s &&
1814 test_must_fail git tag -s -l &&
1815 test_must_fail git tag -m &&
1816 test_must_fail git tag -m -l &&
1817 test_must_fail git tag -m "hlagh" &&
1818 test_must_fail git tag -m "hlagh" -l &&
1819 test_must_fail git tag -F &&
1820 test_must_fail git tag -F -l &&
1821 test_must_fail git tag -f &&
1822 test_must_fail git tag -f -l &&
1823 test_must_fail git tag -a -s -m -F &&
1824 test_must_fail git tag -a -s -m -F -l &&
1825 test_must_fail git tag -l -v &&
1826 test_must_fail git tag -l -d &&
1827 test_must_fail git tag -l -v -d &&
1828 test_must_fail git tag -n 100 -v &&
1829 test_must_fail git tag -l -m msg &&
1830 test_must_fail git tag -l -F some file &&
1831 test_must_fail git tag -v -s &&
1832 test_must_fail git tag --contains tag-tree &&
1833 test_must_fail git tag --contains tag-blob &&
1834 test_must_fail git tag --no-contains tag-tree &&
1835 test_must_fail git tag --no-contains tag-blob &&
1836 test_must_fail git tag --contains --no-contains &&
1837 test_must_fail git tag --no-with HEAD &&
1838 test_must_fail git tag --no-without HEAD
1841 for option in --contains --with --no-contains --without --merged --no-merged --points-at
1843 test_expect_success "mixing incompatible modes with $option is forbidden" "
1844 test_must_fail git tag -d $option HEAD &&
1845 test_must_fail git tag -d $option HEAD some-tag &&
1846 test_must_fail git tag -v $option HEAD
1848 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1849 git tag -n $option HEAD HEAD &&
1850 git tag $option HEAD HEAD &&
1851 git tag $option
1853 done
1855 # check points-at
1857 test_expect_success '--points-at can be used in non-list mode' '
1858 echo v4.0 >expect &&
1859 git tag --points-at=v4.0 "v*" >actual &&
1860 test_cmp expect actual
1863 test_expect_success '--points-at is a synonym for --points-at HEAD' '
1864 echo v4.0 >expect &&
1865 git tag --points-at >actual &&
1866 test_cmp expect actual
1869 test_expect_success '--points-at finds lightweight tags' '
1870 echo v4.0 >expect &&
1871 git tag --points-at v4.0 >actual &&
1872 test_cmp expect actual
1875 test_expect_success '--points-at finds annotated tags of commits' '
1876 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1877 echo annotated-v4.0 >expect &&
1878 git tag -l --points-at v4.0 "annotated*" >actual &&
1879 test_cmp expect actual
1882 test_expect_success '--points-at finds annotated tags of tags' '
1883 git tag -m "describing the v4.0 tag object" \
1884 annotated-again-v4.0 annotated-v4.0 &&
1885 cat >expect <<-\EOF &&
1886 annotated-again-v4.0
1887 annotated-v4.0
1889 git tag --points-at=annotated-v4.0 >actual &&
1890 test_cmp expect actual
1893 test_expect_success 'recursive tagging should give advice' '
1894 cat >expect <<-EOF &&
1895 hint: You have created a nested tag. The object referred to by your new tag is
1896 hint: already a tag. If you meant to tag the object that it points to, use:
1897 hint:
1898 hint: git tag -f nested annotated-v4.0^{}
1899 hint: Disable this message with "git config advice.nestedTag false"
1901 git tag -m nested nested annotated-v4.0 2>actual &&
1902 test_cmp expect actual
1905 test_expect_success 'multiple --points-at are OR-ed together' '
1906 cat >expect <<-\EOF &&
1907 v2.0
1908 v3.0
1910 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1911 test_cmp expect actual
1914 test_expect_success 'lexical sort' '
1915 git tag foo1.3 &&
1916 git tag foo1.6 &&
1917 git tag foo1.10 &&
1918 git tag -l --sort=refname "foo*" >actual &&
1919 cat >expect <<-\EOF &&
1920 foo1.10
1921 foo1.3
1922 foo1.6
1924 test_cmp expect actual
1927 test_expect_success 'version sort' '
1928 git tag -l --sort=version:refname "foo*" >actual &&
1929 cat >expect <<-\EOF &&
1930 foo1.3
1931 foo1.6
1932 foo1.10
1934 test_cmp expect actual
1937 test_expect_success 'reverse version sort' '
1938 git tag -l --sort=-version:refname "foo*" >actual &&
1939 cat >expect <<-\EOF &&
1940 foo1.10
1941 foo1.6
1942 foo1.3
1944 test_cmp expect actual
1947 test_expect_success 'reverse lexical sort' '
1948 git tag -l --sort=-refname "foo*" >actual &&
1949 cat >expect <<-\EOF &&
1950 foo1.6
1951 foo1.3
1952 foo1.10
1954 test_cmp expect actual
1957 test_expect_success 'configured lexical sort' '
1958 test_config tag.sort "v:refname" &&
1959 git tag -l "foo*" >actual &&
1960 cat >expect <<-\EOF &&
1961 foo1.3
1962 foo1.6
1963 foo1.10
1965 test_cmp expect actual
1968 test_expect_success 'option override configured sort' '
1969 test_config tag.sort "v:refname" &&
1970 git tag -l --sort=-refname "foo*" >actual &&
1971 cat >expect <<-\EOF &&
1972 foo1.6
1973 foo1.3
1974 foo1.10
1976 test_cmp expect actual
1979 test_expect_success '--no-sort cancels config sort keys' '
1980 test_config tag.sort "-refname" &&
1982 # objecttype is identical for all of them, so sort falls back on
1983 # default (ascending refname)
1984 git tag -l \
1985 --no-sort \
1986 --sort="objecttype" \
1987 "foo*" >actual &&
1988 cat >expect <<-\EOF &&
1989 foo1.10
1990 foo1.3
1991 foo1.6
1993 test_cmp expect actual
1996 test_expect_success '--no-sort cancels command line sort keys' '
1997 # objecttype is identical for all of them, so sort falls back on
1998 # default (ascending refname)
1999 git tag -l \
2000 --sort="-refname" \
2001 --no-sort \
2002 --sort="objecttype" \
2003 "foo*" >actual &&
2004 cat >expect <<-\EOF &&
2005 foo1.10
2006 foo1.3
2007 foo1.6
2009 test_cmp expect actual
2012 test_expect_success '--no-sort without subsequent --sort prints expected tags' '
2013 # Sort the results with `sort` for a consistent comparison against
2014 # expected
2015 git tag -l --no-sort "foo*" | sort >actual &&
2016 cat >expect <<-\EOF &&
2017 foo1.10
2018 foo1.3
2019 foo1.6
2021 test_cmp expect actual
2024 test_expect_success 'invalid sort parameter on command line' '
2025 test_must_fail git tag -l --sort=notvalid "foo*" >actual
2028 test_expect_success 'invalid sort parameter in configuratoin' '
2029 test_config tag.sort "v:notvalid" &&
2030 test_must_fail git tag -l "foo*"
2033 test_expect_success 'version sort handles empty value for versionsort.{prereleaseSuffix,suffix}' '
2034 cp .git/config .git/config.orig &&
2035 test_when_finished mv .git/config.orig .git/config &&
2037 cat >>.git/config <<-\EOF &&
2038 [versionsort]
2039 prereleaseSuffix
2040 suffix
2042 cat >expect <<-\EOF &&
2043 error: missing value for '\''versionsort.suffix'\''
2044 error: missing value for '\''versionsort.prereleasesuffix'\''
2046 git tag -l --sort=version:refname 2>actual &&
2047 test_cmp expect actual
2050 test_expect_success 'version sort with prerelease reordering' '
2051 test_config versionsort.prereleaseSuffix -rc &&
2052 git tag foo1.6-rc1 &&
2053 git tag foo1.6-rc2 &&
2054 git tag -l --sort=version:refname "foo*" >actual &&
2055 cat >expect <<-\EOF &&
2056 foo1.3
2057 foo1.6-rc1
2058 foo1.6-rc2
2059 foo1.6
2060 foo1.10
2062 test_cmp expect actual
2065 test_expect_success 'reverse version sort with prerelease reordering' '
2066 test_config versionsort.prereleaseSuffix -rc &&
2067 git tag -l --sort=-version:refname "foo*" >actual &&
2068 cat >expect <<-\EOF &&
2069 foo1.10
2070 foo1.6
2071 foo1.6-rc2
2072 foo1.6-rc1
2073 foo1.3
2075 test_cmp expect actual
2078 test_expect_success 'version sort with prerelease reordering and common leading character' '
2079 test_config versionsort.prereleaseSuffix -before &&
2080 git tag foo1.7-before1 &&
2081 git tag foo1.7 &&
2082 git tag foo1.7-after1 &&
2083 git tag -l --sort=version:refname "foo1.7*" >actual &&
2084 cat >expect <<-\EOF &&
2085 foo1.7-before1
2086 foo1.7
2087 foo1.7-after1
2089 test_cmp expect actual
2092 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
2093 test_config versionsort.prereleaseSuffix -before &&
2094 git config --add versionsort.prereleaseSuffix -after &&
2095 git tag -l --sort=version:refname "foo1.7*" >actual &&
2096 cat >expect <<-\EOF &&
2097 foo1.7-before1
2098 foo1.7-after1
2099 foo1.7
2101 test_cmp expect actual
2104 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
2105 test_config versionsort.prereleaseSuffix -bar &&
2106 git config --add versionsort.prereleaseSuffix -foo-baz &&
2107 git config --add versionsort.prereleaseSuffix -foo-bar &&
2108 git tag foo1.8-foo-bar &&
2109 git tag foo1.8-foo-baz &&
2110 git tag foo1.8 &&
2111 git tag -l --sort=version:refname "foo1.8*" >actual &&
2112 cat >expect <<-\EOF &&
2113 foo1.8-foo-baz
2114 foo1.8-foo-bar
2115 foo1.8
2117 test_cmp expect actual
2120 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
2121 test_config versionsort.prereleaseSuffix -pre &&
2122 git config --add versionsort.prereleaseSuffix -prerelease &&
2123 git tag foo1.9-pre1 &&
2124 git tag foo1.9-pre2 &&
2125 git tag foo1.9-prerelease1 &&
2126 git tag -l --sort=version:refname "foo1.9*" >actual &&
2127 cat >expect <<-\EOF &&
2128 foo1.9-pre1
2129 foo1.9-pre2
2130 foo1.9-prerelease1
2132 test_cmp expect actual
2135 test_expect_success 'version sort with general suffix reordering' '
2136 test_config versionsort.suffix -alpha &&
2137 git config --add versionsort.suffix -beta &&
2138 git config --add versionsort.suffix "" &&
2139 git config --add versionsort.suffix -gamma &&
2140 git config --add versionsort.suffix -delta &&
2141 git tag foo1.10-alpha &&
2142 git tag foo1.10-beta &&
2143 git tag foo1.10-gamma &&
2144 git tag foo1.10-delta &&
2145 git tag foo1.10-unlisted-suffix &&
2146 git tag -l --sort=version:refname "foo1.10*" >actual &&
2147 cat >expect <<-\EOF &&
2148 foo1.10-alpha
2149 foo1.10-beta
2150 foo1.10
2151 foo1.10-unlisted-suffix
2152 foo1.10-gamma
2153 foo1.10-delta
2155 test_cmp expect actual
2158 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
2159 test_config versionsort.suffix -before &&
2160 test_config versionsort.prereleaseSuffix -after &&
2161 git tag -l --sort=version:refname "foo1.7*" >actual &&
2162 cat >expect <<-\EOF &&
2163 foo1.7-before1
2164 foo1.7
2165 foo1.7-after1
2167 test_cmp expect actual
2170 test_expect_success 'version sort with very long prerelease suffix' '
2171 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
2172 git tag -l --sort=version:refname
2175 test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
2176 i=1 &&
2177 while test $i -lt 8000
2179 echo "commit refs/heads/main
2180 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
2181 data <<EOF
2182 commit #$i
2183 EOF" &&
2184 if test $i = 1
2185 then
2186 echo "from refs/heads/main^0"
2187 fi &&
2188 i=$(($i + 1)) || return 1
2189 done | git fast-import &&
2190 git checkout main &&
2191 git tag far-far-away HEAD^ &&
2192 run_with_limited_stack git tag --contains HEAD >actual &&
2193 test_must_be_empty actual &&
2194 run_with_limited_stack git tag --no-contains HEAD >actual &&
2195 test_line_count "-gt" 10 actual
2198 test_expect_success '--format should list tags as per format given' '
2199 cat >expect <<-\EOF &&
2200 refname : refs/tags/v1.0
2201 refname : refs/tags/v1.0.1
2202 refname : refs/tags/v1.1.3
2204 git tag -l --format="refname : %(refname)" "v1*" >actual &&
2205 test_cmp expect actual
2208 test_expect_success '--format --omit-empty works' '
2209 cat >expect <<-\EOF &&
2210 refname : refs/tags/v1.0
2212 refname : refs/tags/v1.1.3
2214 git tag -l --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2215 test_cmp expect actual &&
2216 cat >expect <<-\EOF &&
2217 refname : refs/tags/v1.0
2218 refname : refs/tags/v1.1.3
2220 git tag -l --omit-empty --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2221 test_cmp expect actual
2224 test_expect_success 'git tag -l with --format="%(rest)" must fail' '
2225 test_must_fail git tag -l --format="%(rest)" "v1*"
2228 test_expect_success "set up color tests" '
2229 echo "<RED>v1.0<RESET>" >expect.color &&
2230 echo "v1.0" >expect.bare &&
2231 color_args="--format=%(color:red)%(refname:short) --list v1.0"
2234 test_expect_success '%(color) omitted without tty' '
2235 TERM=vt100 git tag $color_args >actual.raw &&
2236 test_decode_color <actual.raw >actual &&
2237 test_cmp expect.bare actual
2240 test_expect_success TTY '%(color) present with tty' '
2241 test_terminal git tag $color_args >actual.raw &&
2242 test_decode_color <actual.raw >actual &&
2243 test_cmp expect.color actual
2246 test_expect_success '--color overrides auto-color' '
2247 git tag --color $color_args >actual.raw &&
2248 test_decode_color <actual.raw >actual &&
2249 test_cmp expect.color actual
2252 test_expect_success 'color.ui=always overrides auto-color' '
2253 git -c color.ui=always tag $color_args >actual.raw &&
2254 test_decode_color <actual.raw >actual &&
2255 test_cmp expect.color actual
2258 test_expect_success 'setup --merged test tags' '
2259 git tag mergetest-1 HEAD~2 &&
2260 git tag mergetest-2 HEAD~1 &&
2261 git tag mergetest-3 HEAD
2264 test_expect_success '--merged can be used in non-list mode' '
2265 cat >expect <<-\EOF &&
2266 mergetest-1
2267 mergetest-2
2269 git tag --merged=mergetest-2 "mergetest*" >actual &&
2270 test_cmp expect actual
2273 test_expect_success '--merged is compatible with --no-merged' '
2274 git tag --merged HEAD --no-merged HEAD
2277 test_expect_success '--merged shows merged tags' '
2278 cat >expect <<-\EOF &&
2279 mergetest-1
2280 mergetest-2
2282 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2283 test_cmp expect actual
2286 test_expect_success '--no-merged show unmerged tags' '
2287 cat >expect <<-\EOF &&
2288 mergetest-3
2290 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2291 test_cmp expect actual
2294 test_expect_success '--no-merged can be used in non-list mode' '
2295 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2296 test_cmp expect actual
2299 test_expect_success 'ambiguous branch/tags not marked' '
2300 git tag ambiguous &&
2301 git branch ambiguous &&
2302 echo ambiguous >expect &&
2303 git tag -l ambiguous >actual &&
2304 test_cmp expect actual
2307 test_expect_success '--contains combined with --no-contains' '
2309 git init no-contains &&
2310 cd no-contains &&
2311 test_commit v0.1 &&
2312 test_commit v0.2 &&
2313 test_commit v0.3 &&
2314 test_commit v0.4 &&
2315 test_commit v0.5 &&
2316 cat >expected <<-\EOF &&
2317 v0.2
2318 v0.3
2319 v0.4
2321 git tag --contains v0.2 --no-contains v0.5 >actual &&
2322 test_cmp expected actual
2326 # As the docs say, list tags which contain a specified *commit*. We
2327 # don't recurse down to tags for trees or blobs pointed to by *those*
2328 # commits.
2329 test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2330 cd no-contains &&
2331 blob=$(git rev-parse v0.3:v0.3.t) &&
2332 tree=$(git rev-parse v0.3^{tree}) &&
2333 git tag tag-blob $blob &&
2334 git tag tag-tree $tree &&
2335 git tag --contains v0.3 >actual &&
2336 cat >expected <<-\EOF &&
2337 v0.3
2338 v0.4
2339 v0.5
2341 test_cmp expected actual &&
2342 git tag --no-contains v0.3 >actual &&
2343 cat >expected <<-\EOF &&
2344 v0.1
2345 v0.2
2347 test_cmp expected actual
2350 test_expect_success 'If tag is created then tag message file is unlinked' '
2351 test_when_finished "git tag -d foo" &&
2352 write_script fakeeditor <<-\EOF &&
2353 echo Message >.git/TAG_EDITMSG
2355 GIT_EDITOR=./fakeeditor git tag -a foo &&
2356 test_path_is_missing .git/TAG_EDITMSG
2359 test_expect_success 'If tag cannot be created then tag message file is not unlinked' '
2360 test_when_finished "git tag -d foo/bar && rm .git/TAG_EDITMSG" &&
2361 write_script fakeeditor <<-\EOF &&
2362 echo Message >.git/TAG_EDITMSG
2364 git tag foo/bar &&
2365 test_must_fail env GIT_EDITOR=./fakeeditor git tag -a foo &&
2366 test_path_exists .git/TAG_EDITMSG
2369 test_done