apply: update line lengths for --inaccurate-eof
[git/raj.git] / t / t7004-tag.sh
blobb8ad076c25680cad1f9faa1de544980c78547f6c
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 GPG 'verifying a proper tag with --format pass and format accordingly' '
883 cat >expect <<-\EOF &&
884 tagname : signed-tag
886 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
887 test_cmp expect actual
890 test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
891 >expect &&
892 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
893 test_cmp expect actual
896 # blank and empty messages for signed tags:
898 get_tag_header empty-signed-tag $commit commit $time >expect
899 echo '-----BEGIN PGP SIGNATURE-----' >>expect
900 test_expect_success GPG \
901 'creating a signed tag with an empty -m message should succeed' '
902 git tag -s -m "" empty-signed-tag &&
903 get_tag_msg empty-signed-tag >actual &&
904 test_cmp expect actual &&
905 git tag -v empty-signed-tag
908 >sigemptyfile
909 get_tag_header emptyfile-signed-tag $commit commit $time >expect
910 echo '-----BEGIN PGP SIGNATURE-----' >>expect
911 test_expect_success GPG \
912 'creating a signed tag with an empty -F messagefile should succeed' '
913 git tag -s -F sigemptyfile emptyfile-signed-tag &&
914 get_tag_msg emptyfile-signed-tag >actual &&
915 test_cmp expect actual &&
916 git tag -v emptyfile-signed-tag
919 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
920 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
921 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
922 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
923 get_tag_header blanks-signed-tag $commit commit $time >expect
924 cat >>expect <<EOF
925 Leading blank lines
927 Repeated blank lines
929 Trailing spaces
931 Trailing blank lines
933 echo '-----BEGIN PGP SIGNATURE-----' >>expect
934 test_expect_success GPG \
935 'extra blanks in the message for a signed tag should be removed' '
936 git tag -s -F sigblanksfile blanks-signed-tag &&
937 get_tag_msg blanks-signed-tag >actual &&
938 test_cmp expect actual &&
939 git tag -v blanks-signed-tag
942 get_tag_header blank-signed-tag $commit commit $time >expect
943 echo '-----BEGIN PGP SIGNATURE-----' >>expect
944 test_expect_success GPG \
945 'creating a signed tag with a blank -m message should succeed' '
946 git tag -s -m " " blank-signed-tag &&
947 get_tag_msg blank-signed-tag >actual &&
948 test_cmp expect actual &&
949 git tag -v blank-signed-tag
952 echo ' ' >sigblankfile
953 echo '' >>sigblankfile
954 echo ' ' >>sigblankfile
955 get_tag_header blankfile-signed-tag $commit commit $time >expect
956 echo '-----BEGIN PGP SIGNATURE-----' >>expect
957 test_expect_success GPG \
958 'creating a signed tag with blank -F file with spaces should succeed' '
959 git tag -s -F sigblankfile blankfile-signed-tag &&
960 get_tag_msg blankfile-signed-tag >actual &&
961 test_cmp expect actual &&
962 git tag -v blankfile-signed-tag
965 printf ' ' >sigblanknonlfile
966 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
967 echo '-----BEGIN PGP SIGNATURE-----' >>expect
968 test_expect_success GPG \
969 'creating a signed tag with spaces and no newline should succeed' '
970 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
971 get_tag_msg blanknonlfile-signed-tag >actual &&
972 test_cmp expect actual &&
973 git tag -v signed-tag
976 # messages with commented lines for signed tags:
978 cat >sigcommentsfile <<EOF
979 # A comment
981 ############
982 The message.
983 ############
984 One line.
987 # commented lines
988 # commented lines
990 Another line.
991 # comments
993 Last line.
995 get_tag_header comments-signed-tag $commit commit $time >expect
996 cat >>expect <<EOF
997 The message.
998 One line.
1000 Another line.
1002 Last line.
1004 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1005 test_expect_success GPG \
1006 'creating a signed tag with a -F file with #comments should succeed' '
1007 git tag -s -F sigcommentsfile comments-signed-tag &&
1008 get_tag_msg comments-signed-tag >actual &&
1009 test_cmp expect actual &&
1010 git tag -v comments-signed-tag
1013 get_tag_header comment-signed-tag $commit commit $time >expect
1014 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1015 test_expect_success GPG \
1016 'creating a signed tag with #commented -m message should succeed' '
1017 git tag -s -m "#comment" comment-signed-tag &&
1018 get_tag_msg comment-signed-tag >actual &&
1019 test_cmp expect actual &&
1020 git tag -v comment-signed-tag
1023 echo '#comment' >sigcommentfile
1024 echo '' >>sigcommentfile
1025 echo '####' >>sigcommentfile
1026 get_tag_header commentfile-signed-tag $commit commit $time >expect
1027 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1028 test_expect_success GPG \
1029 'creating a signed tag with #commented -F messagefile should succeed' '
1030 git tag -s -F sigcommentfile commentfile-signed-tag &&
1031 get_tag_msg commentfile-signed-tag >actual &&
1032 test_cmp expect actual &&
1033 git tag -v commentfile-signed-tag
1036 printf '#comment' >sigcommentnonlfile
1037 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1038 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1039 test_expect_success GPG \
1040 'creating a signed tag with a #comment and no newline should succeed' '
1041 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1042 get_tag_msg commentnonlfile-signed-tag >actual &&
1043 test_cmp expect actual &&
1044 git tag -v commentnonlfile-signed-tag
1047 # listing messages for signed tags:
1049 test_expect_success GPG \
1050 'listing the one-line message of a signed tag should succeed' '
1051 git tag -s -m "A message line signed" stag-one-line &&
1053 echo "stag-one-line" >expect &&
1054 git tag -l | grep "^stag-one-line" >actual &&
1055 test_cmp expect actual &&
1056 git tag -n0 -l | grep "^stag-one-line" >actual &&
1057 test_cmp expect actual &&
1058 git tag -n0 -l stag-one-line >actual &&
1059 test_cmp expect actual &&
1061 echo "stag-one-line A message line signed" >expect &&
1062 git tag -n1 -l | grep "^stag-one-line" >actual &&
1063 test_cmp expect actual &&
1064 git tag -n -l | grep "^stag-one-line" >actual &&
1065 test_cmp expect actual &&
1066 git tag -n1 -l stag-one-line >actual &&
1067 test_cmp expect actual &&
1068 git tag -n2 -l stag-one-line >actual &&
1069 test_cmp expect actual &&
1070 git tag -n999 -l stag-one-line >actual &&
1071 test_cmp expect actual
1074 test_expect_success GPG \
1075 'listing the zero-lines message of a signed tag should succeed' '
1076 git tag -s -m "" stag-zero-lines &&
1078 echo "stag-zero-lines" >expect &&
1079 git tag -l | grep "^stag-zero-lines" >actual &&
1080 test_cmp expect actual &&
1081 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1082 test_cmp expect actual &&
1083 git tag -n0 -l stag-zero-lines >actual &&
1084 test_cmp expect actual &&
1086 echo "stag-zero-lines " >expect &&
1087 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1088 test_cmp expect actual &&
1089 git tag -n -l | grep "^stag-zero-lines" >actual &&
1090 test_cmp expect actual &&
1091 git tag -n1 -l stag-zero-lines >actual &&
1092 test_cmp expect actual &&
1093 git tag -n2 -l stag-zero-lines >actual &&
1094 test_cmp expect actual &&
1095 git tag -n999 -l stag-zero-lines >actual &&
1096 test_cmp expect actual
1099 echo 'stag line one' >sigtagmsg
1100 echo 'stag line two' >>sigtagmsg
1101 echo 'stag line three' >>sigtagmsg
1102 test_expect_success GPG \
1103 'listing many message lines of a signed tag should succeed' '
1104 git tag -s -F sigtagmsg stag-lines &&
1106 echo "stag-lines" >expect &&
1107 git tag -l | grep "^stag-lines" >actual &&
1108 test_cmp expect actual &&
1109 git tag -n0 -l | grep "^stag-lines" >actual &&
1110 test_cmp expect actual &&
1111 git tag -n0 -l stag-lines >actual &&
1112 test_cmp expect actual &&
1114 echo "stag-lines stag line one" >expect &&
1115 git tag -n1 -l | grep "^stag-lines" >actual &&
1116 test_cmp expect actual &&
1117 git tag -n -l | grep "^stag-lines" >actual &&
1118 test_cmp expect actual &&
1119 git tag -n1 -l stag-lines >actual &&
1120 test_cmp expect actual &&
1122 echo " stag line two" >>expect &&
1123 git tag -n2 -l | grep "^ *stag.line" >actual &&
1124 test_cmp expect actual &&
1125 git tag -n2 -l stag-lines >actual &&
1126 test_cmp expect actual &&
1128 echo " stag line three" >>expect &&
1129 git tag -n3 -l | grep "^ *stag.line" >actual &&
1130 test_cmp expect actual &&
1131 git tag -n3 -l stag-lines >actual &&
1132 test_cmp expect actual &&
1133 git tag -n4 -l | grep "^ *stag.line" >actual &&
1134 test_cmp expect actual &&
1135 git tag -n4 -l stag-lines >actual &&
1136 test_cmp expect actual &&
1137 git tag -n99 -l | grep "^ *stag.line" >actual &&
1138 test_cmp expect actual &&
1139 git tag -n99 -l stag-lines >actual &&
1140 test_cmp expect actual
1143 # tags pointing to objects different from commits:
1145 tree=$(git rev-parse HEAD^{tree})
1146 blob=$(git rev-parse HEAD:foo)
1147 tag=$(git rev-parse signed-tag 2>/dev/null)
1149 get_tag_header tree-signed-tag $tree tree $time >expect
1150 echo "A message for a tree" >>expect
1151 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1152 test_expect_success GPG \
1153 'creating a signed tag pointing to a tree should succeed' '
1154 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1155 get_tag_msg tree-signed-tag >actual &&
1156 test_cmp expect actual
1159 get_tag_header blob-signed-tag $blob blob $time >expect
1160 echo "A message for a blob" >>expect
1161 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1162 test_expect_success GPG \
1163 'creating a signed tag pointing to a blob should succeed' '
1164 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1165 get_tag_msg blob-signed-tag >actual &&
1166 test_cmp expect actual
1169 get_tag_header tag-signed-tag $tag tag $time >expect
1170 echo "A message for another tag" >>expect
1171 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1172 test_expect_success GPG \
1173 'creating a signed tag pointing to another tag should succeed' '
1174 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1175 get_tag_msg tag-signed-tag >actual &&
1176 test_cmp expect actual
1179 # usage with rfc1991 signatures
1180 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1181 echo "RFC1991 signed tag" >>expect
1182 echo '-----BEGIN PGP MESSAGE-----' >>expect
1183 test_expect_success GPG,RFC1991 \
1184 'creating a signed tag with rfc1991' '
1185 echo "rfc1991" >gpghome/gpg.conf &&
1186 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1187 get_tag_msg rfc1991-signed-tag >actual &&
1188 test_cmp expect actual
1191 cat >fakeeditor <<'EOF'
1192 #!/bin/sh
1193 cp "$1" actual
1195 chmod +x fakeeditor
1197 test_expect_success GPG,RFC1991 \
1198 'reediting a signed tag body omits signature' '
1199 echo "rfc1991" >gpghome/gpg.conf &&
1200 echo "RFC1991 signed tag" >expect &&
1201 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1202 test_cmp expect actual
1205 test_expect_success GPG,RFC1991 \
1206 'verifying rfc1991 signature' '
1207 echo "rfc1991" >gpghome/gpg.conf &&
1208 git tag -v rfc1991-signed-tag
1211 test_expect_success GPG,RFC1991 \
1212 'list tag with rfc1991 signature' '
1213 echo "rfc1991" >gpghome/gpg.conf &&
1214 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1215 git tag -l -n1 rfc1991-signed-tag >actual &&
1216 test_cmp expect actual &&
1217 git tag -l -n2 rfc1991-signed-tag >actual &&
1218 test_cmp expect actual &&
1219 git tag -l -n999 rfc1991-signed-tag >actual &&
1220 test_cmp expect actual
1223 rm -f gpghome/gpg.conf
1225 test_expect_success GPG,RFC1991 \
1226 'verifying rfc1991 signature without --rfc1991' '
1227 git tag -v rfc1991-signed-tag
1230 test_expect_success GPG,RFC1991 \
1231 'list tag with rfc1991 signature without --rfc1991' '
1232 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1233 git tag -l -n1 rfc1991-signed-tag >actual &&
1234 test_cmp expect actual &&
1235 git tag -l -n2 rfc1991-signed-tag >actual &&
1236 test_cmp expect actual &&
1237 git tag -l -n999 rfc1991-signed-tag >actual &&
1238 test_cmp expect actual
1241 test_expect_success GPG,RFC1991 \
1242 'reediting a signed tag body omits signature' '
1243 echo "RFC1991 signed tag" >expect &&
1244 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1245 test_cmp expect actual
1248 # try to sign with bad user.signingkey
1249 test_expect_success GPG \
1250 'git tag -s fails if gpg is misconfigured (bad key)' \
1251 'test_config user.signingkey BobTheMouse &&
1252 test_must_fail git tag -s -m tail tag-gpg-failure'
1254 # try to produce invalid signature
1255 test_expect_success GPG \
1256 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1257 'test_config gpg.program echo &&
1258 test_must_fail git tag -s -m tail tag-gpg-failure'
1261 # try to verify without gpg:
1263 rm -rf gpghome
1264 test_expect_success GPG \
1265 'verify signed tag fails when public key is not present' \
1266 'test_must_fail git tag -v signed-tag'
1268 test_expect_success \
1269 'git tag -a fails if tag annotation is empty' '
1270 ! (GIT_EDITOR=cat git tag -a initial-comment)
1273 test_expect_success \
1274 'message in editor has initial comment' '
1275 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1278 test_expect_success 'message in editor has initial comment: first line' '
1279 # check the first line --- should be empty
1280 echo >first.expect &&
1281 sed -e 1q <actual >first.actual &&
1282 test_i18ncmp first.expect first.actual
1285 test_expect_success \
1286 'message in editor has initial comment: remainder' '
1287 # remove commented lines from the remainder -- should be empty
1288 >rest.expect &&
1289 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1290 test_cmp rest.expect rest.actual
1293 get_tag_header reuse $commit commit $time >expect
1294 echo "An annotation to be reused" >> expect
1295 test_expect_success \
1296 'overwriting an annoted tag should use its previous body' '
1297 git tag -a -m "An annotation to be reused" reuse &&
1298 GIT_EDITOR=true git tag -f -a reuse &&
1299 get_tag_msg reuse >actual &&
1300 test_cmp expect actual
1303 test_expect_success 'filename for the message is relative to cwd' '
1304 mkdir subdir &&
1305 echo "Tag message in top directory" >msgfile-5 &&
1306 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1308 cd subdir &&
1309 git tag -a -F msgfile-5 tag-from-subdir
1310 ) &&
1311 git cat-file tag tag-from-subdir | grep "in sub directory"
1314 test_expect_success 'filename for the message is relative to cwd' '
1315 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1317 cd subdir &&
1318 git tag -a -F msgfile-6 tag-from-subdir-2
1319 ) &&
1320 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1323 # create a few more commits to test --contains
1325 hash1=$(git rev-parse HEAD)
1327 test_expect_success 'creating second commit and tag' '
1328 echo foo-2.0 >foo &&
1329 git add foo &&
1330 git commit -m second &&
1331 git tag v2.0
1334 hash2=$(git rev-parse HEAD)
1336 test_expect_success 'creating third commit without tag' '
1337 echo foo-dev >foo &&
1338 git add foo &&
1339 git commit -m third
1342 hash3=$(git rev-parse HEAD)
1344 # simple linear checks of --continue
1346 cat > expected <<EOF
1347 v0.2.1
1348 v1.0
1349 v1.0.1
1350 v1.1.3
1351 v2.0
1354 test_expect_success 'checking that first commit is in all tags (hash)' "
1355 git tag -l --contains $hash1 v* >actual &&
1356 test_cmp expected actual
1359 # other ways of specifying the commit
1360 test_expect_success 'checking that first commit is in all tags (tag)' "
1361 git tag -l --contains v1.0 v* >actual &&
1362 test_cmp expected actual
1365 test_expect_success 'checking that first commit is in all tags (relative)' "
1366 git tag -l --contains HEAD~2 v* >actual &&
1367 test_cmp expected actual
1370 cat > expected <<EOF
1371 v2.0
1374 test_expect_success 'checking that second commit only has one tag' "
1375 git tag -l --contains $hash2 v* >actual &&
1376 test_cmp expected actual
1380 cat > expected <<EOF
1383 test_expect_success 'checking that third commit has no tags' "
1384 git tag -l --contains $hash3 v* >actual &&
1385 test_cmp expected actual
1388 # how about a simple merge?
1390 test_expect_success 'creating simple branch' '
1391 git branch stable v2.0 &&
1392 git checkout stable &&
1393 echo foo-3.0 > foo &&
1394 git commit foo -m fourth &&
1395 git tag v3.0
1398 hash4=$(git rev-parse HEAD)
1400 cat > expected <<EOF
1401 v3.0
1404 test_expect_success 'checking that branch head only has one tag' "
1405 git tag -l --contains $hash4 v* >actual &&
1406 test_cmp expected actual
1409 test_expect_success 'merging original branch into this branch' '
1410 git merge --strategy=ours master &&
1411 git tag v4.0
1414 cat > expected <<EOF
1415 v4.0
1418 test_expect_success 'checking that original branch head has one tag now' "
1419 git tag -l --contains $hash3 v* >actual &&
1420 test_cmp expected actual
1423 cat > expected <<EOF
1424 v0.2.1
1425 v1.0
1426 v1.0.1
1427 v1.1.3
1428 v2.0
1429 v3.0
1430 v4.0
1433 test_expect_success 'checking that initial commit is in all tags' "
1434 git tag -l --contains $hash1 v* >actual &&
1435 test_cmp expected actual
1438 # mixing modes and options:
1440 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1441 test_must_fail git tag -a &&
1442 test_must_fail git tag -l -v &&
1443 test_must_fail git tag -n 100 &&
1444 test_must_fail git tag -l -m msg &&
1445 test_must_fail git tag -l -F some file &&
1446 test_must_fail git tag -v -s
1449 # check points-at
1451 test_expect_success '--points-at cannot be used in non-list mode' '
1452 test_must_fail git tag --points-at=v4.0 foo
1455 test_expect_success '--points-at finds lightweight tags' '
1456 echo v4.0 >expect &&
1457 git tag --points-at v4.0 >actual &&
1458 test_cmp expect actual
1461 test_expect_success '--points-at finds annotated tags of commits' '
1462 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1463 echo annotated-v4.0 >expect &&
1464 git tag -l --points-at v4.0 "annotated*" >actual &&
1465 test_cmp expect actual
1468 test_expect_success '--points-at finds annotated tags of tags' '
1469 git tag -m "describing the v4.0 tag object" \
1470 annotated-again-v4.0 annotated-v4.0 &&
1471 cat >expect <<-\EOF &&
1472 annotated-again-v4.0
1473 annotated-v4.0
1475 git tag --points-at=annotated-v4.0 >actual &&
1476 test_cmp expect actual
1479 test_expect_success 'multiple --points-at are OR-ed together' '
1480 cat >expect <<-\EOF &&
1481 v2.0
1482 v3.0
1484 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1485 test_cmp expect actual
1488 test_expect_success 'lexical sort' '
1489 git tag foo1.3 &&
1490 git tag foo1.6 &&
1491 git tag foo1.10 &&
1492 git tag -l --sort=refname "foo*" >actual &&
1493 cat >expect <<-\EOF &&
1494 foo1.10
1495 foo1.3
1496 foo1.6
1498 test_cmp expect actual
1501 test_expect_success 'version sort' '
1502 git tag -l --sort=version:refname "foo*" >actual &&
1503 cat >expect <<-\EOF &&
1504 foo1.3
1505 foo1.6
1506 foo1.10
1508 test_cmp expect actual
1511 test_expect_success 'reverse version sort' '
1512 git tag -l --sort=-version:refname "foo*" >actual &&
1513 cat >expect <<-\EOF &&
1514 foo1.10
1515 foo1.6
1516 foo1.3
1518 test_cmp expect actual
1521 test_expect_success 'reverse lexical sort' '
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 'configured lexical sort' '
1532 test_config tag.sort "v:refname" &&
1533 git tag -l "foo*" >actual &&
1534 cat >expect <<-\EOF &&
1535 foo1.3
1536 foo1.6
1537 foo1.10
1539 test_cmp expect actual
1542 test_expect_success 'option override configured sort' '
1543 test_config tag.sort "v:refname" &&
1544 git tag -l --sort=-refname "foo*" >actual &&
1545 cat >expect <<-\EOF &&
1546 foo1.6
1547 foo1.3
1548 foo1.10
1550 test_cmp expect actual
1553 test_expect_success 'invalid sort parameter on command line' '
1554 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1557 test_expect_success 'invalid sort parameter in configuratoin' '
1558 test_config tag.sort "v:notvalid" &&
1559 test_must_fail git tag -l "foo*"
1562 test_expect_success 'version sort with prerelease reordering' '
1563 test_config versionsort.prereleaseSuffix -rc &&
1564 git tag foo1.6-rc1 &&
1565 git tag foo1.6-rc2 &&
1566 git tag -l --sort=version:refname "foo*" >actual &&
1567 cat >expect <<-\EOF &&
1568 foo1.3
1569 foo1.6-rc1
1570 foo1.6-rc2
1571 foo1.6
1572 foo1.10
1574 test_cmp expect actual
1577 test_expect_success 'reverse version sort with prerelease reordering' '
1578 test_config versionsort.prereleaseSuffix -rc &&
1579 git tag -l --sort=-version:refname "foo*" >actual &&
1580 cat >expect <<-\EOF &&
1581 foo1.10
1582 foo1.6
1583 foo1.6-rc2
1584 foo1.6-rc1
1585 foo1.3
1587 test_cmp expect actual
1590 test_expect_success 'version sort with prerelease reordering and common leading character' '
1591 test_config versionsort.prereleaseSuffix -before &&
1592 git tag foo1.7-before1 &&
1593 git tag foo1.7 &&
1594 git tag foo1.7-after1 &&
1595 git tag -l --sort=version:refname "foo1.7*" >actual &&
1596 cat >expect <<-\EOF &&
1597 foo1.7-before1
1598 foo1.7
1599 foo1.7-after1
1601 test_cmp expect actual
1604 test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1605 test_config versionsort.prereleaseSuffix -before &&
1606 git config --add versionsort.prereleaseSuffix -after &&
1607 git tag -l --sort=version:refname "foo1.7*" >actual &&
1608 cat >expect <<-\EOF &&
1609 foo1.7-before1
1610 foo1.7-after1
1611 foo1.7
1613 test_cmp expect actual
1616 test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1617 test_config versionsort.prereleaseSuffix -bar &&
1618 git config --add versionsort.prereleaseSuffix -foo-baz &&
1619 git config --add versionsort.prereleaseSuffix -foo-bar &&
1620 git tag foo1.8-foo-bar &&
1621 git tag foo1.8-foo-baz &&
1622 git tag foo1.8 &&
1623 git tag -l --sort=version:refname "foo1.8*" >actual &&
1624 cat >expect <<-\EOF &&
1625 foo1.8-foo-baz
1626 foo1.8-foo-bar
1627 foo1.8
1629 test_cmp expect actual
1632 test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1633 test_config versionsort.prereleaseSuffix -pre &&
1634 git config --add versionsort.prereleaseSuffix -prerelease &&
1635 git tag foo1.9-pre1 &&
1636 git tag foo1.9-pre2 &&
1637 git tag foo1.9-prerelease1 &&
1638 git tag -l --sort=version:refname "foo1.9*" >actual &&
1639 cat >expect <<-\EOF &&
1640 foo1.9-pre1
1641 foo1.9-pre2
1642 foo1.9-prerelease1
1644 test_cmp expect actual
1647 test_expect_success 'version sort with general suffix reordering' '
1648 test_config versionsort.suffix -alpha &&
1649 git config --add versionsort.suffix -beta &&
1650 git config --add versionsort.suffix "" &&
1651 git config --add versionsort.suffix -gamma &&
1652 git config --add versionsort.suffix -delta &&
1653 git tag foo1.10-alpha &&
1654 git tag foo1.10-beta &&
1655 git tag foo1.10-gamma &&
1656 git tag foo1.10-delta &&
1657 git tag foo1.10-unlisted-suffix &&
1658 git tag -l --sort=version:refname "foo1.10*" >actual &&
1659 cat >expect <<-\EOF &&
1660 foo1.10-alpha
1661 foo1.10-beta
1662 foo1.10
1663 foo1.10-unlisted-suffix
1664 foo1.10-gamma
1665 foo1.10-delta
1667 test_cmp expect actual
1670 test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1671 test_config versionsort.suffix -before &&
1672 test_config versionsort.prereleaseSuffix -after &&
1673 git tag -l --sort=version:refname "foo1.7*" >actual &&
1674 cat >expect <<-\EOF &&
1675 foo1.7-before1
1676 foo1.7
1677 foo1.7-after1
1679 test_cmp expect actual
1682 test_expect_success 'version sort with very long prerelease suffix' '
1683 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1684 git tag -l --sort=version:refname
1687 run_with_limited_stack () {
1688 (ulimit -s 128 && "$@")
1691 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1693 # we require ulimit, this excludes Windows
1694 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1695 >expect &&
1696 i=1 &&
1697 while test $i -lt 8000
1699 echo "commit refs/heads/master
1700 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1701 data <<EOF
1702 commit #$i
1703 EOF"
1704 test $i = 1 && echo "from refs/heads/master^0"
1705 i=$(($i + 1))
1706 done | git fast-import &&
1707 git checkout master &&
1708 git tag far-far-away HEAD^ &&
1709 run_with_limited_stack git tag --contains HEAD >actual &&
1710 test_cmp expect actual
1713 test_expect_success '--format should list tags as per format given' '
1714 cat >expect <<-\EOF &&
1715 refname : refs/tags/v1.0
1716 refname : refs/tags/v1.0.1
1717 refname : refs/tags/v1.1.3
1719 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1720 test_cmp expect actual
1723 test_expect_success 'setup --merged test tags' '
1724 git tag mergetest-1 HEAD~2 &&
1725 git tag mergetest-2 HEAD~1 &&
1726 git tag mergetest-3 HEAD
1729 test_expect_success '--merged cannot be used in non-list mode' '
1730 test_must_fail git tag --merged=mergetest-2 foo
1733 test_expect_success '--merged shows merged tags' '
1734 cat >expect <<-\EOF &&
1735 mergetest-1
1736 mergetest-2
1738 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1739 test_cmp expect actual
1742 test_expect_success '--no-merged show unmerged tags' '
1743 cat >expect <<-\EOF &&
1744 mergetest-3
1746 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1747 test_cmp expect actual
1750 test_expect_success 'ambiguous branch/tags not marked' '
1751 git tag ambiguous &&
1752 git branch ambiguous &&
1753 echo ambiguous >expect &&
1754 git tag -l ambiguous >actual &&
1755 test_cmp expect actual
1758 test_done