Merge branch 'sb/push-options-via-transport'
[git/debian.git] / t / t7004-tag.sh
blob072e6c6b88447f21e89a0087d894ae8ab2868ad7
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 test_when_finished "git tag -d tag_with_reflog" &&
85 git tag --create-reflog tag_with_reflog &&
86 git reflog exists refs/tags/tag_with_reflog
89 test_expect_success '--create-reflog does not create reflog on failure' '
90 test_must_fail git tag --create-reflog mytag &&
91 test_must_fail git reflog exists refs/tags/mytag
94 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
95 test_when_finished "git tag -d tag_with_reflog" &&
96 test_config core.logAllRefUpdates always &&
97 git tag tag_with_reflog &&
98 git reflog exists refs/tags/tag_with_reflog
101 test_expect_success 'listing all tags if one exists should succeed' '
102 git tag -l &&
103 git tag
106 test_expect_success 'listing all tags if one exists should output that tag' '
107 test $(git tag -l) = mytag &&
108 test $(git tag) = mytag
111 # pattern matching:
113 test_expect_success 'listing a tag using a matching pattern should succeed' \
114 'git tag -l mytag'
116 test_expect_success 'listing a tag with --ignore-case' \
117 'test $(git tag -l --ignore-case MYTAG) = mytag'
119 test_expect_success \
120 'listing a tag using a matching pattern should output that tag' \
121 'test $(git tag -l mytag) = mytag'
123 # todo: git tag -l now returns always zero, when fixed, change this test
124 test_expect_success \
125 'listing tags using a non-matching pattern should suceed' \
126 'git tag -l xxx'
128 test_expect_success \
129 'listing tags using a non-matching pattern should output nothing' \
130 'test $(git tag -l xxx | wc -l) -eq 0'
132 # special cases for creating tags:
134 test_expect_success \
135 'trying to create a tag with the name of one existing should fail' \
136 'test_must_fail git tag mytag'
138 test_expect_success \
139 'trying to create a tag with a non-valid name should fail' '
140 test $(git tag -l | wc -l) -eq 1 &&
141 test_must_fail git tag "" &&
142 test_must_fail git tag .othertag &&
143 test_must_fail git tag "other tag" &&
144 test_must_fail git tag "othertag^" &&
145 test_must_fail git tag "other~tag" &&
146 test $(git tag -l | wc -l) -eq 1
149 test_expect_success 'creating a tag using HEAD directly should succeed' '
150 git tag myhead HEAD &&
151 tag_exists myhead
154 test_expect_success '--force can create a tag with the name of one existing' '
155 tag_exists mytag &&
156 git tag --force mytag &&
157 tag_exists mytag'
159 test_expect_success '--force is moot with a non-existing tag name' '
160 test_when_finished git tag -d newtag forcetag &&
161 git tag newtag >expect &&
162 git tag --force forcetag >actual &&
163 test_cmp expect actual
166 # deleting tags:
168 test_expect_success 'trying to delete an unknown tag should fail' '
169 ! tag_exists unknown-tag &&
170 test_must_fail git tag -d unknown-tag
173 cat >expect <<EOF
174 myhead
175 mytag
177 test_expect_success \
178 'trying to delete tags without params should succeed and do nothing' '
179 git tag -l > actual && test_cmp expect actual &&
180 git tag -d &&
181 git tag -l > actual && test_cmp expect actual
184 test_expect_success \
185 'deleting two existing tags in one command should succeed' '
186 tag_exists mytag &&
187 tag_exists myhead &&
188 git tag -d mytag myhead &&
189 ! tag_exists mytag &&
190 ! tag_exists myhead
193 test_expect_success \
194 'creating a tag with the name of another deleted one should succeed' '
195 ! tag_exists mytag &&
196 git tag mytag &&
197 tag_exists mytag
200 test_expect_success \
201 'trying to delete two tags, existing and not, should fail in the 2nd' '
202 tag_exists mytag &&
203 ! tag_exists myhead &&
204 test_must_fail git tag -d mytag anothertag &&
205 ! tag_exists mytag &&
206 ! tag_exists myhead
209 test_expect_success 'trying to delete an already deleted tag should fail' \
210 'test_must_fail git tag -d mytag'
212 # listing various tags with pattern matching:
214 cat >expect <<EOF
218 t210
219 t211
220 v0.2.1
221 v1.0
222 v1.0.1
223 v1.1.3
225 test_expect_success 'listing all tags should print them ordered' '
226 git tag v1.0.1 &&
227 git tag t211 &&
228 git tag aa1 &&
229 git tag v0.2.1 &&
230 git tag v1.1.3 &&
231 git tag cba &&
232 git tag a1 &&
233 git tag v1.0 &&
234 git tag t210 &&
235 git tag -l > actual &&
236 test_cmp expect actual &&
237 git tag > actual &&
238 test_cmp expect actual
241 cat >expect <<EOF
246 test_expect_success \
247 'listing tags with substring as pattern must print those matching' '
248 rm *a* &&
249 git tag -l "*a*" > current &&
250 test_cmp expect current
253 cat >expect <<EOF
254 v0.2.1
255 v1.0.1
257 test_expect_success \
258 'listing tags with a suffix as pattern must print those matching' '
259 git tag -l "*.1" > actual &&
260 test_cmp expect actual
263 cat >expect <<EOF
264 t210
265 t211
267 test_expect_success \
268 'listing tags with a prefix as pattern must print those matching' '
269 git tag -l "t21*" > actual &&
270 test_cmp expect actual
273 cat >expect <<EOF
276 test_expect_success \
277 'listing tags using a name as pattern must print that one matching' '
278 git tag -l a1 > actual &&
279 test_cmp expect actual
282 cat >expect <<EOF
283 v1.0
285 test_expect_success \
286 'listing tags using a name as pattern must print that one matching' '
287 git tag -l v1.0 > actual &&
288 test_cmp expect actual
291 cat >expect <<EOF
292 v1.0.1
293 v1.1.3
295 test_expect_success \
296 'listing tags with ? in the pattern should print those matching' '
297 git tag -l "v1.?.?" > actual &&
298 test_cmp expect actual
301 >expect
302 test_expect_success \
303 'listing tags using v.* should print nothing because none have v.' '
304 git tag -l "v.*" > actual &&
305 test_cmp expect actual
308 cat >expect <<EOF
309 v0.2.1
310 v1.0
311 v1.0.1
312 v1.1.3
314 test_expect_success \
315 'listing tags using v* should print only those having v' '
316 git tag -l "v*" > actual &&
317 test_cmp expect actual
320 test_expect_success 'tag -l can accept multiple patterns' '
321 git tag -l "v1*" "v0*" >actual &&
322 test_cmp expect actual
325 test_expect_success 'listing tags in column' '
326 COLUMNS=40 git tag -l --column=row >actual &&
327 cat >expected <<\EOF &&
328 a1 aa1 cba t210 t211
329 v0.2.1 v1.0 v1.0.1 v1.1.3
331 test_cmp expected actual
334 test_expect_success 'listing tags in column with column.*' '
335 test_config column.tag row &&
336 test_config column.ui dense &&
337 COLUMNS=40 git tag -l >actual &&
338 cat >expected <<\EOF &&
339 a1 aa1 cba t210 t211
340 v0.2.1 v1.0 v1.0.1 v1.1.3
342 test_cmp expected actual
345 test_expect_success 'listing tag with -n --column should fail' '
346 test_must_fail git tag --column -n
349 test_expect_success 'listing tags -n in column with column.ui ignored' '
350 test_config column.ui "row dense" &&
351 COLUMNS=40 git tag -l -n >actual &&
352 cat >expected <<\EOF &&
353 a1 Foo
354 aa1 Foo
355 cba Foo
356 t210 Foo
357 t211 Foo
358 v0.2.1 Foo
359 v1.0 Foo
360 v1.0.1 Foo
361 v1.1.3 Foo
363 test_cmp expected actual
366 # creating and verifying lightweight tags:
368 test_expect_success \
369 'a non-annotated tag created without parameters should point to HEAD' '
370 git tag non-annotated-tag &&
371 test $(git cat-file -t non-annotated-tag) = commit &&
372 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
375 test_expect_success 'trying to verify an unknown tag should fail' \
376 'test_must_fail git tag -v unknown-tag'
378 test_expect_success \
379 'trying to verify a non-annotated and non-signed tag should fail' \
380 'test_must_fail git tag -v non-annotated-tag'
382 test_expect_success \
383 'trying to verify many non-annotated or unknown tags, should fail' \
384 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
386 # creating annotated tags:
388 get_tag_msg () {
389 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
392 # run test_tick before committing always gives the time in that timezone
393 get_tag_header () {
394 cat <<EOF
395 object $2
396 type $3
397 tag $1
398 tagger C O Mitter <committer@example.com> $4 -0700
403 commit=$(git rev-parse HEAD)
404 time=$test_tick
406 get_tag_header annotated-tag $commit commit $time >expect
407 echo "A message" >>expect
408 test_expect_success \
409 'creating an annotated tag with -m message should succeed' '
410 git tag -m "A message" annotated-tag &&
411 get_tag_msg annotated-tag >actual &&
412 test_cmp expect actual
415 cat >msgfile <<EOF
416 Another message
417 in a file.
419 get_tag_header file-annotated-tag $commit commit $time >expect
420 cat msgfile >>expect
421 test_expect_success \
422 'creating an annotated tag with -F messagefile should succeed' '
423 git tag -F msgfile file-annotated-tag &&
424 get_tag_msg file-annotated-tag >actual &&
425 test_cmp expect actual
428 cat >inputmsg <<EOF
429 A message from the
430 standard input
432 get_tag_header stdin-annotated-tag $commit commit $time >expect
433 cat inputmsg >>expect
434 test_expect_success 'creating an annotated tag with -F - should succeed' '
435 git tag -F - stdin-annotated-tag <inputmsg &&
436 get_tag_msg stdin-annotated-tag >actual &&
437 test_cmp expect actual
440 test_expect_success \
441 'trying to create a tag with a non-existing -F file should fail' '
442 ! test -f nonexistingfile &&
443 ! tag_exists notag &&
444 test_must_fail git tag -F nonexistingfile notag &&
445 ! tag_exists notag
448 test_expect_success \
449 'trying to create tags giving both -m or -F options should fail' '
450 echo "message file 1" >msgfile1 &&
451 echo "message file 2" >msgfile2 &&
452 ! tag_exists msgtag &&
453 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
454 ! tag_exists msgtag &&
455 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
456 ! tag_exists msgtag &&
457 test_must_fail git tag -m "message 1" -F msgfile1 \
458 -m "message 2" msgtag &&
459 ! tag_exists msgtag
462 # blank and empty messages:
464 get_tag_header empty-annotated-tag $commit commit $time >expect
465 test_expect_success \
466 'creating a tag with an empty -m message should succeed' '
467 git tag -m "" empty-annotated-tag &&
468 get_tag_msg empty-annotated-tag >actual &&
469 test_cmp expect actual
472 >emptyfile
473 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
474 test_expect_success \
475 'creating a tag with an empty -F messagefile should succeed' '
476 git tag -F emptyfile emptyfile-annotated-tag &&
477 get_tag_msg emptyfile-annotated-tag >actual &&
478 test_cmp expect actual
481 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
482 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
483 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
484 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
485 get_tag_header blanks-annotated-tag $commit commit $time >expect
486 cat >>expect <<EOF
487 Leading blank lines
489 Repeated blank lines
491 Trailing spaces
493 Trailing blank lines
495 test_expect_success \
496 'extra blanks in the message for an annotated tag should be removed' '
497 git tag -F blanksfile blanks-annotated-tag &&
498 get_tag_msg blanks-annotated-tag >actual &&
499 test_cmp expect actual
502 get_tag_header blank-annotated-tag $commit commit $time >expect
503 test_expect_success \
504 'creating a tag with blank -m message with spaces should succeed' '
505 git tag -m " " blank-annotated-tag &&
506 get_tag_msg blank-annotated-tag >actual &&
507 test_cmp expect actual
510 echo ' ' >blankfile
511 echo '' >>blankfile
512 echo ' ' >>blankfile
513 get_tag_header blankfile-annotated-tag $commit commit $time >expect
514 test_expect_success \
515 'creating a tag with blank -F messagefile with spaces should succeed' '
516 git tag -F blankfile blankfile-annotated-tag &&
517 get_tag_msg blankfile-annotated-tag >actual &&
518 test_cmp expect actual
521 printf ' ' >blanknonlfile
522 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
523 test_expect_success \
524 'creating a tag with -F file of spaces and no newline should succeed' '
525 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
526 get_tag_msg blanknonlfile-annotated-tag >actual &&
527 test_cmp expect actual
530 # messages with commented lines:
532 cat >commentsfile <<EOF
533 # A comment
535 ############
536 The message.
537 ############
538 One line.
541 # commented lines
542 # commented lines
544 Another line.
545 # comments
547 Last line.
549 get_tag_header comments-annotated-tag $commit commit $time >expect
550 cat >>expect <<EOF
551 The message.
552 One line.
554 Another line.
556 Last line.
558 test_expect_success \
559 'creating a tag using a -F messagefile with #comments should succeed' '
560 git tag -F commentsfile comments-annotated-tag &&
561 get_tag_msg comments-annotated-tag >actual &&
562 test_cmp expect actual
565 get_tag_header comment-annotated-tag $commit commit $time >expect
566 test_expect_success \
567 'creating a tag with a #comment in the -m message should succeed' '
568 git tag -m "#comment" comment-annotated-tag &&
569 get_tag_msg comment-annotated-tag >actual &&
570 test_cmp expect actual
573 echo '#comment' >commentfile
574 echo '' >>commentfile
575 echo '####' >>commentfile
576 get_tag_header commentfile-annotated-tag $commit commit $time >expect
577 test_expect_success \
578 'creating a tag with #comments in the -F messagefile should succeed' '
579 git tag -F commentfile commentfile-annotated-tag &&
580 get_tag_msg commentfile-annotated-tag >actual &&
581 test_cmp expect actual
584 printf '#comment' >commentnonlfile
585 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
586 test_expect_success \
587 'creating a tag with a file of #comment and no newline should succeed' '
588 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
589 get_tag_msg commentnonlfile-annotated-tag >actual &&
590 test_cmp expect actual
593 # listing messages for annotated non-signed tags:
595 test_expect_success \
596 'listing the one-line message of a non-signed tag should succeed' '
597 git tag -m "A msg" tag-one-line &&
599 echo "tag-one-line" >expect &&
600 git tag -l | grep "^tag-one-line" >actual &&
601 test_cmp expect actual &&
602 git tag -n0 -l | grep "^tag-one-line" >actual &&
603 test_cmp expect actual &&
604 git tag -n0 -l tag-one-line >actual &&
605 test_cmp expect actual &&
607 echo "tag-one-line A msg" >expect &&
608 git tag -n1 -l | grep "^tag-one-line" >actual &&
609 test_cmp expect actual &&
610 git tag -n -l | grep "^tag-one-line" >actual &&
611 test_cmp expect actual &&
612 git tag -n1 -l tag-one-line >actual &&
613 test_cmp expect actual &&
614 git tag -n2 -l tag-one-line >actual &&
615 test_cmp expect actual &&
616 git tag -n999 -l tag-one-line >actual &&
617 test_cmp expect actual
620 test_expect_success \
621 'listing the zero-lines message of a non-signed tag should succeed' '
622 git tag -m "" tag-zero-lines &&
624 echo "tag-zero-lines" >expect &&
625 git tag -l | grep "^tag-zero-lines" >actual &&
626 test_cmp expect actual &&
627 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
628 test_cmp expect actual &&
629 git tag -n0 -l tag-zero-lines >actual &&
630 test_cmp expect actual &&
632 echo "tag-zero-lines " >expect &&
633 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
634 test_cmp expect actual &&
635 git tag -n -l | grep "^tag-zero-lines" >actual &&
636 test_cmp expect actual &&
637 git tag -n1 -l tag-zero-lines >actual &&
638 test_cmp expect actual &&
639 git tag -n2 -l tag-zero-lines >actual &&
640 test_cmp expect actual &&
641 git tag -n999 -l tag-zero-lines >actual &&
642 test_cmp expect actual
645 echo 'tag line one' >annotagmsg
646 echo 'tag line two' >>annotagmsg
647 echo 'tag line three' >>annotagmsg
648 test_expect_success \
649 'listing many message lines of a non-signed tag should succeed' '
650 git tag -F annotagmsg tag-lines &&
652 echo "tag-lines" >expect &&
653 git tag -l | grep "^tag-lines" >actual &&
654 test_cmp expect actual &&
655 git tag -n0 -l | grep "^tag-lines" >actual &&
656 test_cmp expect actual &&
657 git tag -n0 -l tag-lines >actual &&
658 test_cmp expect actual &&
660 echo "tag-lines tag line one" >expect &&
661 git tag -n1 -l | grep "^tag-lines" >actual &&
662 test_cmp expect actual &&
663 git tag -n -l | grep "^tag-lines" >actual &&
664 test_cmp expect actual &&
665 git tag -n1 -l tag-lines >actual &&
666 test_cmp expect actual &&
668 echo " tag line two" >>expect &&
669 git tag -n2 -l | grep "^ *tag.line" >actual &&
670 test_cmp expect actual &&
671 git tag -n2 -l tag-lines >actual &&
672 test_cmp expect actual &&
674 echo " tag line three" >>expect &&
675 git tag -n3 -l | grep "^ *tag.line" >actual &&
676 test_cmp expect actual &&
677 git tag -n3 -l tag-lines >actual &&
678 test_cmp expect actual &&
679 git tag -n4 -l | grep "^ *tag.line" >actual &&
680 test_cmp expect actual &&
681 git tag -n4 -l tag-lines >actual &&
682 test_cmp expect actual &&
683 git tag -n99 -l | grep "^ *tag.line" >actual &&
684 test_cmp expect actual &&
685 git tag -n99 -l tag-lines >actual &&
686 test_cmp expect actual
689 test_expect_success 'annotations for blobs are empty' '
690 blob=$(git hash-object -w --stdin <<-\EOF
691 Blob paragraph 1.
693 Blob paragraph 2.
695 ) &&
696 git tag tag-blob $blob &&
697 echo "tag-blob " >expect &&
698 git tag -n1 -l tag-blob >actual &&
699 test_cmp expect actual
702 # trying to verify annotated non-signed tags:
704 test_expect_success GPG \
705 'trying to verify an annotated non-signed tag should fail' '
706 tag_exists annotated-tag &&
707 test_must_fail git tag -v annotated-tag
710 test_expect_success GPG \
711 'trying to verify a file-annotated non-signed tag should fail' '
712 tag_exists file-annotated-tag &&
713 test_must_fail git tag -v file-annotated-tag
716 test_expect_success GPG \
717 'trying to verify two annotated non-signed tags should fail' '
718 tag_exists annotated-tag file-annotated-tag &&
719 test_must_fail git tag -v annotated-tag file-annotated-tag
722 # creating and verifying signed tags:
724 get_tag_header signed-tag $commit commit $time >expect
725 echo 'A signed tag message' >>expect
726 echo '-----BEGIN PGP SIGNATURE-----' >>expect
727 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
728 git tag -s -m "A signed tag message" signed-tag &&
729 get_tag_msg signed-tag >actual &&
730 test_cmp expect actual
733 get_tag_header u-signed-tag $commit commit $time >expect
734 echo 'Another message' >>expect
735 echo '-----BEGIN PGP SIGNATURE-----' >>expect
736 test_expect_success GPG 'sign with a given key id' '
738 git tag -u committer@example.com -m "Another message" u-signed-tag &&
739 get_tag_msg u-signed-tag >actual &&
740 test_cmp expect actual
744 test_expect_success GPG 'sign with an unknown id (1)' '
746 test_must_fail git tag -u author@example.com \
747 -m "Another message" o-signed-tag
751 test_expect_success GPG 'sign with an unknown id (2)' '
753 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
757 cat >fakeeditor <<'EOF'
758 #!/bin/sh
759 test -n "$1" && exec >"$1"
760 echo A signed tag message
761 echo from a fake editor.
763 chmod +x fakeeditor
765 get_tag_header implied-sign $commit commit $time >expect
766 ./fakeeditor >>expect
767 echo '-----BEGIN PGP SIGNATURE-----' >>expect
768 test_expect_success GPG '-u implies signed tag' '
769 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
770 get_tag_msg implied-sign >actual &&
771 test_cmp expect actual
774 cat >sigmsgfile <<EOF
775 Another signed tag
776 message in a file.
778 get_tag_header file-signed-tag $commit commit $time >expect
779 cat sigmsgfile >>expect
780 echo '-----BEGIN PGP SIGNATURE-----' >>expect
781 test_expect_success GPG \
782 'creating a signed tag with -F messagefile should succeed' '
783 git tag -s -F sigmsgfile file-signed-tag &&
784 get_tag_msg file-signed-tag >actual &&
785 test_cmp expect actual
788 cat >siginputmsg <<EOF
789 A signed tag message from
790 the standard input
792 get_tag_header stdin-signed-tag $commit commit $time >expect
793 cat siginputmsg >>expect
794 echo '-----BEGIN PGP SIGNATURE-----' >>expect
795 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
796 git tag -s -F - stdin-signed-tag <siginputmsg &&
797 get_tag_msg stdin-signed-tag >actual &&
798 test_cmp expect actual
801 get_tag_header implied-annotate $commit commit $time >expect
802 ./fakeeditor >>expect
803 echo '-----BEGIN PGP SIGNATURE-----' >>expect
804 test_expect_success GPG '-s implies annotated tag' '
805 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
806 get_tag_msg implied-annotate >actual &&
807 test_cmp expect actual
810 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
811 echo "A message" >>expect
812 echo '-----BEGIN PGP SIGNATURE-----' >>expect
813 test_expect_success GPG \
814 'git tag -s implied if configured with tag.forcesignannotated' \
815 'test_config tag.forcesignannotated true &&
816 git tag -m "A message" forcesignannotated-implied-sign &&
817 get_tag_msg forcesignannotated-implied-sign >actual &&
818 test_cmp expect actual
821 test_expect_success GPG \
822 'lightweight with no message when configured with tag.forcesignannotated' \
823 'test_config tag.forcesignannotated true &&
824 git tag forcesignannotated-lightweight &&
825 tag_exists forcesignannotated-lightweight &&
826 test_must_fail git tag -v forcesignannotated-no-message
829 get_tag_header forcesignannotated-annotate $commit commit $time >expect
830 echo "A message" >>expect
831 test_expect_success GPG \
832 'git tag -a disable configured tag.forcesignannotated' \
833 'test_config tag.forcesignannotated true &&
834 git tag -a -m "A message" forcesignannotated-annotate &&
835 get_tag_msg forcesignannotated-annotate >actual &&
836 test_cmp expect actual &&
837 test_must_fail git tag -v forcesignannotated-annotate
840 get_tag_header forcesignannotated-disabled $commit commit $time >expect
841 echo "A message" >>expect
842 echo '-----BEGIN PGP SIGNATURE-----' >>expect
843 test_expect_success GPG \
844 'git tag --sign enable GPG sign' \
845 'test_config tag.forcesignannotated false &&
846 git tag --sign -m "A message" forcesignannotated-disabled &&
847 get_tag_msg forcesignannotated-disabled >actual &&
848 test_cmp expect actual
851 test_expect_success GPG \
852 'trying to create a signed tag with non-existing -F file should fail' '
853 ! test -f nonexistingfile &&
854 ! tag_exists nosigtag &&
855 test_must_fail git tag -s -F nonexistingfile nosigtag &&
856 ! tag_exists nosigtag
859 test_expect_success GPG 'verifying a signed tag should succeed' \
860 'git tag -v signed-tag'
862 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
863 'git tag -v signed-tag file-signed-tag'
865 test_expect_success GPG \
866 'verifying many signed and non-signed tags should fail' '
867 test_must_fail git tag -v signed-tag annotated-tag &&
868 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
869 test_must_fail git tag -v annotated-tag \
870 file-signed-tag file-annotated-tag &&
871 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
874 test_expect_success GPG 'verifying a forged tag should fail' '
875 forged=$(git cat-file tag signed-tag |
876 sed -e "s/signed-tag/forged-tag/" |
877 git mktag) &&
878 git tag forged-tag $forged &&
879 test_must_fail git tag -v forged-tag
882 test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
883 cat >expect <<-\EOF
884 tagname : signed-tag
885 EOF &&
886 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
887 test_cmp expect actual
890 test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
891 cat >expect <<-\EOF
892 tagname : forged-tag
893 EOF &&
894 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
895 test_cmp expect actual
898 # blank and empty messages for signed tags:
900 get_tag_header empty-signed-tag $commit commit $time >expect
901 echo '-----BEGIN PGP SIGNATURE-----' >>expect
902 test_expect_success GPG \
903 'creating a signed tag with an empty -m message should succeed' '
904 git tag -s -m "" empty-signed-tag &&
905 get_tag_msg empty-signed-tag >actual &&
906 test_cmp expect actual &&
907 git tag -v empty-signed-tag
910 >sigemptyfile
911 get_tag_header emptyfile-signed-tag $commit commit $time >expect
912 echo '-----BEGIN PGP SIGNATURE-----' >>expect
913 test_expect_success GPG \
914 'creating a signed tag with an empty -F messagefile should succeed' '
915 git tag -s -F sigemptyfile emptyfile-signed-tag &&
916 get_tag_msg emptyfile-signed-tag >actual &&
917 test_cmp expect actual &&
918 git tag -v emptyfile-signed-tag
921 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
922 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
923 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
924 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
925 get_tag_header blanks-signed-tag $commit commit $time >expect
926 cat >>expect <<EOF
927 Leading blank lines
929 Repeated blank lines
931 Trailing spaces
933 Trailing blank lines
935 echo '-----BEGIN PGP SIGNATURE-----' >>expect
936 test_expect_success GPG \
937 'extra blanks in the message for a signed tag should be removed' '
938 git tag -s -F sigblanksfile blanks-signed-tag &&
939 get_tag_msg blanks-signed-tag >actual &&
940 test_cmp expect actual &&
941 git tag -v blanks-signed-tag
944 get_tag_header blank-signed-tag $commit commit $time >expect
945 echo '-----BEGIN PGP SIGNATURE-----' >>expect
946 test_expect_success GPG \
947 'creating a signed tag with a blank -m message should succeed' '
948 git tag -s -m " " blank-signed-tag &&
949 get_tag_msg blank-signed-tag >actual &&
950 test_cmp expect actual &&
951 git tag -v blank-signed-tag
954 echo ' ' >sigblankfile
955 echo '' >>sigblankfile
956 echo ' ' >>sigblankfile
957 get_tag_header blankfile-signed-tag $commit commit $time >expect
958 echo '-----BEGIN PGP SIGNATURE-----' >>expect
959 test_expect_success GPG \
960 'creating a signed tag with blank -F file with spaces should succeed' '
961 git tag -s -F sigblankfile blankfile-signed-tag &&
962 get_tag_msg blankfile-signed-tag >actual &&
963 test_cmp expect actual &&
964 git tag -v blankfile-signed-tag
967 printf ' ' >sigblanknonlfile
968 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
969 echo '-----BEGIN PGP SIGNATURE-----' >>expect
970 test_expect_success GPG \
971 'creating a signed tag with spaces and no newline should succeed' '
972 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
973 get_tag_msg blanknonlfile-signed-tag >actual &&
974 test_cmp expect actual &&
975 git tag -v signed-tag
978 # messages with commented lines for signed tags:
980 cat >sigcommentsfile <<EOF
981 # A comment
983 ############
984 The message.
985 ############
986 One line.
989 # commented lines
990 # commented lines
992 Another line.
993 # comments
995 Last line.
997 get_tag_header comments-signed-tag $commit commit $time >expect
998 cat >>expect <<EOF
999 The message.
1000 One line.
1002 Another line.
1004 Last line.
1006 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1007 test_expect_success GPG \
1008 'creating a signed tag with a -F file with #comments should succeed' '
1009 git tag -s -F sigcommentsfile comments-signed-tag &&
1010 get_tag_msg comments-signed-tag >actual &&
1011 test_cmp expect actual &&
1012 git tag -v comments-signed-tag
1015 get_tag_header comment-signed-tag $commit commit $time >expect
1016 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017 test_expect_success GPG \
1018 'creating a signed tag with #commented -m message should succeed' '
1019 git tag -s -m "#comment" comment-signed-tag &&
1020 get_tag_msg comment-signed-tag >actual &&
1021 test_cmp expect actual &&
1022 git tag -v comment-signed-tag
1025 echo '#comment' >sigcommentfile
1026 echo '' >>sigcommentfile
1027 echo '####' >>sigcommentfile
1028 get_tag_header commentfile-signed-tag $commit commit $time >expect
1029 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1030 test_expect_success GPG \
1031 'creating a signed tag with #commented -F messagefile should succeed' '
1032 git tag -s -F sigcommentfile commentfile-signed-tag &&
1033 get_tag_msg commentfile-signed-tag >actual &&
1034 test_cmp expect actual &&
1035 git tag -v commentfile-signed-tag
1038 printf '#comment' >sigcommentnonlfile
1039 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1040 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1041 test_expect_success GPG \
1042 'creating a signed tag with a #comment and no newline should succeed' '
1043 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1044 get_tag_msg commentnonlfile-signed-tag >actual &&
1045 test_cmp expect actual &&
1046 git tag -v commentnonlfile-signed-tag
1049 # listing messages for signed tags:
1051 test_expect_success GPG \
1052 'listing the one-line message of a signed tag should succeed' '
1053 git tag -s -m "A message line signed" stag-one-line &&
1055 echo "stag-one-line" >expect &&
1056 git tag -l | grep "^stag-one-line" >actual &&
1057 test_cmp expect actual &&
1058 git tag -n0 -l | grep "^stag-one-line" >actual &&
1059 test_cmp expect actual &&
1060 git tag -n0 -l stag-one-line >actual &&
1061 test_cmp expect actual &&
1063 echo "stag-one-line A message line signed" >expect &&
1064 git tag -n1 -l | grep "^stag-one-line" >actual &&
1065 test_cmp expect actual &&
1066 git tag -n -l | grep "^stag-one-line" >actual &&
1067 test_cmp expect actual &&
1068 git tag -n1 -l stag-one-line >actual &&
1069 test_cmp expect actual &&
1070 git tag -n2 -l stag-one-line >actual &&
1071 test_cmp expect actual &&
1072 git tag -n999 -l stag-one-line >actual &&
1073 test_cmp expect actual
1076 test_expect_success GPG \
1077 'listing the zero-lines message of a signed tag should succeed' '
1078 git tag -s -m "" stag-zero-lines &&
1080 echo "stag-zero-lines" >expect &&
1081 git tag -l | grep "^stag-zero-lines" >actual &&
1082 test_cmp expect actual &&
1083 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1084 test_cmp expect actual &&
1085 git tag -n0 -l stag-zero-lines >actual &&
1086 test_cmp expect actual &&
1088 echo "stag-zero-lines " >expect &&
1089 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1090 test_cmp expect actual &&
1091 git tag -n -l | grep "^stag-zero-lines" >actual &&
1092 test_cmp expect actual &&
1093 git tag -n1 -l stag-zero-lines >actual &&
1094 test_cmp expect actual &&
1095 git tag -n2 -l stag-zero-lines >actual &&
1096 test_cmp expect actual &&
1097 git tag -n999 -l stag-zero-lines >actual &&
1098 test_cmp expect actual
1101 echo 'stag line one' >sigtagmsg
1102 echo 'stag line two' >>sigtagmsg
1103 echo 'stag line three' >>sigtagmsg
1104 test_expect_success GPG \
1105 'listing many message lines of a signed tag should succeed' '
1106 git tag -s -F sigtagmsg stag-lines &&
1108 echo "stag-lines" >expect &&
1109 git tag -l | grep "^stag-lines" >actual &&
1110 test_cmp expect actual &&
1111 git tag -n0 -l | grep "^stag-lines" >actual &&
1112 test_cmp expect actual &&
1113 git tag -n0 -l stag-lines >actual &&
1114 test_cmp expect actual &&
1116 echo "stag-lines stag line one" >expect &&
1117 git tag -n1 -l | grep "^stag-lines" >actual &&
1118 test_cmp expect actual &&
1119 git tag -n -l | grep "^stag-lines" >actual &&
1120 test_cmp expect actual &&
1121 git tag -n1 -l stag-lines >actual &&
1122 test_cmp expect actual &&
1124 echo " stag line two" >>expect &&
1125 git tag -n2 -l | grep "^ *stag.line" >actual &&
1126 test_cmp expect actual &&
1127 git tag -n2 -l stag-lines >actual &&
1128 test_cmp expect actual &&
1130 echo " stag line three" >>expect &&
1131 git tag -n3 -l | grep "^ *stag.line" >actual &&
1132 test_cmp expect actual &&
1133 git tag -n3 -l stag-lines >actual &&
1134 test_cmp expect actual &&
1135 git tag -n4 -l | grep "^ *stag.line" >actual &&
1136 test_cmp expect actual &&
1137 git tag -n4 -l stag-lines >actual &&
1138 test_cmp expect actual &&
1139 git tag -n99 -l | grep "^ *stag.line" >actual &&
1140 test_cmp expect actual &&
1141 git tag -n99 -l stag-lines >actual &&
1142 test_cmp expect actual
1145 # tags pointing to objects different from commits:
1147 tree=$(git rev-parse HEAD^{tree})
1148 blob=$(git rev-parse HEAD:foo)
1149 tag=$(git rev-parse signed-tag 2>/dev/null)
1151 get_tag_header tree-signed-tag $tree tree $time >expect
1152 echo "A message for a tree" >>expect
1153 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1154 test_expect_success GPG \
1155 'creating a signed tag pointing to a tree should succeed' '
1156 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1157 get_tag_msg tree-signed-tag >actual &&
1158 test_cmp expect actual
1161 get_tag_header blob-signed-tag $blob blob $time >expect
1162 echo "A message for a blob" >>expect
1163 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1164 test_expect_success GPG \
1165 'creating a signed tag pointing to a blob should succeed' '
1166 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1167 get_tag_msg blob-signed-tag >actual &&
1168 test_cmp expect actual
1171 get_tag_header tag-signed-tag $tag tag $time >expect
1172 echo "A message for another tag" >>expect
1173 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1174 test_expect_success GPG \
1175 'creating a signed tag pointing to another tag should succeed' '
1176 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1177 get_tag_msg tag-signed-tag >actual &&
1178 test_cmp expect actual
1181 # usage with rfc1991 signatures
1182 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1183 echo "RFC1991 signed tag" >>expect
1184 echo '-----BEGIN PGP MESSAGE-----' >>expect
1185 test_expect_success GPG,RFC1991 \
1186 'creating a signed tag with rfc1991' '
1187 echo "rfc1991" >gpghome/gpg.conf &&
1188 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1189 get_tag_msg rfc1991-signed-tag >actual &&
1190 test_cmp expect actual
1193 cat >fakeeditor <<'EOF'
1194 #!/bin/sh
1195 cp "$1" actual
1197 chmod +x fakeeditor
1199 test_expect_success GPG,RFC1991 \
1200 'reediting a signed tag body omits signature' '
1201 echo "rfc1991" >gpghome/gpg.conf &&
1202 echo "RFC1991 signed tag" >expect &&
1203 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1204 test_cmp expect actual
1207 test_expect_success GPG,RFC1991 \
1208 'verifying rfc1991 signature' '
1209 echo "rfc1991" >gpghome/gpg.conf &&
1210 git tag -v rfc1991-signed-tag
1213 test_expect_success GPG,RFC1991 \
1214 'list tag with rfc1991 signature' '
1215 echo "rfc1991" >gpghome/gpg.conf &&
1216 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1217 git tag -l -n1 rfc1991-signed-tag >actual &&
1218 test_cmp expect actual &&
1219 git tag -l -n2 rfc1991-signed-tag >actual &&
1220 test_cmp expect actual &&
1221 git tag -l -n999 rfc1991-signed-tag >actual &&
1222 test_cmp expect actual
1225 rm -f gpghome/gpg.conf
1227 test_expect_success GPG,RFC1991 \
1228 'verifying rfc1991 signature without --rfc1991' '
1229 git tag -v rfc1991-signed-tag
1232 test_expect_success GPG,RFC1991 \
1233 'list tag with rfc1991 signature without --rfc1991' '
1234 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1235 git tag -l -n1 rfc1991-signed-tag >actual &&
1236 test_cmp expect actual &&
1237 git tag -l -n2 rfc1991-signed-tag >actual &&
1238 test_cmp expect actual &&
1239 git tag -l -n999 rfc1991-signed-tag >actual &&
1240 test_cmp expect actual
1243 test_expect_success GPG,RFC1991 \
1244 'reediting a signed tag body omits signature' '
1245 echo "RFC1991 signed tag" >expect &&
1246 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1247 test_cmp expect actual
1250 # try to sign with bad user.signingkey
1251 test_expect_success GPG \
1252 'git tag -s fails if gpg is misconfigured (bad key)' \
1253 'test_config user.signingkey BobTheMouse &&
1254 test_must_fail git tag -s -m tail tag-gpg-failure'
1256 # try to produce invalid signature
1257 test_expect_success GPG \
1258 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1259 'test_config gpg.program echo &&
1260 test_must_fail git tag -s -m tail tag-gpg-failure'
1263 # try to verify without gpg:
1265 rm -rf gpghome
1266 test_expect_success GPG \
1267 'verify signed tag fails when public key is not present' \
1268 'test_must_fail git tag -v signed-tag'
1270 test_expect_success \
1271 'git tag -a fails if tag annotation is empty' '
1272 ! (GIT_EDITOR=cat git tag -a initial-comment)
1275 test_expect_success \
1276 'message in editor has initial comment' '
1277 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1280 test_expect_success 'message in editor has initial comment: first line' '
1281 # check the first line --- should be empty
1282 echo >first.expect &&
1283 sed -e 1q <actual >first.actual &&
1284 test_i18ncmp first.expect first.actual
1287 test_expect_success \
1288 'message in editor has initial comment: remainder' '
1289 # remove commented lines from the remainder -- should be empty
1290 >rest.expect &&
1291 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1292 test_cmp rest.expect rest.actual
1295 get_tag_header reuse $commit commit $time >expect
1296 echo "An annotation to be reused" >> expect
1297 test_expect_success \
1298 'overwriting an annoted tag should use its previous body' '
1299 git tag -a -m "An annotation to be reused" reuse &&
1300 GIT_EDITOR=true git tag -f -a reuse &&
1301 get_tag_msg reuse >actual &&
1302 test_cmp expect actual
1305 test_expect_success 'filename for the message is relative to cwd' '
1306 mkdir subdir &&
1307 echo "Tag message in top directory" >msgfile-5 &&
1308 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1310 cd subdir &&
1311 git tag -a -F msgfile-5 tag-from-subdir
1312 ) &&
1313 git cat-file tag tag-from-subdir | grep "in sub directory"
1316 test_expect_success 'filename for the message is relative to cwd' '
1317 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1319 cd subdir &&
1320 git tag -a -F msgfile-6 tag-from-subdir-2
1321 ) &&
1322 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1325 # create a few more commits to test --contains
1327 hash1=$(git rev-parse HEAD)
1329 test_expect_success 'creating second commit and tag' '
1330 echo foo-2.0 >foo &&
1331 git add foo &&
1332 git commit -m second &&
1333 git tag v2.0
1336 hash2=$(git rev-parse HEAD)
1338 test_expect_success 'creating third commit without tag' '
1339 echo foo-dev >foo &&
1340 git add foo &&
1341 git commit -m third
1344 hash3=$(git rev-parse HEAD)
1346 # simple linear checks of --continue
1348 cat > expected <<EOF
1349 v0.2.1
1350 v1.0
1351 v1.0.1
1352 v1.1.3
1353 v2.0
1356 test_expect_success 'checking that first commit is in all tags (hash)' "
1357 git tag -l --contains $hash1 v* >actual &&
1358 test_cmp expected actual
1361 # other ways of specifying the commit
1362 test_expect_success 'checking that first commit is in all tags (tag)' "
1363 git tag -l --contains v1.0 v* >actual &&
1364 test_cmp expected actual
1367 test_expect_success 'checking that first commit is in all tags (relative)' "
1368 git tag -l --contains HEAD~2 v* >actual &&
1369 test_cmp expected actual
1372 cat > expected <<EOF
1373 v2.0
1376 test_expect_success 'checking that second commit only has one tag' "
1377 git tag -l --contains $hash2 v* >actual &&
1378 test_cmp expected actual
1382 cat > expected <<EOF
1385 test_expect_success 'checking that third commit has no tags' "
1386 git tag -l --contains $hash3 v* >actual &&
1387 test_cmp expected actual
1390 # how about a simple merge?
1392 test_expect_success 'creating simple branch' '
1393 git branch stable v2.0 &&
1394 git checkout stable &&
1395 echo foo-3.0 > foo &&
1396 git commit foo -m fourth &&
1397 git tag v3.0
1400 hash4=$(git rev-parse HEAD)
1402 cat > expected <<EOF
1403 v3.0
1406 test_expect_success 'checking that branch head only has one tag' "
1407 git tag -l --contains $hash4 v* >actual &&
1408 test_cmp expected actual
1411 test_expect_success 'merging original branch into this branch' '
1412 git merge --strategy=ours master &&
1413 git tag v4.0
1416 cat > expected <<EOF
1417 v4.0
1420 test_expect_success 'checking that original branch head has one tag now' "
1421 git tag -l --contains $hash3 v* >actual &&
1422 test_cmp expected actual
1425 cat > expected <<EOF
1426 v0.2.1
1427 v1.0
1428 v1.0.1
1429 v1.1.3
1430 v2.0
1431 v3.0
1432 v4.0
1435 test_expect_success 'checking that initial commit is in all tags' "
1436 git tag -l --contains $hash1 v* >actual &&
1437 test_cmp expected actual
1440 # mixing modes and options:
1442 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1443 test_must_fail git tag -a &&
1444 test_must_fail git tag -l -v &&
1445 test_must_fail git tag -n 100 &&
1446 test_must_fail git tag -l -m msg &&
1447 test_must_fail git tag -l -F some file &&
1448 test_must_fail git tag -v -s
1451 # check points-at
1453 test_expect_success '--points-at cannot be used in non-list mode' '
1454 test_must_fail git tag --points-at=v4.0 foo
1457 test_expect_success '--points-at finds lightweight tags' '
1458 echo v4.0 >expect &&
1459 git tag --points-at v4.0 >actual &&
1460 test_cmp expect actual
1463 test_expect_success '--points-at finds annotated tags of commits' '
1464 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1465 echo annotated-v4.0 >expect &&
1466 git tag -l --points-at v4.0 "annotated*" >actual &&
1467 test_cmp expect actual
1470 test_expect_success '--points-at finds annotated tags of tags' '
1471 git tag -m "describing the v4.0 tag object" \
1472 annotated-again-v4.0 annotated-v4.0 &&
1473 cat >expect <<-\EOF &&
1474 annotated-again-v4.0
1475 annotated-v4.0
1477 git tag --points-at=annotated-v4.0 >actual &&
1478 test_cmp expect actual
1481 test_expect_success 'multiple --points-at are OR-ed together' '
1482 cat >expect <<-\EOF &&
1483 v2.0
1484 v3.0
1486 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1487 test_cmp expect actual
1490 test_expect_success 'lexical sort' '
1491 git tag foo1.3 &&
1492 git tag foo1.6 &&
1493 git tag foo1.10 &&
1494 git tag -l --sort=refname "foo*" >actual &&
1495 cat >expect <<-\EOF &&
1496 foo1.10
1497 foo1.3
1498 foo1.6
1500 test_cmp expect actual
1503 test_expect_success 'version sort' '
1504 git tag -l --sort=version:refname "foo*" >actual &&
1505 cat >expect <<-\EOF &&
1506 foo1.3
1507 foo1.6
1508 foo1.10
1510 test_cmp expect actual
1513 test_expect_success 'reverse version sort' '
1514 git tag -l --sort=-version:refname "foo*" >actual &&
1515 cat >expect <<-\EOF &&
1516 foo1.10
1517 foo1.6
1518 foo1.3
1520 test_cmp expect actual
1523 test_expect_success 'reverse lexical sort' '
1524 git tag -l --sort=-refname "foo*" >actual &&
1525 cat >expect <<-\EOF &&
1526 foo1.6
1527 foo1.3
1528 foo1.10
1530 test_cmp expect actual
1533 test_expect_success 'configured lexical sort' '
1534 test_config tag.sort "v:refname" &&
1535 git tag -l "foo*" >actual &&
1536 cat >expect <<-\EOF &&
1537 foo1.3
1538 foo1.6
1539 foo1.10
1541 test_cmp expect actual
1544 test_expect_success 'option override configured sort' '
1545 test_config tag.sort "v:refname" &&
1546 git tag -l --sort=-refname "foo*" >actual &&
1547 cat >expect <<-\EOF &&
1548 foo1.6
1549 foo1.3
1550 foo1.10
1552 test_cmp expect actual
1555 test_expect_success 'invalid sort parameter on command line' '
1556 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1559 test_expect_success 'invalid sort parameter in configuratoin' '
1560 test_config tag.sort "v:notvalid" &&
1561 test_must_fail git tag -l "foo*"
1564 test_expect_success 'version sort with prerelease reordering' '
1565 test_config versionsort.prereleaseSuffix -rc &&
1566 git tag foo1.6-rc1 &&
1567 git tag foo1.6-rc2 &&
1568 git tag -l --sort=version:refname "foo*" >actual &&
1569 cat >expect <<-\EOF &&
1570 foo1.3
1571 foo1.6-rc1
1572 foo1.6-rc2
1573 foo1.6
1574 foo1.10
1576 test_cmp expect actual
1579 test_expect_success 'reverse version sort with prerelease reordering' '
1580 test_config versionsort.prereleaseSuffix -rc &&
1581 git tag -l --sort=-version:refname "foo*" >actual &&
1582 cat >expect <<-\EOF &&
1583 foo1.10
1584 foo1.6
1585 foo1.6-rc2
1586 foo1.6-rc1
1587 foo1.3
1589 test_cmp expect actual
1592 test_expect_success 'version sort with prerelease reordering and common leading character' '
1593 test_config versionsort.prereleaseSuffix -before &&
1594 git tag foo1.7-before1 &&
1595 git tag foo1.7 &&
1596 git tag foo1.7-after1 &&
1597 git tag -l --sort=version:refname "foo1.7*" >actual &&
1598 cat >expect <<-\EOF &&
1599 foo1.7-before1
1600 foo1.7
1601 foo1.7-after1
1603 test_cmp expect actual
1606 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1607 test_config versionsort.prereleaseSuffix -before &&
1608 git config --add versionsort.prereleaseSuffix -after &&
1609 git tag -l --sort=version:refname "foo1.7*" >actual &&
1610 cat >expect <<-\EOF &&
1611 foo1.7-before1
1612 foo1.7-after1
1613 foo1.7
1615 test_cmp expect actual
1618 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1619 test_config versionsort.prereleaseSuffix -bar &&
1620 git config --add versionsort.prereleaseSuffix -foo-baz &&
1621 git config --add versionsort.prereleaseSuffix -foo-bar &&
1622 git tag foo1.8-foo-bar &&
1623 git tag foo1.8-foo-baz &&
1624 git tag foo1.8 &&
1625 git tag -l --sort=version:refname "foo1.8*" >actual &&
1626 cat >expect <<-\EOF &&
1627 foo1.8-foo-baz
1628 foo1.8-foo-bar
1629 foo1.8
1631 test_cmp expect actual
1634 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1635 test_config versionsort.prereleaseSuffix -pre &&
1636 git config --add versionsort.prereleaseSuffix -prerelease &&
1637 git tag foo1.9-pre1 &&
1638 git tag foo1.9-pre2 &&
1639 git tag foo1.9-prerelease1 &&
1640 git tag -l --sort=version:refname "foo1.9*" >actual &&
1641 cat >expect <<-\EOF &&
1642 foo1.9-pre1
1643 foo1.9-pre2
1644 foo1.9-prerelease1
1646 test_cmp expect actual
1649 test_expect_success 'version sort with general suffix reordering' '
1650 test_config versionsort.suffix -alpha &&
1651 git config --add versionsort.suffix -beta &&
1652 git config --add versionsort.suffix "" &&
1653 git config --add versionsort.suffix -gamma &&
1654 git config --add versionsort.suffix -delta &&
1655 git tag foo1.10-alpha &&
1656 git tag foo1.10-beta &&
1657 git tag foo1.10-gamma &&
1658 git tag foo1.10-delta &&
1659 git tag foo1.10-unlisted-suffix &&
1660 git tag -l --sort=version:refname "foo1.10*" >actual &&
1661 cat >expect <<-\EOF &&
1662 foo1.10-alpha
1663 foo1.10-beta
1664 foo1.10
1665 foo1.10-unlisted-suffix
1666 foo1.10-gamma
1667 foo1.10-delta
1669 test_cmp expect actual
1672 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1673 test_config versionsort.suffix -before &&
1674 test_config versionsort.prereleaseSuffix -after &&
1675 git tag -l --sort=version:refname "foo1.7*" >actual &&
1676 cat >expect <<-\EOF &&
1677 foo1.7-before1
1678 foo1.7
1679 foo1.7-after1
1681 test_cmp expect actual
1684 test_expect_success 'version sort with very long prerelease suffix' '
1685 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1686 git tag -l --sort=version:refname
1689 run_with_limited_stack () {
1690 (ulimit -s 128 && "$@")
1693 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1695 # we require ulimit, this excludes Windows
1696 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1697 >expect &&
1698 i=1 &&
1699 while test $i -lt 8000
1701 echo "commit refs/heads/master
1702 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1703 data <<EOF
1704 commit #$i
1705 EOF"
1706 test $i = 1 && echo "from refs/heads/master^0"
1707 i=$(($i + 1))
1708 done | git fast-import &&
1709 git checkout master &&
1710 git tag far-far-away HEAD^ &&
1711 run_with_limited_stack git tag --contains HEAD >actual &&
1712 test_cmp expect actual
1715 test_expect_success '--format should list tags as per format given' '
1716 cat >expect <<-\EOF &&
1717 refname : refs/tags/v1.0
1718 refname : refs/tags/v1.0.1
1719 refname : refs/tags/v1.1.3
1721 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1722 test_cmp expect actual
1725 test_expect_success 'setup --merged test tags' '
1726 git tag mergetest-1 HEAD~2 &&
1727 git tag mergetest-2 HEAD~1 &&
1728 git tag mergetest-3 HEAD
1731 test_expect_success '--merged cannot be used in non-list mode' '
1732 test_must_fail git tag --merged=mergetest-2 foo
1735 test_expect_success '--merged shows merged tags' '
1736 cat >expect <<-\EOF &&
1737 mergetest-1
1738 mergetest-2
1740 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1741 test_cmp expect actual
1744 test_expect_success '--no-merged show unmerged tags' '
1745 cat >expect <<-\EOF &&
1746 mergetest-3
1748 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1749 test_cmp expect actual
1752 test_expect_success 'ambiguous branch/tags not marked' '
1753 git tag ambiguous &&
1754 git branch ambiguous &&
1755 echo ambiguous >expect &&
1756 git tag -l ambiguous >actual &&
1757 test_cmp expect actual
1760 test_done