tag doc: split up the --[no-]merged documentation
[git.git] / t / t7004-tag.sh
blobb4698ab5f53c2ce92bd349fe4fa336e5fc5ca3e5
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git tag
8 Tests for operations with tags.'
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-gpg.sh
13 # creating and listing lightweight tags:
15 tag_exists () {
16 git show-ref --quiet --verify refs/tags/"$1"
19 # todo: git tag -l now returns always zero, when fixed, change this test
20 test_expect_success 'listing all tags in an empty tree should succeed' '
21 git tag -l &&
22 git tag
25 test_expect_success 'listing all tags in an empty tree should output nothing' '
26 test $(git tag -l | wc -l) -eq 0 &&
27 test $(git tag | wc -l) -eq 0
30 test_expect_success '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_cmp 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_cmp 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 test_expect_success 'listing all tags if one exists should output that tag' '
123 test $(git tag -l) = mytag &&
124 test $(git tag) = mytag
127 # pattern matching:
129 test_expect_success 'listing a tag using a matching pattern should succeed' \
130 'git tag -l mytag'
132 test_expect_success 'listing a tag with --ignore-case' \
133 'test $(git tag -l --ignore-case MYTAG) = mytag'
135 test_expect_success \
136 'listing a tag using a matching pattern should output that tag' \
137 'test $(git tag -l mytag) = mytag'
139 # todo: git tag -l now returns always zero, when fixed, change this test
140 test_expect_success \
141 'listing tags using a non-matching pattern should suceed' \
142 'git tag -l xxx'
144 test_expect_success \
145 'listing tags using a non-matching pattern should output nothing' \
146 'test $(git tag -l xxx | wc -l) -eq 0'
148 # special cases for creating tags:
150 test_expect_success \
151 'trying to create a tag with the name of one existing should fail' \
152 'test_must_fail git tag mytag'
154 test_expect_success \
155 'trying to create a tag with a non-valid name should fail' '
156 test $(git tag -l | wc -l) -eq 1 &&
157 test_must_fail git tag "" &&
158 test_must_fail git tag .othertag &&
159 test_must_fail git tag "other tag" &&
160 test_must_fail git tag "othertag^" &&
161 test_must_fail git tag "other~tag" &&
162 test $(git tag -l | wc -l) -eq 1
165 test_expect_success 'creating a tag using HEAD directly should succeed' '
166 git tag myhead HEAD &&
167 tag_exists myhead
170 test_expect_success '--force can create a tag with the name of one existing' '
171 tag_exists mytag &&
172 git tag --force mytag &&
173 tag_exists mytag'
175 test_expect_success '--force is moot with a non-existing tag name' '
176 test_when_finished git tag -d newtag forcetag &&
177 git tag newtag >expect &&
178 git tag --force forcetag >actual &&
179 test_cmp expect actual
182 # deleting tags:
184 test_expect_success 'trying to delete an unknown tag should fail' '
185 ! tag_exists unknown-tag &&
186 test_must_fail git tag -d unknown-tag
189 cat >expect <<EOF
190 myhead
191 mytag
193 test_expect_success \
194 'trying to delete tags without params should succeed and do nothing' '
195 git tag -l > actual && test_cmp expect actual &&
196 git tag -d &&
197 git tag -l > actual && test_cmp expect actual
200 test_expect_success \
201 'deleting two existing tags in one command should succeed' '
202 tag_exists mytag &&
203 tag_exists myhead &&
204 git tag -d mytag myhead &&
205 ! tag_exists mytag &&
206 ! tag_exists myhead
209 test_expect_success \
210 'creating a tag with the name of another deleted one should succeed' '
211 ! tag_exists mytag &&
212 git tag mytag &&
213 tag_exists mytag
216 test_expect_success \
217 'trying to delete two tags, existing and not, should fail in the 2nd' '
218 tag_exists mytag &&
219 ! tag_exists myhead &&
220 test_must_fail git tag -d mytag anothertag &&
221 ! tag_exists mytag &&
222 ! tag_exists myhead
225 test_expect_success 'trying to delete an already deleted tag should fail' \
226 'test_must_fail git tag -d mytag'
228 # listing various tags with pattern matching:
230 cat >expect <<EOF
234 t210
235 t211
236 v0.2.1
237 v1.0
238 v1.0.1
239 v1.1.3
241 test_expect_success 'listing all tags should print them ordered' '
242 git tag v1.0.1 &&
243 git tag t211 &&
244 git tag aa1 &&
245 git tag v0.2.1 &&
246 git tag v1.1.3 &&
247 git tag cba &&
248 git tag a1 &&
249 git tag v1.0 &&
250 git tag t210 &&
251 git tag -l > actual &&
252 test_cmp expect actual &&
253 git tag > actual &&
254 test_cmp expect actual
257 cat >expect <<EOF
262 test_expect_success \
263 'listing tags with substring as pattern must print those matching' '
264 rm *a* &&
265 git tag -l "*a*" > current &&
266 test_cmp expect current
269 cat >expect <<EOF
270 v0.2.1
271 v1.0.1
273 test_expect_success \
274 'listing tags with a suffix as pattern must print those matching' '
275 git tag -l "*.1" > actual &&
276 test_cmp expect actual
279 cat >expect <<EOF
280 t210
281 t211
283 test_expect_success \
284 'listing tags with a prefix as pattern must print those matching' '
285 git tag -l "t21*" > actual &&
286 test_cmp expect actual
289 cat >expect <<EOF
292 test_expect_success \
293 'listing tags using a name as pattern must print that one matching' '
294 git tag -l a1 > actual &&
295 test_cmp expect actual
298 cat >expect <<EOF
299 v1.0
301 test_expect_success \
302 'listing tags using a name as pattern must print that one matching' '
303 git tag -l v1.0 > actual &&
304 test_cmp expect actual
307 cat >expect <<EOF
308 v1.0.1
309 v1.1.3
311 test_expect_success \
312 'listing tags with ? in the pattern should print those matching' '
313 git tag -l "v1.?.?" > actual &&
314 test_cmp expect actual
317 >expect
318 test_expect_success \
319 'listing tags using v.* should print nothing because none have v.' '
320 git tag -l "v.*" > actual &&
321 test_cmp expect actual
324 cat >expect <<EOF
325 v0.2.1
326 v1.0
327 v1.0.1
328 v1.1.3
330 test_expect_success \
331 'listing tags using v* should print only those having v' '
332 git tag -l "v*" > actual &&
333 test_cmp expect actual
336 test_expect_success 'tag -l can accept multiple patterns' '
337 git tag -l "v1*" "v0*" >actual &&
338 test_cmp expect actual
341 test_expect_success 'listing tags in column' '
342 COLUMNS=40 git tag -l --column=row >actual &&
343 cat >expected <<\EOF &&
344 a1 aa1 cba t210 t211
345 v0.2.1 v1.0 v1.0.1 v1.1.3
347 test_cmp expected actual
350 test_expect_success 'listing tags in column with column.*' '
351 test_config column.tag row &&
352 test_config column.ui dense &&
353 COLUMNS=40 git tag -l >actual &&
354 cat >expected <<\EOF &&
355 a1 aa1 cba t210 t211
356 v0.2.1 v1.0 v1.0.1 v1.1.3
358 test_cmp expected actual
361 test_expect_success 'listing tag with -n --column should fail' '
362 test_must_fail git tag --column -n
365 test_expect_success 'listing tags -n in column with column.ui ignored' '
366 test_config column.ui "row dense" &&
367 COLUMNS=40 git tag -l -n >actual &&
368 cat >expected <<\EOF &&
369 a1 Foo
370 aa1 Foo
371 cba Foo
372 t210 Foo
373 t211 Foo
374 v0.2.1 Foo
375 v1.0 Foo
376 v1.0.1 Foo
377 v1.1.3 Foo
379 test_cmp expected actual
382 # creating and verifying lightweight tags:
384 test_expect_success \
385 'a non-annotated tag created without parameters should point to HEAD' '
386 git tag non-annotated-tag &&
387 test $(git cat-file -t non-annotated-tag) = commit &&
388 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
391 test_expect_success 'trying to verify an unknown tag should fail' \
392 'test_must_fail git tag -v unknown-tag'
394 test_expect_success \
395 'trying to verify a non-annotated and non-signed tag should fail' \
396 'test_must_fail git tag -v non-annotated-tag'
398 test_expect_success \
399 'trying to verify many non-annotated or unknown tags, should fail' \
400 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
402 # creating annotated tags:
404 get_tag_msg () {
405 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
408 # run test_tick before committing always gives the time in that timezone
409 get_tag_header () {
410 cat <<EOF
411 object $2
412 type $3
413 tag $1
414 tagger C O Mitter <committer@example.com> $4 -0700
419 commit=$(git rev-parse HEAD)
420 time=$test_tick
422 get_tag_header annotated-tag $commit commit $time >expect
423 echo "A message" >>expect
424 test_expect_success \
425 'creating an annotated tag with -m message should succeed' '
426 git tag -m "A message" annotated-tag &&
427 get_tag_msg annotated-tag >actual &&
428 test_cmp expect actual
431 cat >msgfile <<EOF
432 Another message
433 in a file.
435 get_tag_header file-annotated-tag $commit commit $time >expect
436 cat msgfile >>expect
437 test_expect_success \
438 'creating an annotated tag with -F messagefile should succeed' '
439 git tag -F msgfile file-annotated-tag &&
440 get_tag_msg file-annotated-tag >actual &&
441 test_cmp expect actual
444 cat >inputmsg <<EOF
445 A message from the
446 standard input
448 get_tag_header stdin-annotated-tag $commit commit $time >expect
449 cat inputmsg >>expect
450 test_expect_success 'creating an annotated tag with -F - should succeed' '
451 git tag -F - stdin-annotated-tag <inputmsg &&
452 get_tag_msg stdin-annotated-tag >actual &&
453 test_cmp expect actual
456 test_expect_success \
457 'trying to create a tag with a non-existing -F file should fail' '
458 ! test -f nonexistingfile &&
459 ! tag_exists notag &&
460 test_must_fail git tag -F nonexistingfile notag &&
461 ! tag_exists notag
464 test_expect_success \
465 'trying to create tags giving both -m or -F options should fail' '
466 echo "message file 1" >msgfile1 &&
467 echo "message file 2" >msgfile2 &&
468 ! tag_exists msgtag &&
469 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
470 ! tag_exists msgtag &&
471 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
472 ! tag_exists msgtag &&
473 test_must_fail git tag -m "message 1" -F msgfile1 \
474 -m "message 2" msgtag &&
475 ! tag_exists msgtag
478 # blank and empty messages:
480 get_tag_header empty-annotated-tag $commit commit $time >expect
481 test_expect_success \
482 'creating a tag with an empty -m message should succeed' '
483 git tag -m "" empty-annotated-tag &&
484 get_tag_msg empty-annotated-tag >actual &&
485 test_cmp expect actual
488 >emptyfile
489 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
490 test_expect_success \
491 'creating a tag with an empty -F messagefile should succeed' '
492 git tag -F emptyfile emptyfile-annotated-tag &&
493 get_tag_msg emptyfile-annotated-tag >actual &&
494 test_cmp expect actual
497 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
498 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
499 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
500 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
501 get_tag_header blanks-annotated-tag $commit commit $time >expect
502 cat >>expect <<EOF
503 Leading blank lines
505 Repeated blank lines
507 Trailing spaces
509 Trailing blank lines
511 test_expect_success \
512 'extra blanks in the message for an annotated tag should be removed' '
513 git tag -F blanksfile blanks-annotated-tag &&
514 get_tag_msg blanks-annotated-tag >actual &&
515 test_cmp expect actual
518 get_tag_header blank-annotated-tag $commit commit $time >expect
519 test_expect_success \
520 'creating a tag with blank -m message with spaces should succeed' '
521 git tag -m " " blank-annotated-tag &&
522 get_tag_msg blank-annotated-tag >actual &&
523 test_cmp expect actual
526 echo ' ' >blankfile
527 echo '' >>blankfile
528 echo ' ' >>blankfile
529 get_tag_header blankfile-annotated-tag $commit commit $time >expect
530 test_expect_success \
531 'creating a tag with blank -F messagefile with spaces should succeed' '
532 git tag -F blankfile blankfile-annotated-tag &&
533 get_tag_msg blankfile-annotated-tag >actual &&
534 test_cmp expect actual
537 printf ' ' >blanknonlfile
538 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
539 test_expect_success \
540 'creating a tag with -F file of spaces and no newline should succeed' '
541 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
542 get_tag_msg blanknonlfile-annotated-tag >actual &&
543 test_cmp expect actual
546 # messages with commented lines:
548 cat >commentsfile <<EOF
549 # A comment
551 ############
552 The message.
553 ############
554 One line.
557 # commented lines
558 # commented lines
560 Another line.
561 # comments
563 Last line.
565 get_tag_header comments-annotated-tag $commit commit $time >expect
566 cat >>expect <<EOF
567 The message.
568 One line.
570 Another line.
572 Last line.
574 test_expect_success \
575 'creating a tag using a -F messagefile with #comments should succeed' '
576 git tag -F commentsfile comments-annotated-tag &&
577 get_tag_msg comments-annotated-tag >actual &&
578 test_cmp expect actual
581 get_tag_header comment-annotated-tag $commit commit $time >expect
582 test_expect_success \
583 'creating a tag with a #comment in the -m message should succeed' '
584 git tag -m "#comment" comment-annotated-tag &&
585 get_tag_msg comment-annotated-tag >actual &&
586 test_cmp expect actual
589 echo '#comment' >commentfile
590 echo '' >>commentfile
591 echo '####' >>commentfile
592 get_tag_header commentfile-annotated-tag $commit commit $time >expect
593 test_expect_success \
594 'creating a tag with #comments in the -F messagefile should succeed' '
595 git tag -F commentfile commentfile-annotated-tag &&
596 get_tag_msg commentfile-annotated-tag >actual &&
597 test_cmp expect actual
600 printf '#comment' >commentnonlfile
601 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
602 test_expect_success \
603 'creating a tag with a file of #comment and no newline should succeed' '
604 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
605 get_tag_msg commentnonlfile-annotated-tag >actual &&
606 test_cmp expect actual
609 # listing messages for annotated non-signed tags:
611 test_expect_success \
612 'listing the one-line message of a non-signed tag should succeed' '
613 git tag -m "A msg" tag-one-line &&
615 echo "tag-one-line" >expect &&
616 git tag -l | grep "^tag-one-line" >actual &&
617 test_cmp expect actual &&
618 git tag -n0 -l | grep "^tag-one-line" >actual &&
619 test_cmp expect actual &&
620 git tag -n0 -l tag-one-line >actual &&
621 test_cmp expect actual &&
623 echo "tag-one-line A msg" >expect &&
624 git tag -n1 -l | grep "^tag-one-line" >actual &&
625 test_cmp expect actual &&
626 git tag -n -l | grep "^tag-one-line" >actual &&
627 test_cmp expect actual &&
628 git tag -n1 -l tag-one-line >actual &&
629 test_cmp expect actual &&
630 git tag -n2 -l tag-one-line >actual &&
631 test_cmp expect actual &&
632 git tag -n999 -l tag-one-line >actual &&
633 test_cmp expect actual
636 test_expect_success \
637 'listing the zero-lines message of a non-signed tag should succeed' '
638 git tag -m "" tag-zero-lines &&
640 echo "tag-zero-lines" >expect &&
641 git tag -l | grep "^tag-zero-lines" >actual &&
642 test_cmp expect actual &&
643 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
644 test_cmp expect actual &&
645 git tag -n0 -l tag-zero-lines >actual &&
646 test_cmp expect actual &&
648 echo "tag-zero-lines " >expect &&
649 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
650 test_cmp expect actual &&
651 git tag -n -l | grep "^tag-zero-lines" >actual &&
652 test_cmp expect actual &&
653 git tag -n1 -l tag-zero-lines >actual &&
654 test_cmp expect actual &&
655 git tag -n2 -l tag-zero-lines >actual &&
656 test_cmp expect actual &&
657 git tag -n999 -l tag-zero-lines >actual &&
658 test_cmp expect actual
661 echo 'tag line one' >annotagmsg
662 echo 'tag line two' >>annotagmsg
663 echo 'tag line three' >>annotagmsg
664 test_expect_success \
665 'listing many message lines of a non-signed tag should succeed' '
666 git tag -F annotagmsg tag-lines &&
668 echo "tag-lines" >expect &&
669 git tag -l | grep "^tag-lines" >actual &&
670 test_cmp expect actual &&
671 git tag -n0 -l | grep "^tag-lines" >actual &&
672 test_cmp expect actual &&
673 git tag -n0 -l tag-lines >actual &&
674 test_cmp expect actual &&
676 echo "tag-lines tag line one" >expect &&
677 git tag -n1 -l | grep "^tag-lines" >actual &&
678 test_cmp expect actual &&
679 git tag -n -l | grep "^tag-lines" >actual &&
680 test_cmp expect actual &&
681 git tag -n1 -l tag-lines >actual &&
682 test_cmp expect actual &&
684 echo " tag line two" >>expect &&
685 git tag -n2 -l | grep "^ *tag.line" >actual &&
686 test_cmp expect actual &&
687 git tag -n2 -l tag-lines >actual &&
688 test_cmp expect actual &&
690 echo " tag line three" >>expect &&
691 git tag -n3 -l | grep "^ *tag.line" >actual &&
692 test_cmp expect actual &&
693 git tag -n3 -l tag-lines >actual &&
694 test_cmp expect actual &&
695 git tag -n4 -l | grep "^ *tag.line" >actual &&
696 test_cmp expect actual &&
697 git tag -n4 -l tag-lines >actual &&
698 test_cmp expect actual &&
699 git tag -n99 -l | grep "^ *tag.line" >actual &&
700 test_cmp expect actual &&
701 git tag -n99 -l tag-lines >actual &&
702 test_cmp expect actual
705 test_expect_success 'annotations for blobs are empty' '
706 blob=$(git hash-object -w --stdin <<-\EOF
707 Blob paragraph 1.
709 Blob paragraph 2.
711 ) &&
712 git tag tag-blob $blob &&
713 echo "tag-blob " >expect &&
714 git tag -n1 -l tag-blob >actual &&
715 test_cmp expect actual
718 # trying to verify annotated non-signed tags:
720 test_expect_success GPG \
721 'trying to verify an annotated non-signed tag should fail' '
722 tag_exists annotated-tag &&
723 test_must_fail git tag -v annotated-tag
726 test_expect_success GPG \
727 'trying to verify a file-annotated non-signed tag should fail' '
728 tag_exists file-annotated-tag &&
729 test_must_fail git tag -v file-annotated-tag
732 test_expect_success GPG \
733 'trying to verify two annotated non-signed tags should fail' '
734 tag_exists annotated-tag file-annotated-tag &&
735 test_must_fail git tag -v annotated-tag file-annotated-tag
738 # creating and verifying signed tags:
740 get_tag_header signed-tag $commit commit $time >expect
741 echo 'A signed tag message' >>expect
742 echo '-----BEGIN PGP SIGNATURE-----' >>expect
743 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
744 git tag -s -m "A signed tag message" signed-tag &&
745 get_tag_msg signed-tag >actual &&
746 test_cmp expect actual
749 get_tag_header u-signed-tag $commit commit $time >expect
750 echo 'Another message' >>expect
751 echo '-----BEGIN PGP SIGNATURE-----' >>expect
752 test_expect_success GPG 'sign with a given key id' '
754 git tag -u committer@example.com -m "Another message" u-signed-tag &&
755 get_tag_msg u-signed-tag >actual &&
756 test_cmp expect actual
760 test_expect_success GPG 'sign with an unknown id (1)' '
762 test_must_fail git tag -u author@example.com \
763 -m "Another message" o-signed-tag
767 test_expect_success GPG 'sign with an unknown id (2)' '
769 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
773 cat >fakeeditor <<'EOF'
774 #!/bin/sh
775 test -n "$1" && exec >"$1"
776 echo A signed tag message
777 echo from a fake editor.
779 chmod +x fakeeditor
781 get_tag_header implied-sign $commit commit $time >expect
782 ./fakeeditor >>expect
783 echo '-----BEGIN PGP SIGNATURE-----' >>expect
784 test_expect_success GPG '-u implies signed tag' '
785 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
786 get_tag_msg implied-sign >actual &&
787 test_cmp expect actual
790 cat >sigmsgfile <<EOF
791 Another signed tag
792 message in a file.
794 get_tag_header file-signed-tag $commit commit $time >expect
795 cat sigmsgfile >>expect
796 echo '-----BEGIN PGP SIGNATURE-----' >>expect
797 test_expect_success GPG \
798 'creating a signed tag with -F messagefile should succeed' '
799 git tag -s -F sigmsgfile file-signed-tag &&
800 get_tag_msg file-signed-tag >actual &&
801 test_cmp expect actual
804 cat >siginputmsg <<EOF
805 A signed tag message from
806 the standard input
808 get_tag_header stdin-signed-tag $commit commit $time >expect
809 cat siginputmsg >>expect
810 echo '-----BEGIN PGP SIGNATURE-----' >>expect
811 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
812 git tag -s -F - stdin-signed-tag <siginputmsg &&
813 get_tag_msg stdin-signed-tag >actual &&
814 test_cmp expect actual
817 get_tag_header implied-annotate $commit commit $time >expect
818 ./fakeeditor >>expect
819 echo '-----BEGIN PGP SIGNATURE-----' >>expect
820 test_expect_success GPG '-s implies annotated tag' '
821 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
822 get_tag_msg implied-annotate >actual &&
823 test_cmp expect actual
826 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
827 echo "A message" >>expect
828 echo '-----BEGIN PGP SIGNATURE-----' >>expect
829 test_expect_success GPG \
830 'git tag -s implied if configured with tag.forcesignannotated' \
831 'test_config tag.forcesignannotated true &&
832 git tag -m "A message" forcesignannotated-implied-sign &&
833 get_tag_msg forcesignannotated-implied-sign >actual &&
834 test_cmp expect actual
837 test_expect_success GPG \
838 'lightweight with no message when configured with tag.forcesignannotated' \
839 'test_config tag.forcesignannotated true &&
840 git tag forcesignannotated-lightweight &&
841 tag_exists forcesignannotated-lightweight &&
842 test_must_fail git tag -v forcesignannotated-no-message
845 get_tag_header forcesignannotated-annotate $commit commit $time >expect
846 echo "A message" >>expect
847 test_expect_success GPG \
848 'git tag -a disable configured tag.forcesignannotated' \
849 'test_config tag.forcesignannotated true &&
850 git tag -a -m "A message" forcesignannotated-annotate &&
851 get_tag_msg forcesignannotated-annotate >actual &&
852 test_cmp expect actual &&
853 test_must_fail git tag -v forcesignannotated-annotate
856 get_tag_header forcesignannotated-disabled $commit commit $time >expect
857 echo "A message" >>expect
858 echo '-----BEGIN PGP SIGNATURE-----' >>expect
859 test_expect_success GPG \
860 'git tag --sign enable GPG sign' \
861 'test_config tag.forcesignannotated false &&
862 git tag --sign -m "A message" forcesignannotated-disabled &&
863 get_tag_msg forcesignannotated-disabled >actual &&
864 test_cmp expect actual
867 test_expect_success GPG \
868 'trying to create a signed tag with non-existing -F file should fail' '
869 ! test -f nonexistingfile &&
870 ! tag_exists nosigtag &&
871 test_must_fail git tag -s -F nonexistingfile nosigtag &&
872 ! tag_exists nosigtag
875 test_expect_success GPG 'verifying a signed tag should succeed' \
876 'git tag -v signed-tag'
878 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
879 'git tag -v signed-tag file-signed-tag'
881 test_expect_success GPG \
882 'verifying many signed and non-signed tags should fail' '
883 test_must_fail git tag -v signed-tag annotated-tag &&
884 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
885 test_must_fail git tag -v annotated-tag \
886 file-signed-tag file-annotated-tag &&
887 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
890 test_expect_success GPG 'verifying a forged tag should fail' '
891 forged=$(git cat-file tag signed-tag |
892 sed -e "s/signed-tag/forged-tag/" |
893 git mktag) &&
894 git tag forged-tag $forged &&
895 test_must_fail git tag -v forged-tag
898 test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
899 cat >expect <<-\EOF
900 tagname : signed-tag
901 EOF &&
902 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
903 test_cmp expect actual
906 test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
907 cat >expect <<-\EOF
908 tagname : forged-tag
909 EOF &&
910 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
911 test_cmp expect actual
914 # blank and empty messages for signed tags:
916 get_tag_header empty-signed-tag $commit commit $time >expect
917 echo '-----BEGIN PGP SIGNATURE-----' >>expect
918 test_expect_success GPG \
919 'creating a signed tag with an empty -m message should succeed' '
920 git tag -s -m "" empty-signed-tag &&
921 get_tag_msg empty-signed-tag >actual &&
922 test_cmp expect actual &&
923 git tag -v empty-signed-tag
926 >sigemptyfile
927 get_tag_header emptyfile-signed-tag $commit commit $time >expect
928 echo '-----BEGIN PGP SIGNATURE-----' >>expect
929 test_expect_success GPG \
930 'creating a signed tag with an empty -F messagefile should succeed' '
931 git tag -s -F sigemptyfile emptyfile-signed-tag &&
932 get_tag_msg emptyfile-signed-tag >actual &&
933 test_cmp expect actual &&
934 git tag -v emptyfile-signed-tag
937 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
938 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
939 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
940 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
941 get_tag_header blanks-signed-tag $commit commit $time >expect
942 cat >>expect <<EOF
943 Leading blank lines
945 Repeated blank lines
947 Trailing spaces
949 Trailing blank lines
951 echo '-----BEGIN PGP SIGNATURE-----' >>expect
952 test_expect_success GPG \
953 'extra blanks in the message for a signed tag should be removed' '
954 git tag -s -F sigblanksfile blanks-signed-tag &&
955 get_tag_msg blanks-signed-tag >actual &&
956 test_cmp expect actual &&
957 git tag -v blanks-signed-tag
960 get_tag_header blank-signed-tag $commit commit $time >expect
961 echo '-----BEGIN PGP SIGNATURE-----' >>expect
962 test_expect_success GPG \
963 'creating a signed tag with a blank -m message should succeed' '
964 git tag -s -m " " blank-signed-tag &&
965 get_tag_msg blank-signed-tag >actual &&
966 test_cmp expect actual &&
967 git tag -v blank-signed-tag
970 echo ' ' >sigblankfile
971 echo '' >>sigblankfile
972 echo ' ' >>sigblankfile
973 get_tag_header blankfile-signed-tag $commit commit $time >expect
974 echo '-----BEGIN PGP SIGNATURE-----' >>expect
975 test_expect_success GPG \
976 'creating a signed tag with blank -F file with spaces should succeed' '
977 git tag -s -F sigblankfile blankfile-signed-tag &&
978 get_tag_msg blankfile-signed-tag >actual &&
979 test_cmp expect actual &&
980 git tag -v blankfile-signed-tag
983 printf ' ' >sigblanknonlfile
984 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
985 echo '-----BEGIN PGP SIGNATURE-----' >>expect
986 test_expect_success GPG \
987 'creating a signed tag with spaces and no newline should succeed' '
988 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
989 get_tag_msg blanknonlfile-signed-tag >actual &&
990 test_cmp expect actual &&
991 git tag -v signed-tag
994 # messages with commented lines for signed tags:
996 cat >sigcommentsfile <<EOF
997 # A comment
999 ############
1000 The message.
1001 ############
1002 One line.
1005 # commented lines
1006 # commented lines
1008 Another line.
1009 # comments
1011 Last line.
1013 get_tag_header comments-signed-tag $commit commit $time >expect
1014 cat >>expect <<EOF
1015 The message.
1016 One line.
1018 Another line.
1020 Last line.
1022 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1023 test_expect_success GPG \
1024 'creating a signed tag with a -F file with #comments should succeed' '
1025 git tag -s -F sigcommentsfile comments-signed-tag &&
1026 get_tag_msg comments-signed-tag >actual &&
1027 test_cmp expect actual &&
1028 git tag -v comments-signed-tag
1031 get_tag_header comment-signed-tag $commit commit $time >expect
1032 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1033 test_expect_success GPG \
1034 'creating a signed tag with #commented -m message should succeed' '
1035 git tag -s -m "#comment" comment-signed-tag &&
1036 get_tag_msg comment-signed-tag >actual &&
1037 test_cmp expect actual &&
1038 git tag -v comment-signed-tag
1041 echo '#comment' >sigcommentfile
1042 echo '' >>sigcommentfile
1043 echo '####' >>sigcommentfile
1044 get_tag_header commentfile-signed-tag $commit commit $time >expect
1045 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1046 test_expect_success GPG \
1047 'creating a signed tag with #commented -F messagefile should succeed' '
1048 git tag -s -F sigcommentfile commentfile-signed-tag &&
1049 get_tag_msg commentfile-signed-tag >actual &&
1050 test_cmp expect actual &&
1051 git tag -v commentfile-signed-tag
1054 printf '#comment' >sigcommentnonlfile
1055 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1056 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1057 test_expect_success GPG \
1058 'creating a signed tag with a #comment and no newline should succeed' '
1059 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1060 get_tag_msg commentnonlfile-signed-tag >actual &&
1061 test_cmp expect actual &&
1062 git tag -v commentnonlfile-signed-tag
1065 # listing messages for signed tags:
1067 test_expect_success GPG \
1068 'listing the one-line message of a signed tag should succeed' '
1069 git tag -s -m "A message line signed" stag-one-line &&
1071 echo "stag-one-line" >expect &&
1072 git tag -l | grep "^stag-one-line" >actual &&
1073 test_cmp expect actual &&
1074 git tag -n0 -l | grep "^stag-one-line" >actual &&
1075 test_cmp expect actual &&
1076 git tag -n0 -l stag-one-line >actual &&
1077 test_cmp expect actual &&
1079 echo "stag-one-line A message line signed" >expect &&
1080 git tag -n1 -l | grep "^stag-one-line" >actual &&
1081 test_cmp expect actual &&
1082 git tag -n -l | grep "^stag-one-line" >actual &&
1083 test_cmp expect actual &&
1084 git tag -n1 -l stag-one-line >actual &&
1085 test_cmp expect actual &&
1086 git tag -n2 -l stag-one-line >actual &&
1087 test_cmp expect actual &&
1088 git tag -n999 -l stag-one-line >actual &&
1089 test_cmp expect actual
1092 test_expect_success GPG \
1093 'listing the zero-lines message of a signed tag should succeed' '
1094 git tag -s -m "" stag-zero-lines &&
1096 echo "stag-zero-lines" >expect &&
1097 git tag -l | grep "^stag-zero-lines" >actual &&
1098 test_cmp expect actual &&
1099 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1100 test_cmp expect actual &&
1101 git tag -n0 -l stag-zero-lines >actual &&
1102 test_cmp expect actual &&
1104 echo "stag-zero-lines " >expect &&
1105 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1106 test_cmp expect actual &&
1107 git tag -n -l | grep "^stag-zero-lines" >actual &&
1108 test_cmp expect actual &&
1109 git tag -n1 -l stag-zero-lines >actual &&
1110 test_cmp expect actual &&
1111 git tag -n2 -l stag-zero-lines >actual &&
1112 test_cmp expect actual &&
1113 git tag -n999 -l stag-zero-lines >actual &&
1114 test_cmp expect actual
1117 echo 'stag line one' >sigtagmsg
1118 echo 'stag line two' >>sigtagmsg
1119 echo 'stag line three' >>sigtagmsg
1120 test_expect_success GPG \
1121 'listing many message lines of a signed tag should succeed' '
1122 git tag -s -F sigtagmsg stag-lines &&
1124 echo "stag-lines" >expect &&
1125 git tag -l | grep "^stag-lines" >actual &&
1126 test_cmp expect actual &&
1127 git tag -n0 -l | grep "^stag-lines" >actual &&
1128 test_cmp expect actual &&
1129 git tag -n0 -l stag-lines >actual &&
1130 test_cmp expect actual &&
1132 echo "stag-lines stag line one" >expect &&
1133 git tag -n1 -l | grep "^stag-lines" >actual &&
1134 test_cmp expect actual &&
1135 git tag -n -l | grep "^stag-lines" >actual &&
1136 test_cmp expect actual &&
1137 git tag -n1 -l stag-lines >actual &&
1138 test_cmp expect actual &&
1140 echo " stag line two" >>expect &&
1141 git tag -n2 -l | grep "^ *stag.line" >actual &&
1142 test_cmp expect actual &&
1143 git tag -n2 -l stag-lines >actual &&
1144 test_cmp expect actual &&
1146 echo " stag line three" >>expect &&
1147 git tag -n3 -l | grep "^ *stag.line" >actual &&
1148 test_cmp expect actual &&
1149 git tag -n3 -l stag-lines >actual &&
1150 test_cmp expect actual &&
1151 git tag -n4 -l | grep "^ *stag.line" >actual &&
1152 test_cmp expect actual &&
1153 git tag -n4 -l stag-lines >actual &&
1154 test_cmp expect actual &&
1155 git tag -n99 -l | grep "^ *stag.line" >actual &&
1156 test_cmp expect actual &&
1157 git tag -n99 -l stag-lines >actual &&
1158 test_cmp expect actual
1161 # tags pointing to objects different from commits:
1163 tree=$(git rev-parse HEAD^{tree})
1164 blob=$(git rev-parse HEAD:foo)
1165 tag=$(git rev-parse signed-tag 2>/dev/null)
1167 get_tag_header tree-signed-tag $tree tree $time >expect
1168 echo "A message for a tree" >>expect
1169 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1170 test_expect_success GPG \
1171 'creating a signed tag pointing to a tree should succeed' '
1172 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1173 get_tag_msg tree-signed-tag >actual &&
1174 test_cmp expect actual
1177 get_tag_header blob-signed-tag $blob blob $time >expect
1178 echo "A message for a blob" >>expect
1179 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1180 test_expect_success GPG \
1181 'creating a signed tag pointing to a blob should succeed' '
1182 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1183 get_tag_msg blob-signed-tag >actual &&
1184 test_cmp expect actual
1187 get_tag_header tag-signed-tag $tag tag $time >expect
1188 echo "A message for another tag" >>expect
1189 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1190 test_expect_success GPG \
1191 'creating a signed tag pointing to another tag should succeed' '
1192 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1193 get_tag_msg tag-signed-tag >actual &&
1194 test_cmp expect actual
1197 # usage with rfc1991 signatures
1198 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1199 echo "RFC1991 signed tag" >>expect
1200 echo '-----BEGIN PGP MESSAGE-----' >>expect
1201 test_expect_success GPG,RFC1991 \
1202 'creating a signed tag with rfc1991' '
1203 echo "rfc1991" >gpghome/gpg.conf &&
1204 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1205 get_tag_msg rfc1991-signed-tag >actual &&
1206 test_cmp expect actual
1209 cat >fakeeditor <<'EOF'
1210 #!/bin/sh
1211 cp "$1" actual
1213 chmod +x fakeeditor
1215 test_expect_success GPG,RFC1991 \
1216 'reediting a signed tag body omits signature' '
1217 echo "rfc1991" >gpghome/gpg.conf &&
1218 echo "RFC1991 signed tag" >expect &&
1219 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1220 test_cmp expect actual
1223 test_expect_success GPG,RFC1991 \
1224 'verifying rfc1991 signature' '
1225 echo "rfc1991" >gpghome/gpg.conf &&
1226 git tag -v rfc1991-signed-tag
1229 test_expect_success GPG,RFC1991 \
1230 'list tag with rfc1991 signature' '
1231 echo "rfc1991" >gpghome/gpg.conf &&
1232 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1233 git tag -l -n1 rfc1991-signed-tag >actual &&
1234 test_cmp expect actual &&
1235 git tag -l -n2 rfc1991-signed-tag >actual &&
1236 test_cmp expect actual &&
1237 git tag -l -n999 rfc1991-signed-tag >actual &&
1238 test_cmp expect actual
1241 rm -f gpghome/gpg.conf
1243 test_expect_success GPG,RFC1991 \
1244 'verifying rfc1991 signature without --rfc1991' '
1245 git tag -v rfc1991-signed-tag
1248 test_expect_success GPG,RFC1991 \
1249 'list tag with rfc1991 signature without --rfc1991' '
1250 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1251 git tag -l -n1 rfc1991-signed-tag >actual &&
1252 test_cmp expect actual &&
1253 git tag -l -n2 rfc1991-signed-tag >actual &&
1254 test_cmp expect actual &&
1255 git tag -l -n999 rfc1991-signed-tag >actual &&
1256 test_cmp expect actual
1259 test_expect_success GPG,RFC1991 \
1260 'reediting a signed tag body omits signature' '
1261 echo "RFC1991 signed tag" >expect &&
1262 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1263 test_cmp expect actual
1266 # try to sign with bad user.signingkey
1267 test_expect_success GPG \
1268 'git tag -s fails if gpg is misconfigured (bad key)' \
1269 'test_config user.signingkey BobTheMouse &&
1270 test_must_fail git tag -s -m tail tag-gpg-failure'
1272 # try to produce invalid signature
1273 test_expect_success GPG \
1274 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1275 'test_config gpg.program echo &&
1276 test_must_fail git tag -s -m tail tag-gpg-failure'
1279 # try to verify without gpg:
1281 rm -rf gpghome
1282 test_expect_success GPG \
1283 'verify signed tag fails when public key is not present' \
1284 'test_must_fail git tag -v signed-tag'
1286 test_expect_success \
1287 'git tag -a fails if tag annotation is empty' '
1288 ! (GIT_EDITOR=cat git tag -a initial-comment)
1291 test_expect_success \
1292 'message in editor has initial comment' '
1293 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1296 test_expect_success 'message in editor has initial comment: first line' '
1297 # check the first line --- should be empty
1298 echo >first.expect &&
1299 sed -e 1q <actual >first.actual &&
1300 test_i18ncmp first.expect first.actual
1303 test_expect_success \
1304 'message in editor has initial comment: remainder' '
1305 # remove commented lines from the remainder -- should be empty
1306 >rest.expect &&
1307 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1308 test_cmp rest.expect rest.actual
1311 get_tag_header reuse $commit commit $time >expect
1312 echo "An annotation to be reused" >> expect
1313 test_expect_success \
1314 'overwriting an annoted tag should use its previous body' '
1315 git tag -a -m "An annotation to be reused" reuse &&
1316 GIT_EDITOR=true git tag -f -a reuse &&
1317 get_tag_msg reuse >actual &&
1318 test_cmp expect actual
1321 test_expect_success 'filename for the message is relative to cwd' '
1322 mkdir subdir &&
1323 echo "Tag message in top directory" >msgfile-5 &&
1324 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1326 cd subdir &&
1327 git tag -a -F msgfile-5 tag-from-subdir
1328 ) &&
1329 git cat-file tag tag-from-subdir | grep "in sub directory"
1332 test_expect_success 'filename for the message is relative to cwd' '
1333 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1335 cd subdir &&
1336 git tag -a -F msgfile-6 tag-from-subdir-2
1337 ) &&
1338 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1341 # create a few more commits to test --contains
1343 hash1=$(git rev-parse HEAD)
1345 test_expect_success 'creating second commit and tag' '
1346 echo foo-2.0 >foo &&
1347 git add foo &&
1348 git commit -m second &&
1349 git tag v2.0
1352 hash2=$(git rev-parse HEAD)
1354 test_expect_success 'creating third commit without tag' '
1355 echo foo-dev >foo &&
1356 git add foo &&
1357 git commit -m third
1360 hash3=$(git rev-parse HEAD)
1362 # simple linear checks of --continue
1364 cat > expected <<EOF
1365 v0.2.1
1366 v1.0
1367 v1.0.1
1368 v1.1.3
1369 v2.0
1372 test_expect_success 'checking that first commit is in all tags (hash)' "
1373 git tag -l --contains $hash1 v* >actual &&
1374 test_cmp expected actual
1377 # other ways of specifying the commit
1378 test_expect_success 'checking that first commit is in all tags (tag)' "
1379 git tag -l --contains v1.0 v* >actual &&
1380 test_cmp expected actual
1383 test_expect_success 'checking that first commit is in all tags (relative)' "
1384 git tag -l --contains HEAD~2 v* >actual &&
1385 test_cmp expected actual
1388 cat > expected <<EOF
1389 v2.0
1392 test_expect_success 'checking that second commit only has one tag' "
1393 git tag -l --contains $hash2 v* >actual &&
1394 test_cmp expected actual
1398 cat > expected <<EOF
1401 test_expect_success 'checking that third commit has no tags' "
1402 git tag -l --contains $hash3 v* >actual &&
1403 test_cmp expected actual
1406 # how about a simple merge?
1408 test_expect_success 'creating simple branch' '
1409 git branch stable v2.0 &&
1410 git checkout stable &&
1411 echo foo-3.0 > foo &&
1412 git commit foo -m fourth &&
1413 git tag v3.0
1416 hash4=$(git rev-parse HEAD)
1418 cat > expected <<EOF
1419 v3.0
1422 test_expect_success 'checking that branch head only has one tag' "
1423 git tag -l --contains $hash4 v* >actual &&
1424 test_cmp expected actual
1427 test_expect_success 'merging original branch into this branch' '
1428 git merge --strategy=ours master &&
1429 git tag v4.0
1432 cat > expected <<EOF
1433 v4.0
1436 test_expect_success 'checking that original branch head has one tag now' "
1437 git tag -l --contains $hash3 v* >actual &&
1438 test_cmp expected actual
1441 cat > expected <<EOF
1442 v0.2.1
1443 v1.0
1444 v1.0.1
1445 v1.1.3
1446 v2.0
1447 v3.0
1448 v4.0
1451 test_expect_success 'checking that initial commit is in all tags' "
1452 git tag -l --contains $hash1 v* >actual &&
1453 test_cmp expected actual
1456 # mixing modes and options:
1458 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1459 test_must_fail git tag -a &&
1460 test_must_fail git tag -l -v &&
1461 test_must_fail git tag -n 100 &&
1462 test_must_fail git tag -l -m msg &&
1463 test_must_fail git tag -l -F some file &&
1464 test_must_fail git tag -v -s
1467 # check points-at
1469 test_expect_success '--points-at cannot be used in non-list mode' '
1470 test_must_fail git tag --points-at=v4.0 foo
1473 test_expect_success '--points-at finds lightweight tags' '
1474 echo v4.0 >expect &&
1475 git tag --points-at v4.0 >actual &&
1476 test_cmp expect actual
1479 test_expect_success '--points-at finds annotated tags of commits' '
1480 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1481 echo annotated-v4.0 >expect &&
1482 git tag -l --points-at v4.0 "annotated*" >actual &&
1483 test_cmp expect actual
1486 test_expect_success '--points-at finds annotated tags of tags' '
1487 git tag -m "describing the v4.0 tag object" \
1488 annotated-again-v4.0 annotated-v4.0 &&
1489 cat >expect <<-\EOF &&
1490 annotated-again-v4.0
1491 annotated-v4.0
1493 git tag --points-at=annotated-v4.0 >actual &&
1494 test_cmp expect actual
1497 test_expect_success 'multiple --points-at are OR-ed together' '
1498 cat >expect <<-\EOF &&
1499 v2.0
1500 v3.0
1502 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1503 test_cmp expect actual
1506 test_expect_success 'lexical sort' '
1507 git tag foo1.3 &&
1508 git tag foo1.6 &&
1509 git tag foo1.10 &&
1510 git tag -l --sort=refname "foo*" >actual &&
1511 cat >expect <<-\EOF &&
1512 foo1.10
1513 foo1.3
1514 foo1.6
1516 test_cmp expect actual
1519 test_expect_success 'version sort' '
1520 git tag -l --sort=version:refname "foo*" >actual &&
1521 cat >expect <<-\EOF &&
1522 foo1.3
1523 foo1.6
1524 foo1.10
1526 test_cmp expect actual
1529 test_expect_success 'reverse version sort' '
1530 git tag -l --sort=-version:refname "foo*" >actual &&
1531 cat >expect <<-\EOF &&
1532 foo1.10
1533 foo1.6
1534 foo1.3
1536 test_cmp expect actual
1539 test_expect_success 'reverse lexical sort' '
1540 git tag -l --sort=-refname "foo*" >actual &&
1541 cat >expect <<-\EOF &&
1542 foo1.6
1543 foo1.3
1544 foo1.10
1546 test_cmp expect actual
1549 test_expect_success 'configured lexical sort' '
1550 test_config tag.sort "v:refname" &&
1551 git tag -l "foo*" >actual &&
1552 cat >expect <<-\EOF &&
1553 foo1.3
1554 foo1.6
1555 foo1.10
1557 test_cmp expect actual
1560 test_expect_success 'option override configured sort' '
1561 test_config tag.sort "v:refname" &&
1562 git tag -l --sort=-refname "foo*" >actual &&
1563 cat >expect <<-\EOF &&
1564 foo1.6
1565 foo1.3
1566 foo1.10
1568 test_cmp expect actual
1571 test_expect_success 'invalid sort parameter on command line' '
1572 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1575 test_expect_success 'invalid sort parameter in configuratoin' '
1576 test_config tag.sort "v:notvalid" &&
1577 test_must_fail git tag -l "foo*"
1580 test_expect_success 'version sort with prerelease reordering' '
1581 test_config versionsort.prereleaseSuffix -rc &&
1582 git tag foo1.6-rc1 &&
1583 git tag foo1.6-rc2 &&
1584 git tag -l --sort=version:refname "foo*" >actual &&
1585 cat >expect <<-\EOF &&
1586 foo1.3
1587 foo1.6-rc1
1588 foo1.6-rc2
1589 foo1.6
1590 foo1.10
1592 test_cmp expect actual
1595 test_expect_success 'reverse version sort with prerelease reordering' '
1596 test_config versionsort.prereleaseSuffix -rc &&
1597 git tag -l --sort=-version:refname "foo*" >actual &&
1598 cat >expect <<-\EOF &&
1599 foo1.10
1600 foo1.6
1601 foo1.6-rc2
1602 foo1.6-rc1
1603 foo1.3
1605 test_cmp expect actual
1608 test_expect_success 'version sort with prerelease reordering and common leading character' '
1609 test_config versionsort.prereleaseSuffix -before &&
1610 git tag foo1.7-before1 &&
1611 git tag foo1.7 &&
1612 git tag foo1.7-after1 &&
1613 git tag -l --sort=version:refname "foo1.7*" >actual &&
1614 cat >expect <<-\EOF &&
1615 foo1.7-before1
1616 foo1.7
1617 foo1.7-after1
1619 test_cmp expect actual
1622 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1623 test_config versionsort.prereleaseSuffix -before &&
1624 git config --add versionsort.prereleaseSuffix -after &&
1625 git tag -l --sort=version:refname "foo1.7*" >actual &&
1626 cat >expect <<-\EOF &&
1627 foo1.7-before1
1628 foo1.7-after1
1629 foo1.7
1631 test_cmp expect actual
1634 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1635 test_config versionsort.prereleaseSuffix -bar &&
1636 git config --add versionsort.prereleaseSuffix -foo-baz &&
1637 git config --add versionsort.prereleaseSuffix -foo-bar &&
1638 git tag foo1.8-foo-bar &&
1639 git tag foo1.8-foo-baz &&
1640 git tag foo1.8 &&
1641 git tag -l --sort=version:refname "foo1.8*" >actual &&
1642 cat >expect <<-\EOF &&
1643 foo1.8-foo-baz
1644 foo1.8-foo-bar
1645 foo1.8
1647 test_cmp expect actual
1650 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1651 test_config versionsort.prereleaseSuffix -pre &&
1652 git config --add versionsort.prereleaseSuffix -prerelease &&
1653 git tag foo1.9-pre1 &&
1654 git tag foo1.9-pre2 &&
1655 git tag foo1.9-prerelease1 &&
1656 git tag -l --sort=version:refname "foo1.9*" >actual &&
1657 cat >expect <<-\EOF &&
1658 foo1.9-pre1
1659 foo1.9-pre2
1660 foo1.9-prerelease1
1662 test_cmp expect actual
1665 test_expect_success 'version sort with general suffix reordering' '
1666 test_config versionsort.suffix -alpha &&
1667 git config --add versionsort.suffix -beta &&
1668 git config --add versionsort.suffix "" &&
1669 git config --add versionsort.suffix -gamma &&
1670 git config --add versionsort.suffix -delta &&
1671 git tag foo1.10-alpha &&
1672 git tag foo1.10-beta &&
1673 git tag foo1.10-gamma &&
1674 git tag foo1.10-delta &&
1675 git tag foo1.10-unlisted-suffix &&
1676 git tag -l --sort=version:refname "foo1.10*" >actual &&
1677 cat >expect <<-\EOF &&
1678 foo1.10-alpha
1679 foo1.10-beta
1680 foo1.10
1681 foo1.10-unlisted-suffix
1682 foo1.10-gamma
1683 foo1.10-delta
1685 test_cmp expect actual
1688 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1689 test_config versionsort.suffix -before &&
1690 test_config versionsort.prereleaseSuffix -after &&
1691 git tag -l --sort=version:refname "foo1.7*" >actual &&
1692 cat >expect <<-\EOF &&
1693 foo1.7-before1
1694 foo1.7
1695 foo1.7-after1
1697 test_cmp expect actual
1700 test_expect_success 'version sort with very long prerelease suffix' '
1701 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1702 git tag -l --sort=version:refname
1705 run_with_limited_stack () {
1706 (ulimit -s 128 && "$@")
1709 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1711 # we require ulimit, this excludes Windows
1712 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1713 >expect &&
1714 i=1 &&
1715 while test $i -lt 8000
1717 echo "commit refs/heads/master
1718 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1719 data <<EOF
1720 commit #$i
1721 EOF"
1722 test $i = 1 && echo "from refs/heads/master^0"
1723 i=$(($i + 1))
1724 done | git fast-import &&
1725 git checkout master &&
1726 git tag far-far-away HEAD^ &&
1727 run_with_limited_stack git tag --contains HEAD >actual &&
1728 test_cmp expect actual
1731 test_expect_success '--format should list tags as per format given' '
1732 cat >expect <<-\EOF &&
1733 refname : refs/tags/v1.0
1734 refname : refs/tags/v1.0.1
1735 refname : refs/tags/v1.1.3
1737 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1738 test_cmp expect actual
1741 test_expect_success 'setup --merged test tags' '
1742 git tag mergetest-1 HEAD~2 &&
1743 git tag mergetest-2 HEAD~1 &&
1744 git tag mergetest-3 HEAD
1747 test_expect_success '--merged cannot be used in non-list mode' '
1748 test_must_fail git tag --merged=mergetest-2 foo
1751 test_expect_success '--merged shows merged tags' '
1752 cat >expect <<-\EOF &&
1753 mergetest-1
1754 mergetest-2
1756 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1757 test_cmp expect actual
1760 test_expect_success '--no-merged show unmerged tags' '
1761 cat >expect <<-\EOF &&
1762 mergetest-3
1764 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1765 test_cmp expect actual
1768 test_expect_success 'ambiguous branch/tags not marked' '
1769 git tag ambiguous &&
1770 git branch ambiguous &&
1771 echo ambiguous >expect &&
1772 git tag -l ambiguous >actual &&
1773 test_cmp expect actual
1776 test_done