Seventh batch for 2.12
[git.git] / t / t7004-tag.sh
blob1cfa8a21d23173e51e95906c00342fa13b85d955
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_tick &&
75 echo foo >foo &&
76 git add foo &&
77 git commit -m Foo &&
78 git tag mytag &&
79 test_must_fail git reflog exists refs/tags/mytag
82 test_expect_success 'creating a tag with --create-reflog should create reflog' '
83 test_when_finished "git tag -d tag_with_reflog" &&
84 git tag --create-reflog tag_with_reflog &&
85 git reflog exists refs/tags/tag_with_reflog
88 test_expect_success '--create-reflog does not create reflog on failure' '
89 test_must_fail git tag --create-reflog mytag &&
90 test_must_fail git reflog exists refs/tags/mytag
93 test_expect_success 'listing all tags if one exists should succeed' '
94 git tag -l &&
95 git tag
98 test_expect_success 'listing all tags if one exists should output that tag' '
99 test $(git tag -l) = mytag &&
100 test $(git tag) = mytag
103 # pattern matching:
105 test_expect_success 'listing a tag using a matching pattern should succeed' \
106 'git tag -l mytag'
108 test_expect_success 'listing a tag with --ignore-case' \
109 'test $(git tag -l --ignore-case MYTAG) = mytag'
111 test_expect_success \
112 'listing a tag using a matching pattern should output that tag' \
113 'test $(git tag -l mytag) = mytag'
115 # todo: git tag -l now returns always zero, when fixed, change this test
116 test_expect_success \
117 'listing tags using a non-matching pattern should suceed' \
118 'git tag -l xxx'
120 test_expect_success \
121 'listing tags using a non-matching pattern should output nothing' \
122 'test $(git tag -l xxx | wc -l) -eq 0'
124 # special cases for creating tags:
126 test_expect_success \
127 'trying to create a tag with the name of one existing should fail' \
128 'test_must_fail git tag mytag'
130 test_expect_success \
131 'trying to create a tag with a non-valid name should fail' '
132 test $(git tag -l | wc -l) -eq 1 &&
133 test_must_fail git tag "" &&
134 test_must_fail git tag .othertag &&
135 test_must_fail git tag "other tag" &&
136 test_must_fail git tag "othertag^" &&
137 test_must_fail git tag "other~tag" &&
138 test $(git tag -l | wc -l) -eq 1
141 test_expect_success 'creating a tag using HEAD directly should succeed' '
142 git tag myhead HEAD &&
143 tag_exists myhead
146 test_expect_success '--force can create a tag with the name of one existing' '
147 tag_exists mytag &&
148 git tag --force mytag &&
149 tag_exists mytag'
151 test_expect_success '--force is moot with a non-existing tag name' '
152 test_when_finished git tag -d newtag forcetag &&
153 git tag newtag >expect &&
154 git tag --force forcetag >actual &&
155 test_cmp expect actual
158 # deleting tags:
160 test_expect_success 'trying to delete an unknown tag should fail' '
161 ! tag_exists unknown-tag &&
162 test_must_fail git tag -d unknown-tag
165 cat >expect <<EOF
166 myhead
167 mytag
169 test_expect_success \
170 'trying to delete tags without params should succeed and do nothing' '
171 git tag -l > actual && test_cmp expect actual &&
172 git tag -d &&
173 git tag -l > actual && test_cmp expect actual
176 test_expect_success \
177 'deleting two existing tags in one command should succeed' '
178 tag_exists mytag &&
179 tag_exists myhead &&
180 git tag -d mytag myhead &&
181 ! tag_exists mytag &&
182 ! tag_exists myhead
185 test_expect_success \
186 'creating a tag with the name of another deleted one should succeed' '
187 ! tag_exists mytag &&
188 git tag mytag &&
189 tag_exists mytag
192 test_expect_success \
193 'trying to delete two tags, existing and not, should fail in the 2nd' '
194 tag_exists mytag &&
195 ! tag_exists myhead &&
196 test_must_fail git tag -d mytag anothertag &&
197 ! tag_exists mytag &&
198 ! tag_exists myhead
201 test_expect_success 'trying to delete an already deleted tag should fail' \
202 'test_must_fail git tag -d mytag'
204 # listing various tags with pattern matching:
206 cat >expect <<EOF
210 t210
211 t211
212 v0.2.1
213 v1.0
214 v1.0.1
215 v1.1.3
217 test_expect_success 'listing all tags should print them ordered' '
218 git tag v1.0.1 &&
219 git tag t211 &&
220 git tag aa1 &&
221 git tag v0.2.1 &&
222 git tag v1.1.3 &&
223 git tag cba &&
224 git tag a1 &&
225 git tag v1.0 &&
226 git tag t210 &&
227 git tag -l > actual &&
228 test_cmp expect actual &&
229 git tag > actual &&
230 test_cmp expect actual
233 cat >expect <<EOF
238 test_expect_success \
239 'listing tags with substring as pattern must print those matching' '
240 rm *a* &&
241 git tag -l "*a*" > current &&
242 test_cmp expect current
245 cat >expect <<EOF
246 v0.2.1
247 v1.0.1
249 test_expect_success \
250 'listing tags with a suffix as pattern must print those matching' '
251 git tag -l "*.1" > actual &&
252 test_cmp expect actual
255 cat >expect <<EOF
256 t210
257 t211
259 test_expect_success \
260 'listing tags with a prefix as pattern must print those matching' '
261 git tag -l "t21*" > actual &&
262 test_cmp expect actual
265 cat >expect <<EOF
268 test_expect_success \
269 'listing tags using a name as pattern must print that one matching' '
270 git tag -l a1 > actual &&
271 test_cmp expect actual
274 cat >expect <<EOF
275 v1.0
277 test_expect_success \
278 'listing tags using a name as pattern must print that one matching' '
279 git tag -l v1.0 > actual &&
280 test_cmp expect actual
283 cat >expect <<EOF
284 v1.0.1
285 v1.1.3
287 test_expect_success \
288 'listing tags with ? in the pattern should print those matching' '
289 git tag -l "v1.?.?" > actual &&
290 test_cmp expect actual
293 >expect
294 test_expect_success \
295 'listing tags using v.* should print nothing because none have v.' '
296 git tag -l "v.*" > actual &&
297 test_cmp expect actual
300 cat >expect <<EOF
301 v0.2.1
302 v1.0
303 v1.0.1
304 v1.1.3
306 test_expect_success \
307 'listing tags using v* should print only those having v' '
308 git tag -l "v*" > actual &&
309 test_cmp expect actual
312 test_expect_success 'tag -l can accept multiple patterns' '
313 git tag -l "v1*" "v0*" >actual &&
314 test_cmp expect actual
317 test_expect_success 'listing tags in column' '
318 COLUMNS=40 git tag -l --column=row >actual &&
319 cat >expected <<\EOF &&
320 a1 aa1 cba t210 t211
321 v0.2.1 v1.0 v1.0.1 v1.1.3
323 test_cmp expected actual
326 test_expect_success 'listing tags in column with column.*' '
327 test_config column.tag row &&
328 test_config column.ui dense &&
329 COLUMNS=40 git tag -l >actual &&
330 cat >expected <<\EOF &&
331 a1 aa1 cba t210 t211
332 v0.2.1 v1.0 v1.0.1 v1.1.3
334 test_cmp expected actual
337 test_expect_success 'listing tag with -n --column should fail' '
338 test_must_fail git tag --column -n
341 test_expect_success 'listing tags -n in column with column.ui ignored' '
342 test_config column.ui "row dense" &&
343 COLUMNS=40 git tag -l -n >actual &&
344 cat >expected <<\EOF &&
345 a1 Foo
346 aa1 Foo
347 cba Foo
348 t210 Foo
349 t211 Foo
350 v0.2.1 Foo
351 v1.0 Foo
352 v1.0.1 Foo
353 v1.1.3 Foo
355 test_cmp expected actual
358 # creating and verifying lightweight tags:
360 test_expect_success \
361 'a non-annotated tag created without parameters should point to HEAD' '
362 git tag non-annotated-tag &&
363 test $(git cat-file -t non-annotated-tag) = commit &&
364 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
367 test_expect_success 'trying to verify an unknown tag should fail' \
368 'test_must_fail git tag -v unknown-tag'
370 test_expect_success \
371 'trying to verify a non-annotated and non-signed tag should fail' \
372 'test_must_fail git tag -v non-annotated-tag'
374 test_expect_success \
375 'trying to verify many non-annotated or unknown tags, should fail' \
376 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
378 # creating annotated tags:
380 get_tag_msg () {
381 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
384 # run test_tick before committing always gives the time in that timezone
385 get_tag_header () {
386 cat <<EOF
387 object $2
388 type $3
389 tag $1
390 tagger C O Mitter <committer@example.com> $4 -0700
395 commit=$(git rev-parse HEAD)
396 time=$test_tick
398 get_tag_header annotated-tag $commit commit $time >expect
399 echo "A message" >>expect
400 test_expect_success \
401 'creating an annotated tag with -m message should succeed' '
402 git tag -m "A message" annotated-tag &&
403 get_tag_msg annotated-tag >actual &&
404 test_cmp expect actual
407 cat >msgfile <<EOF
408 Another message
409 in a file.
411 get_tag_header file-annotated-tag $commit commit $time >expect
412 cat msgfile >>expect
413 test_expect_success \
414 'creating an annotated tag with -F messagefile should succeed' '
415 git tag -F msgfile file-annotated-tag &&
416 get_tag_msg file-annotated-tag >actual &&
417 test_cmp expect actual
420 cat >inputmsg <<EOF
421 A message from the
422 standard input
424 get_tag_header stdin-annotated-tag $commit commit $time >expect
425 cat inputmsg >>expect
426 test_expect_success 'creating an annotated tag with -F - should succeed' '
427 git tag -F - stdin-annotated-tag <inputmsg &&
428 get_tag_msg stdin-annotated-tag >actual &&
429 test_cmp expect actual
432 test_expect_success \
433 'trying to create a tag with a non-existing -F file should fail' '
434 ! test -f nonexistingfile &&
435 ! tag_exists notag &&
436 test_must_fail git tag -F nonexistingfile notag &&
437 ! tag_exists notag
440 test_expect_success \
441 'trying to create tags giving both -m or -F options should fail' '
442 echo "message file 1" >msgfile1 &&
443 echo "message file 2" >msgfile2 &&
444 ! tag_exists msgtag &&
445 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
446 ! tag_exists msgtag &&
447 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
448 ! tag_exists msgtag &&
449 test_must_fail git tag -m "message 1" -F msgfile1 \
450 -m "message 2" msgtag &&
451 ! tag_exists msgtag
454 # blank and empty messages:
456 get_tag_header empty-annotated-tag $commit commit $time >expect
457 test_expect_success \
458 'creating a tag with an empty -m message should succeed' '
459 git tag -m "" empty-annotated-tag &&
460 get_tag_msg empty-annotated-tag >actual &&
461 test_cmp expect actual
464 >emptyfile
465 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
466 test_expect_success \
467 'creating a tag with an empty -F messagefile should succeed' '
468 git tag -F emptyfile emptyfile-annotated-tag &&
469 get_tag_msg emptyfile-annotated-tag >actual &&
470 test_cmp expect actual
473 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
474 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
475 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
476 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
477 get_tag_header blanks-annotated-tag $commit commit $time >expect
478 cat >>expect <<EOF
479 Leading blank lines
481 Repeated blank lines
483 Trailing spaces
485 Trailing blank lines
487 test_expect_success \
488 'extra blanks in the message for an annotated tag should be removed' '
489 git tag -F blanksfile blanks-annotated-tag &&
490 get_tag_msg blanks-annotated-tag >actual &&
491 test_cmp expect actual
494 get_tag_header blank-annotated-tag $commit commit $time >expect
495 test_expect_success \
496 'creating a tag with blank -m message with spaces should succeed' '
497 git tag -m " " blank-annotated-tag &&
498 get_tag_msg blank-annotated-tag >actual &&
499 test_cmp expect actual
502 echo ' ' >blankfile
503 echo '' >>blankfile
504 echo ' ' >>blankfile
505 get_tag_header blankfile-annotated-tag $commit commit $time >expect
506 test_expect_success \
507 'creating a tag with blank -F messagefile with spaces should succeed' '
508 git tag -F blankfile blankfile-annotated-tag &&
509 get_tag_msg blankfile-annotated-tag >actual &&
510 test_cmp expect actual
513 printf ' ' >blanknonlfile
514 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
515 test_expect_success \
516 'creating a tag with -F file of spaces and no newline should succeed' '
517 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
518 get_tag_msg blanknonlfile-annotated-tag >actual &&
519 test_cmp expect actual
522 # messages with commented lines:
524 cat >commentsfile <<EOF
525 # A comment
527 ############
528 The message.
529 ############
530 One line.
533 # commented lines
534 # commented lines
536 Another line.
537 # comments
539 Last line.
541 get_tag_header comments-annotated-tag $commit commit $time >expect
542 cat >>expect <<EOF
543 The message.
544 One line.
546 Another line.
548 Last line.
550 test_expect_success \
551 'creating a tag using a -F messagefile with #comments should succeed' '
552 git tag -F commentsfile comments-annotated-tag &&
553 get_tag_msg comments-annotated-tag >actual &&
554 test_cmp expect actual
557 get_tag_header comment-annotated-tag $commit commit $time >expect
558 test_expect_success \
559 'creating a tag with a #comment in the -m message should succeed' '
560 git tag -m "#comment" comment-annotated-tag &&
561 get_tag_msg comment-annotated-tag >actual &&
562 test_cmp expect actual
565 echo '#comment' >commentfile
566 echo '' >>commentfile
567 echo '####' >>commentfile
568 get_tag_header commentfile-annotated-tag $commit commit $time >expect
569 test_expect_success \
570 'creating a tag with #comments in the -F messagefile should succeed' '
571 git tag -F commentfile commentfile-annotated-tag &&
572 get_tag_msg commentfile-annotated-tag >actual &&
573 test_cmp expect actual
576 printf '#comment' >commentnonlfile
577 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
578 test_expect_success \
579 'creating a tag with a file of #comment and no newline should succeed' '
580 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
581 get_tag_msg commentnonlfile-annotated-tag >actual &&
582 test_cmp expect actual
585 # listing messages for annotated non-signed tags:
587 test_expect_success \
588 'listing the one-line message of a non-signed tag should succeed' '
589 git tag -m "A msg" tag-one-line &&
591 echo "tag-one-line" >expect &&
592 git tag -l | grep "^tag-one-line" >actual &&
593 test_cmp expect actual &&
594 git tag -n0 -l | grep "^tag-one-line" >actual &&
595 test_cmp expect actual &&
596 git tag -n0 -l tag-one-line >actual &&
597 test_cmp expect actual &&
599 echo "tag-one-line A msg" >expect &&
600 git tag -n1 -l | grep "^tag-one-line" >actual &&
601 test_cmp expect actual &&
602 git tag -n -l | grep "^tag-one-line" >actual &&
603 test_cmp expect actual &&
604 git tag -n1 -l tag-one-line >actual &&
605 test_cmp expect actual &&
606 git tag -n2 -l tag-one-line >actual &&
607 test_cmp expect actual &&
608 git tag -n999 -l tag-one-line >actual &&
609 test_cmp expect actual
612 test_expect_success \
613 'listing the zero-lines message of a non-signed tag should succeed' '
614 git tag -m "" tag-zero-lines &&
616 echo "tag-zero-lines" >expect &&
617 git tag -l | grep "^tag-zero-lines" >actual &&
618 test_cmp expect actual &&
619 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
620 test_cmp expect actual &&
621 git tag -n0 -l tag-zero-lines >actual &&
622 test_cmp expect actual &&
624 echo "tag-zero-lines " >expect &&
625 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
626 test_cmp expect actual &&
627 git tag -n -l | grep "^tag-zero-lines" >actual &&
628 test_cmp expect actual &&
629 git tag -n1 -l tag-zero-lines >actual &&
630 test_cmp expect actual &&
631 git tag -n2 -l tag-zero-lines >actual &&
632 test_cmp expect actual &&
633 git tag -n999 -l tag-zero-lines >actual &&
634 test_cmp expect actual
637 echo 'tag line one' >annotagmsg
638 echo 'tag line two' >>annotagmsg
639 echo 'tag line three' >>annotagmsg
640 test_expect_success \
641 'listing many message lines of a non-signed tag should succeed' '
642 git tag -F annotagmsg tag-lines &&
644 echo "tag-lines" >expect &&
645 git tag -l | grep "^tag-lines" >actual &&
646 test_cmp expect actual &&
647 git tag -n0 -l | grep "^tag-lines" >actual &&
648 test_cmp expect actual &&
649 git tag -n0 -l tag-lines >actual &&
650 test_cmp expect actual &&
652 echo "tag-lines tag line one" >expect &&
653 git tag -n1 -l | grep "^tag-lines" >actual &&
654 test_cmp expect actual &&
655 git tag -n -l | grep "^tag-lines" >actual &&
656 test_cmp expect actual &&
657 git tag -n1 -l tag-lines >actual &&
658 test_cmp expect actual &&
660 echo " tag line two" >>expect &&
661 git tag -n2 -l | grep "^ *tag.line" >actual &&
662 test_cmp expect actual &&
663 git tag -n2 -l tag-lines >actual &&
664 test_cmp expect actual &&
666 echo " tag line three" >>expect &&
667 git tag -n3 -l | grep "^ *tag.line" >actual &&
668 test_cmp expect actual &&
669 git tag -n3 -l tag-lines >actual &&
670 test_cmp expect actual &&
671 git tag -n4 -l | grep "^ *tag.line" >actual &&
672 test_cmp expect actual &&
673 git tag -n4 -l tag-lines >actual &&
674 test_cmp expect actual &&
675 git tag -n99 -l | grep "^ *tag.line" >actual &&
676 test_cmp expect actual &&
677 git tag -n99 -l tag-lines >actual &&
678 test_cmp expect actual
681 test_expect_success 'annotations for blobs are empty' '
682 blob=$(git hash-object -w --stdin <<-\EOF
683 Blob paragraph 1.
685 Blob paragraph 2.
687 ) &&
688 git tag tag-blob $blob &&
689 echo "tag-blob " >expect &&
690 git tag -n1 -l tag-blob >actual &&
691 test_cmp expect actual
694 # trying to verify annotated non-signed tags:
696 test_expect_success GPG \
697 'trying to verify an annotated non-signed tag should fail' '
698 tag_exists annotated-tag &&
699 test_must_fail git tag -v annotated-tag
702 test_expect_success GPG \
703 'trying to verify a file-annotated non-signed tag should fail' '
704 tag_exists file-annotated-tag &&
705 test_must_fail git tag -v file-annotated-tag
708 test_expect_success GPG \
709 'trying to verify two annotated non-signed tags should fail' '
710 tag_exists annotated-tag file-annotated-tag &&
711 test_must_fail git tag -v annotated-tag file-annotated-tag
714 # creating and verifying signed tags:
716 get_tag_header signed-tag $commit commit $time >expect
717 echo 'A signed tag message' >>expect
718 echo '-----BEGIN PGP SIGNATURE-----' >>expect
719 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
720 git tag -s -m "A signed tag message" signed-tag &&
721 get_tag_msg signed-tag >actual &&
722 test_cmp expect actual
725 get_tag_header u-signed-tag $commit commit $time >expect
726 echo 'Another message' >>expect
727 echo '-----BEGIN PGP SIGNATURE-----' >>expect
728 test_expect_success GPG 'sign with a given key id' '
730 git tag -u committer@example.com -m "Another message" u-signed-tag &&
731 get_tag_msg u-signed-tag >actual &&
732 test_cmp expect actual
736 test_expect_success GPG 'sign with an unknown id (1)' '
738 test_must_fail git tag -u author@example.com \
739 -m "Another message" o-signed-tag
743 test_expect_success GPG 'sign with an unknown id (2)' '
745 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
749 cat >fakeeditor <<'EOF'
750 #!/bin/sh
751 test -n "$1" && exec >"$1"
752 echo A signed tag message
753 echo from a fake editor.
755 chmod +x fakeeditor
757 get_tag_header implied-sign $commit commit $time >expect
758 ./fakeeditor >>expect
759 echo '-----BEGIN PGP SIGNATURE-----' >>expect
760 test_expect_success GPG '-u implies signed tag' '
761 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
762 get_tag_msg implied-sign >actual &&
763 test_cmp expect actual
766 cat >sigmsgfile <<EOF
767 Another signed tag
768 message in a file.
770 get_tag_header file-signed-tag $commit commit $time >expect
771 cat sigmsgfile >>expect
772 echo '-----BEGIN PGP SIGNATURE-----' >>expect
773 test_expect_success GPG \
774 'creating a signed tag with -F messagefile should succeed' '
775 git tag -s -F sigmsgfile file-signed-tag &&
776 get_tag_msg file-signed-tag >actual &&
777 test_cmp expect actual
780 cat >siginputmsg <<EOF
781 A signed tag message from
782 the standard input
784 get_tag_header stdin-signed-tag $commit commit $time >expect
785 cat siginputmsg >>expect
786 echo '-----BEGIN PGP SIGNATURE-----' >>expect
787 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
788 git tag -s -F - stdin-signed-tag <siginputmsg &&
789 get_tag_msg stdin-signed-tag >actual &&
790 test_cmp expect actual
793 get_tag_header implied-annotate $commit commit $time >expect
794 ./fakeeditor >>expect
795 echo '-----BEGIN PGP SIGNATURE-----' >>expect
796 test_expect_success GPG '-s implies annotated tag' '
797 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
798 get_tag_msg implied-annotate >actual &&
799 test_cmp expect actual
802 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
803 echo "A message" >>expect
804 echo '-----BEGIN PGP SIGNATURE-----' >>expect
805 test_expect_success GPG \
806 'git tag -s implied if configured with tag.forcesignannotated' \
807 'test_config tag.forcesignannotated true &&
808 git tag -m "A message" forcesignannotated-implied-sign &&
809 get_tag_msg forcesignannotated-implied-sign >actual &&
810 test_cmp expect actual
813 test_expect_success GPG \
814 'lightweight with no message when configured with tag.forcesignannotated' \
815 'test_config tag.forcesignannotated true &&
816 git tag forcesignannotated-lightweight &&
817 tag_exists forcesignannotated-lightweight &&
818 test_must_fail git tag -v forcesignannotated-no-message
821 get_tag_header forcesignannotated-annotate $commit commit $time >expect
822 echo "A message" >>expect
823 test_expect_success GPG \
824 'git tag -a disable configured tag.forcesignannotated' \
825 'test_config tag.forcesignannotated true &&
826 git tag -a -m "A message" forcesignannotated-annotate &&
827 get_tag_msg forcesignannotated-annotate >actual &&
828 test_cmp expect actual &&
829 test_must_fail git tag -v forcesignannotated-annotate
832 get_tag_header forcesignannotated-disabled $commit commit $time >expect
833 echo "A message" >>expect
834 echo '-----BEGIN PGP SIGNATURE-----' >>expect
835 test_expect_success GPG \
836 'git tag --sign enable GPG sign' \
837 'test_config tag.forcesignannotated false &&
838 git tag --sign -m "A message" forcesignannotated-disabled &&
839 get_tag_msg forcesignannotated-disabled >actual &&
840 test_cmp expect actual
843 test_expect_success GPG \
844 'trying to create a signed tag with non-existing -F file should fail' '
845 ! test -f nonexistingfile &&
846 ! tag_exists nosigtag &&
847 test_must_fail git tag -s -F nonexistingfile nosigtag &&
848 ! tag_exists nosigtag
851 test_expect_success GPG 'verifying a signed tag should succeed' \
852 'git tag -v signed-tag'
854 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
855 'git tag -v signed-tag file-signed-tag'
857 test_expect_success GPG \
858 'verifying many signed and non-signed tags should fail' '
859 test_must_fail git tag -v signed-tag annotated-tag &&
860 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
861 test_must_fail git tag -v annotated-tag \
862 file-signed-tag file-annotated-tag &&
863 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
866 test_expect_success GPG 'verifying a forged tag should fail' '
867 forged=$(git cat-file tag signed-tag |
868 sed -e "s/signed-tag/forged-tag/" |
869 git mktag) &&
870 git tag forged-tag $forged &&
871 test_must_fail git tag -v forged-tag
874 # blank and empty messages for signed tags:
876 get_tag_header empty-signed-tag $commit commit $time >expect
877 echo '-----BEGIN PGP SIGNATURE-----' >>expect
878 test_expect_success GPG \
879 'creating a signed tag with an empty -m message should succeed' '
880 git tag -s -m "" empty-signed-tag &&
881 get_tag_msg empty-signed-tag >actual &&
882 test_cmp expect actual &&
883 git tag -v empty-signed-tag
886 >sigemptyfile
887 get_tag_header emptyfile-signed-tag $commit commit $time >expect
888 echo '-----BEGIN PGP SIGNATURE-----' >>expect
889 test_expect_success GPG \
890 'creating a signed tag with an empty -F messagefile should succeed' '
891 git tag -s -F sigemptyfile emptyfile-signed-tag &&
892 get_tag_msg emptyfile-signed-tag >actual &&
893 test_cmp expect actual &&
894 git tag -v emptyfile-signed-tag
897 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
898 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
899 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
900 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
901 get_tag_header blanks-signed-tag $commit commit $time >expect
902 cat >>expect <<EOF
903 Leading blank lines
905 Repeated blank lines
907 Trailing spaces
909 Trailing blank lines
911 echo '-----BEGIN PGP SIGNATURE-----' >>expect
912 test_expect_success GPG \
913 'extra blanks in the message for a signed tag should be removed' '
914 git tag -s -F sigblanksfile blanks-signed-tag &&
915 get_tag_msg blanks-signed-tag >actual &&
916 test_cmp expect actual &&
917 git tag -v blanks-signed-tag
920 get_tag_header blank-signed-tag $commit commit $time >expect
921 echo '-----BEGIN PGP SIGNATURE-----' >>expect
922 test_expect_success GPG \
923 'creating a signed tag with a blank -m message should succeed' '
924 git tag -s -m " " blank-signed-tag &&
925 get_tag_msg blank-signed-tag >actual &&
926 test_cmp expect actual &&
927 git tag -v blank-signed-tag
930 echo ' ' >sigblankfile
931 echo '' >>sigblankfile
932 echo ' ' >>sigblankfile
933 get_tag_header blankfile-signed-tag $commit commit $time >expect
934 echo '-----BEGIN PGP SIGNATURE-----' >>expect
935 test_expect_success GPG \
936 'creating a signed tag with blank -F file with spaces should succeed' '
937 git tag -s -F sigblankfile blankfile-signed-tag &&
938 get_tag_msg blankfile-signed-tag >actual &&
939 test_cmp expect actual &&
940 git tag -v blankfile-signed-tag
943 printf ' ' >sigblanknonlfile
944 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
945 echo '-----BEGIN PGP SIGNATURE-----' >>expect
946 test_expect_success GPG \
947 'creating a signed tag with spaces and no newline should succeed' '
948 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
949 get_tag_msg blanknonlfile-signed-tag >actual &&
950 test_cmp expect actual &&
951 git tag -v signed-tag
954 # messages with commented lines for signed tags:
956 cat >sigcommentsfile <<EOF
957 # A comment
959 ############
960 The message.
961 ############
962 One line.
965 # commented lines
966 # commented lines
968 Another line.
969 # comments
971 Last line.
973 get_tag_header comments-signed-tag $commit commit $time >expect
974 cat >>expect <<EOF
975 The message.
976 One line.
978 Another line.
980 Last line.
982 echo '-----BEGIN PGP SIGNATURE-----' >>expect
983 test_expect_success GPG \
984 'creating a signed tag with a -F file with #comments should succeed' '
985 git tag -s -F sigcommentsfile comments-signed-tag &&
986 get_tag_msg comments-signed-tag >actual &&
987 test_cmp expect actual &&
988 git tag -v comments-signed-tag
991 get_tag_header comment-signed-tag $commit commit $time >expect
992 echo '-----BEGIN PGP SIGNATURE-----' >>expect
993 test_expect_success GPG \
994 'creating a signed tag with #commented -m message should succeed' '
995 git tag -s -m "#comment" comment-signed-tag &&
996 get_tag_msg comment-signed-tag >actual &&
997 test_cmp expect actual &&
998 git tag -v comment-signed-tag
1001 echo '#comment' >sigcommentfile
1002 echo '' >>sigcommentfile
1003 echo '####' >>sigcommentfile
1004 get_tag_header commentfile-signed-tag $commit commit $time >expect
1005 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1006 test_expect_success GPG \
1007 'creating a signed tag with #commented -F messagefile should succeed' '
1008 git tag -s -F sigcommentfile commentfile-signed-tag &&
1009 get_tag_msg commentfile-signed-tag >actual &&
1010 test_cmp expect actual &&
1011 git tag -v commentfile-signed-tag
1014 printf '#comment' >sigcommentnonlfile
1015 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success GPG \
1018 'creating a signed tag with a #comment and no newline should succeed' '
1019 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1020 get_tag_msg commentnonlfile-signed-tag >actual &&
1021 test_cmp expect actual &&
1022 git tag -v commentnonlfile-signed-tag
1025 # listing messages for signed tags:
1027 test_expect_success GPG \
1028 'listing the one-line message of a signed tag should succeed' '
1029 git tag -s -m "A message line signed" stag-one-line &&
1031 echo "stag-one-line" >expect &&
1032 git tag -l | grep "^stag-one-line" >actual &&
1033 test_cmp expect actual &&
1034 git tag -n0 -l | grep "^stag-one-line" >actual &&
1035 test_cmp expect actual &&
1036 git tag -n0 -l stag-one-line >actual &&
1037 test_cmp expect actual &&
1039 echo "stag-one-line A message line signed" >expect &&
1040 git tag -n1 -l | grep "^stag-one-line" >actual &&
1041 test_cmp expect actual &&
1042 git tag -n -l | grep "^stag-one-line" >actual &&
1043 test_cmp expect actual &&
1044 git tag -n1 -l stag-one-line >actual &&
1045 test_cmp expect actual &&
1046 git tag -n2 -l stag-one-line >actual &&
1047 test_cmp expect actual &&
1048 git tag -n999 -l stag-one-line >actual &&
1049 test_cmp expect actual
1052 test_expect_success GPG \
1053 'listing the zero-lines message of a signed tag should succeed' '
1054 git tag -s -m "" stag-zero-lines &&
1056 echo "stag-zero-lines" >expect &&
1057 git tag -l | grep "^stag-zero-lines" >actual &&
1058 test_cmp expect actual &&
1059 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1060 test_cmp expect actual &&
1061 git tag -n0 -l stag-zero-lines >actual &&
1062 test_cmp expect actual &&
1064 echo "stag-zero-lines " >expect &&
1065 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1066 test_cmp expect actual &&
1067 git tag -n -l | grep "^stag-zero-lines" >actual &&
1068 test_cmp expect actual &&
1069 git tag -n1 -l stag-zero-lines >actual &&
1070 test_cmp expect actual &&
1071 git tag -n2 -l stag-zero-lines >actual &&
1072 test_cmp expect actual &&
1073 git tag -n999 -l stag-zero-lines >actual &&
1074 test_cmp expect actual
1077 echo 'stag line one' >sigtagmsg
1078 echo 'stag line two' >>sigtagmsg
1079 echo 'stag line three' >>sigtagmsg
1080 test_expect_success GPG \
1081 'listing many message lines of a signed tag should succeed' '
1082 git tag -s -F sigtagmsg stag-lines &&
1084 echo "stag-lines" >expect &&
1085 git tag -l | grep "^stag-lines" >actual &&
1086 test_cmp expect actual &&
1087 git tag -n0 -l | grep "^stag-lines" >actual &&
1088 test_cmp expect actual &&
1089 git tag -n0 -l stag-lines >actual &&
1090 test_cmp expect actual &&
1092 echo "stag-lines stag line one" >expect &&
1093 git tag -n1 -l | grep "^stag-lines" >actual &&
1094 test_cmp expect actual &&
1095 git tag -n -l | grep "^stag-lines" >actual &&
1096 test_cmp expect actual &&
1097 git tag -n1 -l stag-lines >actual &&
1098 test_cmp expect actual &&
1100 echo " stag line two" >>expect &&
1101 git tag -n2 -l | grep "^ *stag.line" >actual &&
1102 test_cmp expect actual &&
1103 git tag -n2 -l stag-lines >actual &&
1104 test_cmp expect actual &&
1106 echo " stag line three" >>expect &&
1107 git tag -n3 -l | grep "^ *stag.line" >actual &&
1108 test_cmp expect actual &&
1109 git tag -n3 -l stag-lines >actual &&
1110 test_cmp expect actual &&
1111 git tag -n4 -l | grep "^ *stag.line" >actual &&
1112 test_cmp expect actual &&
1113 git tag -n4 -l stag-lines >actual &&
1114 test_cmp expect actual &&
1115 git tag -n99 -l | grep "^ *stag.line" >actual &&
1116 test_cmp expect actual &&
1117 git tag -n99 -l stag-lines >actual &&
1118 test_cmp expect actual
1121 # tags pointing to objects different from commits:
1123 tree=$(git rev-parse HEAD^{tree})
1124 blob=$(git rev-parse HEAD:foo)
1125 tag=$(git rev-parse signed-tag 2>/dev/null)
1127 get_tag_header tree-signed-tag $tree tree $time >expect
1128 echo "A message for a tree" >>expect
1129 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1130 test_expect_success GPG \
1131 'creating a signed tag pointing to a tree should succeed' '
1132 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1133 get_tag_msg tree-signed-tag >actual &&
1134 test_cmp expect actual
1137 get_tag_header blob-signed-tag $blob blob $time >expect
1138 echo "A message for a blob" >>expect
1139 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1140 test_expect_success GPG \
1141 'creating a signed tag pointing to a blob should succeed' '
1142 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1143 get_tag_msg blob-signed-tag >actual &&
1144 test_cmp expect actual
1147 get_tag_header tag-signed-tag $tag tag $time >expect
1148 echo "A message for another tag" >>expect
1149 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1150 test_expect_success GPG \
1151 'creating a signed tag pointing to another tag should succeed' '
1152 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1153 get_tag_msg tag-signed-tag >actual &&
1154 test_cmp expect actual
1157 # usage with rfc1991 signatures
1158 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1159 echo "RFC1991 signed tag" >>expect
1160 echo '-----BEGIN PGP MESSAGE-----' >>expect
1161 test_expect_success GPG,RFC1991 \
1162 'creating a signed tag with rfc1991' '
1163 echo "rfc1991" >gpghome/gpg.conf &&
1164 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1165 get_tag_msg rfc1991-signed-tag >actual &&
1166 test_cmp expect actual
1169 cat >fakeeditor <<'EOF'
1170 #!/bin/sh
1171 cp "$1" actual
1173 chmod +x fakeeditor
1175 test_expect_success GPG,RFC1991 \
1176 'reediting a signed tag body omits signature' '
1177 echo "rfc1991" >gpghome/gpg.conf &&
1178 echo "RFC1991 signed tag" >expect &&
1179 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1180 test_cmp expect actual
1183 test_expect_success GPG,RFC1991 \
1184 'verifying rfc1991 signature' '
1185 echo "rfc1991" >gpghome/gpg.conf &&
1186 git tag -v rfc1991-signed-tag
1189 test_expect_success GPG,RFC1991 \
1190 'list tag with rfc1991 signature' '
1191 echo "rfc1991" >gpghome/gpg.conf &&
1192 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1193 git tag -l -n1 rfc1991-signed-tag >actual &&
1194 test_cmp expect actual &&
1195 git tag -l -n2 rfc1991-signed-tag >actual &&
1196 test_cmp expect actual &&
1197 git tag -l -n999 rfc1991-signed-tag >actual &&
1198 test_cmp expect actual
1201 rm -f gpghome/gpg.conf
1203 test_expect_success GPG,RFC1991 \
1204 'verifying rfc1991 signature without --rfc1991' '
1205 git tag -v rfc1991-signed-tag
1208 test_expect_success GPG,RFC1991 \
1209 'list tag with rfc1991 signature without --rfc1991' '
1210 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1211 git tag -l -n1 rfc1991-signed-tag >actual &&
1212 test_cmp expect actual &&
1213 git tag -l -n2 rfc1991-signed-tag >actual &&
1214 test_cmp expect actual &&
1215 git tag -l -n999 rfc1991-signed-tag >actual &&
1216 test_cmp expect actual
1219 test_expect_success GPG,RFC1991 \
1220 'reediting a signed tag body omits signature' '
1221 echo "RFC1991 signed tag" >expect &&
1222 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1223 test_cmp expect actual
1226 # try to sign with bad user.signingkey
1227 test_expect_success GPG \
1228 'git tag -s fails if gpg is misconfigured (bad key)' \
1229 'test_config user.signingkey BobTheMouse &&
1230 test_must_fail git tag -s -m tail tag-gpg-failure'
1232 # try to produce invalid signature
1233 test_expect_success GPG \
1234 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1235 'test_config gpg.program echo &&
1236 test_must_fail git tag -s -m tail tag-gpg-failure'
1239 # try to verify without gpg:
1241 rm -rf gpghome
1242 test_expect_success GPG \
1243 'verify signed tag fails when public key is not present' \
1244 'test_must_fail git tag -v signed-tag'
1246 test_expect_success \
1247 'git tag -a fails if tag annotation is empty' '
1248 ! (GIT_EDITOR=cat git tag -a initial-comment)
1251 test_expect_success \
1252 'message in editor has initial comment' '
1253 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1256 test_expect_success 'message in editor has initial comment: first line' '
1257 # check the first line --- should be empty
1258 echo >first.expect &&
1259 sed -e 1q <actual >first.actual &&
1260 test_i18ncmp first.expect first.actual
1263 test_expect_success \
1264 'message in editor has initial comment: remainder' '
1265 # remove commented lines from the remainder -- should be empty
1266 >rest.expect &&
1267 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1268 test_cmp rest.expect rest.actual
1271 get_tag_header reuse $commit commit $time >expect
1272 echo "An annotation to be reused" >> expect
1273 test_expect_success \
1274 'overwriting an annoted tag should use its previous body' '
1275 git tag -a -m "An annotation to be reused" reuse &&
1276 GIT_EDITOR=true git tag -f -a reuse &&
1277 get_tag_msg reuse >actual &&
1278 test_cmp expect actual
1281 test_expect_success 'filename for the message is relative to cwd' '
1282 mkdir subdir &&
1283 echo "Tag message in top directory" >msgfile-5 &&
1284 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1286 cd subdir &&
1287 git tag -a -F msgfile-5 tag-from-subdir
1288 ) &&
1289 git cat-file tag tag-from-subdir | grep "in sub directory"
1292 test_expect_success 'filename for the message is relative to cwd' '
1293 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1295 cd subdir &&
1296 git tag -a -F msgfile-6 tag-from-subdir-2
1297 ) &&
1298 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1301 # create a few more commits to test --contains
1303 hash1=$(git rev-parse HEAD)
1305 test_expect_success 'creating second commit and tag' '
1306 echo foo-2.0 >foo &&
1307 git add foo &&
1308 git commit -m second &&
1309 git tag v2.0
1312 hash2=$(git rev-parse HEAD)
1314 test_expect_success 'creating third commit without tag' '
1315 echo foo-dev >foo &&
1316 git add foo &&
1317 git commit -m third
1320 hash3=$(git rev-parse HEAD)
1322 # simple linear checks of --continue
1324 cat > expected <<EOF
1325 v0.2.1
1326 v1.0
1327 v1.0.1
1328 v1.1.3
1329 v2.0
1332 test_expect_success 'checking that first commit is in all tags (hash)' "
1333 git tag -l --contains $hash1 v* >actual &&
1334 test_cmp expected actual
1337 # other ways of specifying the commit
1338 test_expect_success 'checking that first commit is in all tags (tag)' "
1339 git tag -l --contains v1.0 v* >actual &&
1340 test_cmp expected actual
1343 test_expect_success 'checking that first commit is in all tags (relative)' "
1344 git tag -l --contains HEAD~2 v* >actual &&
1345 test_cmp expected actual
1348 cat > expected <<EOF
1349 v2.0
1352 test_expect_success 'checking that second commit only has one tag' "
1353 git tag -l --contains $hash2 v* >actual &&
1354 test_cmp expected actual
1358 cat > expected <<EOF
1361 test_expect_success 'checking that third commit has no tags' "
1362 git tag -l --contains $hash3 v* >actual &&
1363 test_cmp expected actual
1366 # how about a simple merge?
1368 test_expect_success 'creating simple branch' '
1369 git branch stable v2.0 &&
1370 git checkout stable &&
1371 echo foo-3.0 > foo &&
1372 git commit foo -m fourth &&
1373 git tag v3.0
1376 hash4=$(git rev-parse HEAD)
1378 cat > expected <<EOF
1379 v3.0
1382 test_expect_success 'checking that branch head only has one tag' "
1383 git tag -l --contains $hash4 v* >actual &&
1384 test_cmp expected actual
1387 test_expect_success 'merging original branch into this branch' '
1388 git merge --strategy=ours master &&
1389 git tag v4.0
1392 cat > expected <<EOF
1393 v4.0
1396 test_expect_success 'checking that original branch head has one tag now' "
1397 git tag -l --contains $hash3 v* >actual &&
1398 test_cmp expected actual
1401 cat > expected <<EOF
1402 v0.2.1
1403 v1.0
1404 v1.0.1
1405 v1.1.3
1406 v2.0
1407 v3.0
1408 v4.0
1411 test_expect_success 'checking that initial commit is in all tags' "
1412 git tag -l --contains $hash1 v* >actual &&
1413 test_cmp expected actual
1416 # mixing modes and options:
1418 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1419 test_must_fail git tag -a &&
1420 test_must_fail git tag -l -v &&
1421 test_must_fail git tag -n 100 &&
1422 test_must_fail git tag -l -m msg &&
1423 test_must_fail git tag -l -F some file &&
1424 test_must_fail git tag -v -s
1427 # check points-at
1429 test_expect_success '--points-at cannot be used in non-list mode' '
1430 test_must_fail git tag --points-at=v4.0 foo
1433 test_expect_success '--points-at finds lightweight tags' '
1434 echo v4.0 >expect &&
1435 git tag --points-at v4.0 >actual &&
1436 test_cmp expect actual
1439 test_expect_success '--points-at finds annotated tags of commits' '
1440 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1441 echo annotated-v4.0 >expect &&
1442 git tag -l --points-at v4.0 "annotated*" >actual &&
1443 test_cmp expect actual
1446 test_expect_success '--points-at finds annotated tags of tags' '
1447 git tag -m "describing the v4.0 tag object" \
1448 annotated-again-v4.0 annotated-v4.0 &&
1449 cat >expect <<-\EOF &&
1450 annotated-again-v4.0
1451 annotated-v4.0
1453 git tag --points-at=annotated-v4.0 >actual &&
1454 test_cmp expect actual
1457 test_expect_success 'multiple --points-at are OR-ed together' '
1458 cat >expect <<-\EOF &&
1459 v2.0
1460 v3.0
1462 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1463 test_cmp expect actual
1466 test_expect_success 'lexical sort' '
1467 git tag foo1.3 &&
1468 git tag foo1.6 &&
1469 git tag foo1.10 &&
1470 git tag -l --sort=refname "foo*" >actual &&
1471 cat >expect <<-\EOF &&
1472 foo1.10
1473 foo1.3
1474 foo1.6
1476 test_cmp expect actual
1479 test_expect_success 'version sort' '
1480 git tag -l --sort=version:refname "foo*" >actual &&
1481 cat >expect <<-\EOF &&
1482 foo1.3
1483 foo1.6
1484 foo1.10
1486 test_cmp expect actual
1489 test_expect_success 'reverse version sort' '
1490 git tag -l --sort=-version:refname "foo*" >actual &&
1491 cat >expect <<-\EOF &&
1492 foo1.10
1493 foo1.6
1494 foo1.3
1496 test_cmp expect actual
1499 test_expect_success 'reverse lexical sort' '
1500 git tag -l --sort=-refname "foo*" >actual &&
1501 cat >expect <<-\EOF &&
1502 foo1.6
1503 foo1.3
1504 foo1.10
1506 test_cmp expect actual
1509 test_expect_success 'configured lexical sort' '
1510 test_config tag.sort "v:refname" &&
1511 git tag -l "foo*" >actual &&
1512 cat >expect <<-\EOF &&
1513 foo1.3
1514 foo1.6
1515 foo1.10
1517 test_cmp expect actual
1520 test_expect_success 'option override configured sort' '
1521 test_config tag.sort "v:refname" &&
1522 git tag -l --sort=-refname "foo*" >actual &&
1523 cat >expect <<-\EOF &&
1524 foo1.6
1525 foo1.3
1526 foo1.10
1528 test_cmp expect actual
1531 test_expect_success 'invalid sort parameter on command line' '
1532 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1535 test_expect_success 'invalid sort parameter in configuratoin' '
1536 test_config tag.sort "v:notvalid" &&
1537 test_must_fail git tag -l "foo*"
1540 test_expect_success 'version sort with prerelease reordering' '
1541 test_config versionsort.prereleaseSuffix -rc &&
1542 git tag foo1.6-rc1 &&
1543 git tag foo1.6-rc2 &&
1544 git tag -l --sort=version:refname "foo*" >actual &&
1545 cat >expect <<-\EOF &&
1546 foo1.3
1547 foo1.6-rc1
1548 foo1.6-rc2
1549 foo1.6
1550 foo1.10
1552 test_cmp expect actual
1555 test_expect_success 'reverse version sort with prerelease reordering' '
1556 test_config versionsort.prereleaseSuffix -rc &&
1557 git tag -l --sort=-version:refname "foo*" >actual &&
1558 cat >expect <<-\EOF &&
1559 foo1.10
1560 foo1.6
1561 foo1.6-rc2
1562 foo1.6-rc1
1563 foo1.3
1565 test_cmp expect actual
1568 test_expect_success 'version sort with prerelease reordering and common leading character' '
1569 test_config versionsort.prereleaseSuffix -before &&
1570 git tag foo1.7-before1 &&
1571 git tag foo1.7 &&
1572 git tag foo1.7-after1 &&
1573 git tag -l --sort=version:refname "foo1.7*" >actual &&
1574 cat >expect <<-\EOF &&
1575 foo1.7-before1
1576 foo1.7
1577 foo1.7-after1
1579 test_cmp expect actual
1582 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1583 test_config versionsort.prereleaseSuffix -before &&
1584 git config --add versionsort.prereleaseSuffix -after &&
1585 git tag -l --sort=version:refname "foo1.7*" >actual &&
1586 cat >expect <<-\EOF &&
1587 foo1.7-before1
1588 foo1.7-after1
1589 foo1.7
1591 test_cmp expect actual
1594 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1595 test_config versionsort.prereleaseSuffix -bar &&
1596 git config --add versionsort.prereleaseSuffix -foo-baz &&
1597 git config --add versionsort.prereleaseSuffix -foo-bar &&
1598 git tag foo1.8-foo-bar &&
1599 git tag foo1.8-foo-baz &&
1600 git tag foo1.8 &&
1601 git tag -l --sort=version:refname "foo1.8*" >actual &&
1602 cat >expect <<-\EOF &&
1603 foo1.8-foo-baz
1604 foo1.8-foo-bar
1605 foo1.8
1607 test_cmp expect actual
1610 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1611 test_config versionsort.prereleaseSuffix -pre &&
1612 git config --add versionsort.prereleaseSuffix -prerelease &&
1613 git tag foo1.9-pre1 &&
1614 git tag foo1.9-pre2 &&
1615 git tag foo1.9-prerelease1 &&
1616 git tag -l --sort=version:refname "foo1.9*" >actual &&
1617 cat >expect <<-\EOF &&
1618 foo1.9-pre1
1619 foo1.9-pre2
1620 foo1.9-prerelease1
1622 test_cmp expect actual
1625 test_expect_success 'version sort with general suffix reordering' '
1626 test_config versionsort.suffix -alpha &&
1627 git config --add versionsort.suffix -beta &&
1628 git config --add versionsort.suffix "" &&
1629 git config --add versionsort.suffix -gamma &&
1630 git config --add versionsort.suffix -delta &&
1631 git tag foo1.10-alpha &&
1632 git tag foo1.10-beta &&
1633 git tag foo1.10-gamma &&
1634 git tag foo1.10-delta &&
1635 git tag foo1.10-unlisted-suffix &&
1636 git tag -l --sort=version:refname "foo1.10*" >actual &&
1637 cat >expect <<-\EOF &&
1638 foo1.10-alpha
1639 foo1.10-beta
1640 foo1.10
1641 foo1.10-unlisted-suffix
1642 foo1.10-gamma
1643 foo1.10-delta
1645 test_cmp expect actual
1648 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1649 test_config versionsort.suffix -before &&
1650 test_config versionsort.prereleaseSuffix -after &&
1651 git tag -l --sort=version:refname "foo1.7*" >actual &&
1652 cat >expect <<-\EOF &&
1653 foo1.7-before1
1654 foo1.7
1655 foo1.7-after1
1657 test_cmp expect actual
1660 test_expect_success 'version sort with very long prerelease suffix' '
1661 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1662 git tag -l --sort=version:refname
1665 run_with_limited_stack () {
1666 (ulimit -s 128 && "$@")
1669 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1671 # we require ulimit, this excludes Windows
1672 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1673 >expect &&
1674 i=1 &&
1675 while test $i -lt 8000
1677 echo "commit refs/heads/master
1678 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1679 data <<EOF
1680 commit #$i
1681 EOF"
1682 test $i = 1 && echo "from refs/heads/master^0"
1683 i=$(($i + 1))
1684 done | git fast-import &&
1685 git checkout master &&
1686 git tag far-far-away HEAD^ &&
1687 run_with_limited_stack git tag --contains HEAD >actual &&
1688 test_cmp expect actual
1691 test_expect_success '--format should list tags as per format given' '
1692 cat >expect <<-\EOF &&
1693 refname : refs/tags/v1.0
1694 refname : refs/tags/v1.0.1
1695 refname : refs/tags/v1.1.3
1697 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1698 test_cmp expect actual
1701 test_expect_success 'setup --merged test tags' '
1702 git tag mergetest-1 HEAD~2 &&
1703 git tag mergetest-2 HEAD~1 &&
1704 git tag mergetest-3 HEAD
1707 test_expect_success '--merged cannot be used in non-list mode' '
1708 test_must_fail git tag --merged=mergetest-2 foo
1711 test_expect_success '--merged shows merged tags' '
1712 cat >expect <<-\EOF &&
1713 mergetest-1
1714 mergetest-2
1716 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1717 test_cmp expect actual
1720 test_expect_success '--no-merged show unmerged tags' '
1721 cat >expect <<-\EOF &&
1722 mergetest-3
1724 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1725 test_cmp expect actual
1728 test_expect_success 'ambiguous branch/tags not marked' '
1729 git tag ambiguous &&
1730 git branch ambiguous &&
1731 echo ambiguous >expect &&
1732 git tag -l ambiguous >actual &&
1733 test_cmp expect actual
1736 test_done