t7004-tag: use test_config helper
[alt-git.git] / t / t7004-tag.sh
blob920a1b4b2e58e4c686261540aeabd21541ac46d4
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 'looking for a tag in an empty tree should fail' \
31 '! (tag_exists mytag)'
33 test_expect_success 'creating a tag in an empty tree should fail' '
34 test_must_fail git tag mynotag &&
35 ! tag_exists mynotag
38 test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
39 test_must_fail git tag mytaghead HEAD &&
40 ! tag_exists mytaghead
43 test_expect_success 'creating a tag for an unknown revision should fail' '
44 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
45 ! tag_exists mytagnorev
48 # commit used in the tests, test_tick is also called here to freeze the date:
49 test_expect_success 'creating a tag using default HEAD should succeed' '
50 test_tick &&
51 echo foo >foo &&
52 git add foo &&
53 git commit -m Foo &&
54 git tag mytag &&
55 test_must_fail git reflog exists refs/tags/mytag
58 test_expect_success 'creating a tag with --create-reflog should create reflog' '
59 test_when_finished "git tag -d tag_with_reflog" &&
60 git tag --create-reflog tag_with_reflog &&
61 git reflog exists refs/tags/tag_with_reflog
64 test_expect_success '--create-reflog does not create reflog on failure' '
65 test_must_fail git tag --create-reflog mytag &&
66 test_must_fail git reflog exists refs/tags/mytag
69 test_expect_success 'listing all tags if one exists should succeed' '
70 git tag -l &&
71 git tag
74 test_expect_success 'listing all tags if one exists should output that tag' '
75 test $(git tag -l) = mytag &&
76 test $(git tag) = mytag
79 # pattern matching:
81 test_expect_success 'listing a tag using a matching pattern should succeed' \
82 'git tag -l mytag'
84 test_expect_success \
85 'listing a tag using a matching pattern should output that tag' \
86 'test $(git tag -l mytag) = mytag'
88 # todo: git tag -l now returns always zero, when fixed, change this test
89 test_expect_success \
90 'listing tags using a non-matching pattern should suceed' \
91 'git tag -l xxx'
93 test_expect_success \
94 'listing tags using a non-matching pattern should output nothing' \
95 'test $(git tag -l xxx | wc -l) -eq 0'
97 # special cases for creating tags:
99 test_expect_success \
100 'trying to create a tag with the name of one existing should fail' \
101 'test_must_fail git tag mytag'
103 test_expect_success \
104 'trying to create a tag with a non-valid name should fail' '
105 test $(git tag -l | wc -l) -eq 1 &&
106 test_must_fail git tag "" &&
107 test_must_fail git tag .othertag &&
108 test_must_fail git tag "other tag" &&
109 test_must_fail git tag "othertag^" &&
110 test_must_fail git tag "other~tag" &&
111 test $(git tag -l | wc -l) -eq 1
114 test_expect_success 'creating a tag using HEAD directly should succeed' '
115 git tag myhead HEAD &&
116 tag_exists myhead
119 test_expect_success '--force can create a tag with the name of one existing' '
120 tag_exists mytag &&
121 git tag --force mytag &&
122 tag_exists mytag'
124 test_expect_success '--force is moot with a non-existing tag name' '
125 test_when_finished git tag -d newtag forcetag &&
126 git tag newtag >expect &&
127 git tag --force forcetag >actual &&
128 test_cmp expect actual
131 # deleting tags:
133 test_expect_success 'trying to delete an unknown tag should fail' '
134 ! tag_exists unknown-tag &&
135 test_must_fail git tag -d unknown-tag
138 cat >expect <<EOF
139 myhead
140 mytag
142 test_expect_success \
143 'trying to delete tags without params should succeed and do nothing' '
144 git tag -l > actual && test_cmp expect actual &&
145 git tag -d &&
146 git tag -l > actual && test_cmp expect actual
149 test_expect_success \
150 'deleting two existing tags in one command should succeed' '
151 tag_exists mytag &&
152 tag_exists myhead &&
153 git tag -d mytag myhead &&
154 ! tag_exists mytag &&
155 ! tag_exists myhead
158 test_expect_success \
159 'creating a tag with the name of another deleted one should succeed' '
160 ! tag_exists mytag &&
161 git tag mytag &&
162 tag_exists mytag
165 test_expect_success \
166 'trying to delete two tags, existing and not, should fail in the 2nd' '
167 tag_exists mytag &&
168 ! tag_exists myhead &&
169 test_must_fail git tag -d mytag anothertag &&
170 ! tag_exists mytag &&
171 ! tag_exists myhead
174 test_expect_success 'trying to delete an already deleted tag should fail' \
175 'test_must_fail git tag -d mytag'
177 # listing various tags with pattern matching:
179 cat >expect <<EOF
183 t210
184 t211
185 v0.2.1
186 v1.0
187 v1.0.1
188 v1.1.3
190 test_expect_success 'listing all tags should print them ordered' '
191 git tag v1.0.1 &&
192 git tag t211 &&
193 git tag aa1 &&
194 git tag v0.2.1 &&
195 git tag v1.1.3 &&
196 git tag cba &&
197 git tag a1 &&
198 git tag v1.0 &&
199 git tag t210 &&
200 git tag -l > actual &&
201 test_cmp expect actual &&
202 git tag > actual &&
203 test_cmp expect actual
206 cat >expect <<EOF
211 test_expect_success \
212 'listing tags with substring as pattern must print those matching' '
213 rm *a* &&
214 git tag -l "*a*" > current &&
215 test_cmp expect current
218 cat >expect <<EOF
219 v0.2.1
220 v1.0.1
222 test_expect_success \
223 'listing tags with a suffix as pattern must print those matching' '
224 git tag -l "*.1" > actual &&
225 test_cmp expect actual
228 cat >expect <<EOF
229 t210
230 t211
232 test_expect_success \
233 'listing tags with a prefix as pattern must print those matching' '
234 git tag -l "t21*" > actual &&
235 test_cmp expect actual
238 cat >expect <<EOF
241 test_expect_success \
242 'listing tags using a name as pattern must print that one matching' '
243 git tag -l a1 > actual &&
244 test_cmp expect actual
247 cat >expect <<EOF
248 v1.0
250 test_expect_success \
251 'listing tags using a name as pattern must print that one matching' '
252 git tag -l v1.0 > actual &&
253 test_cmp expect actual
256 cat >expect <<EOF
257 v1.0.1
258 v1.1.3
260 test_expect_success \
261 'listing tags with ? in the pattern should print those matching' '
262 git tag -l "v1.?.?" > actual &&
263 test_cmp expect actual
266 >expect
267 test_expect_success \
268 'listing tags using v.* should print nothing because none have v.' '
269 git tag -l "v.*" > actual &&
270 test_cmp expect actual
273 cat >expect <<EOF
274 v0.2.1
275 v1.0
276 v1.0.1
277 v1.1.3
279 test_expect_success \
280 'listing tags using v* should print only those having v' '
281 git tag -l "v*" > actual &&
282 test_cmp expect actual
285 test_expect_success 'tag -l can accept multiple patterns' '
286 git tag -l "v1*" "v0*" >actual &&
287 test_cmp expect actual
290 test_expect_success 'listing tags in column' '
291 COLUMNS=40 git tag -l --column=row >actual &&
292 cat >expected <<\EOF &&
293 a1 aa1 cba t210 t211
294 v0.2.1 v1.0 v1.0.1 v1.1.3
296 test_cmp expected actual
299 test_expect_success 'listing tags in column with column.*' '
300 test_config column.tag row &&
301 test_config column.ui dense &&
302 COLUMNS=40 git tag -l >actual &&
303 cat >expected <<\EOF &&
304 a1 aa1 cba t210 t211
305 v0.2.1 v1.0 v1.0.1 v1.1.3
307 test_cmp expected actual
310 test_expect_success 'listing tag with -n --column should fail' '
311 test_must_fail git tag --column -n
314 test_expect_success 'listing tags -n in column with column.ui ignored' '
315 test_config column.ui "row dense" &&
316 COLUMNS=40 git tag -l -n >actual &&
317 cat >expected <<\EOF &&
318 a1 Foo
319 aa1 Foo
320 cba Foo
321 t210 Foo
322 t211 Foo
323 v0.2.1 Foo
324 v1.0 Foo
325 v1.0.1 Foo
326 v1.1.3 Foo
328 test_cmp expected actual
331 # creating and verifying lightweight tags:
333 test_expect_success \
334 'a non-annotated tag created without parameters should point to HEAD' '
335 git tag non-annotated-tag &&
336 test $(git cat-file -t non-annotated-tag) = commit &&
337 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
340 test_expect_success 'trying to verify an unknown tag should fail' \
341 'test_must_fail git tag -v unknown-tag'
343 test_expect_success \
344 'trying to verify a non-annotated and non-signed tag should fail' \
345 'test_must_fail git tag -v non-annotated-tag'
347 test_expect_success \
348 'trying to verify many non-annotated or unknown tags, should fail' \
349 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
351 # creating annotated tags:
353 get_tag_msg () {
354 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
357 # run test_tick before committing always gives the time in that timezone
358 get_tag_header () {
359 cat <<EOF
360 object $2
361 type $3
362 tag $1
363 tagger C O Mitter <committer@example.com> $4 -0700
368 commit=$(git rev-parse HEAD)
369 time=$test_tick
371 get_tag_header annotated-tag $commit commit $time >expect
372 echo "A message" >>expect
373 test_expect_success \
374 'creating an annotated tag with -m message should succeed' '
375 git tag -m "A message" annotated-tag &&
376 get_tag_msg annotated-tag >actual &&
377 test_cmp expect actual
380 cat >msgfile <<EOF
381 Another message
382 in a file.
384 get_tag_header file-annotated-tag $commit commit $time >expect
385 cat msgfile >>expect
386 test_expect_success \
387 'creating an annotated tag with -F messagefile should succeed' '
388 git tag -F msgfile file-annotated-tag &&
389 get_tag_msg file-annotated-tag >actual &&
390 test_cmp expect actual
393 cat >inputmsg <<EOF
394 A message from the
395 standard input
397 get_tag_header stdin-annotated-tag $commit commit $time >expect
398 cat inputmsg >>expect
399 test_expect_success 'creating an annotated tag with -F - should succeed' '
400 git tag -F - stdin-annotated-tag <inputmsg &&
401 get_tag_msg stdin-annotated-tag >actual &&
402 test_cmp expect actual
405 test_expect_success \
406 'trying to create a tag with a non-existing -F file should fail' '
407 ! test -f nonexistingfile &&
408 ! tag_exists notag &&
409 test_must_fail git tag -F nonexistingfile notag &&
410 ! tag_exists notag
413 test_expect_success \
414 'trying to create tags giving both -m or -F options should fail' '
415 echo "message file 1" >msgfile1 &&
416 echo "message file 2" >msgfile2 &&
417 ! tag_exists msgtag &&
418 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
419 ! tag_exists msgtag &&
420 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
421 ! tag_exists msgtag &&
422 test_must_fail git tag -m "message 1" -F msgfile1 \
423 -m "message 2" msgtag &&
424 ! tag_exists msgtag
427 # blank and empty messages:
429 get_tag_header empty-annotated-tag $commit commit $time >expect
430 test_expect_success \
431 'creating a tag with an empty -m message should succeed' '
432 git tag -m "" empty-annotated-tag &&
433 get_tag_msg empty-annotated-tag >actual &&
434 test_cmp expect actual
437 >emptyfile
438 get_tag_header emptyfile-annotated-tag $commit commit $time >expect
439 test_expect_success \
440 'creating a tag with an empty -F messagefile should succeed' '
441 git tag -F emptyfile emptyfile-annotated-tag &&
442 get_tag_msg emptyfile-annotated-tag >actual &&
443 test_cmp expect actual
446 printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
447 printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
448 printf '\n\n\nTrailing spaces \t \n' >>blanksfile
449 printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
450 get_tag_header blanks-annotated-tag $commit commit $time >expect
451 cat >>expect <<EOF
452 Leading blank lines
454 Repeated blank lines
456 Trailing spaces
458 Trailing blank lines
460 test_expect_success \
461 'extra blanks in the message for an annotated tag should be removed' '
462 git tag -F blanksfile blanks-annotated-tag &&
463 get_tag_msg blanks-annotated-tag >actual &&
464 test_cmp expect actual
467 get_tag_header blank-annotated-tag $commit commit $time >expect
468 test_expect_success \
469 'creating a tag with blank -m message with spaces should succeed' '
470 git tag -m " " blank-annotated-tag &&
471 get_tag_msg blank-annotated-tag >actual &&
472 test_cmp expect actual
475 echo ' ' >blankfile
476 echo '' >>blankfile
477 echo ' ' >>blankfile
478 get_tag_header blankfile-annotated-tag $commit commit $time >expect
479 test_expect_success \
480 'creating a tag with blank -F messagefile with spaces should succeed' '
481 git tag -F blankfile blankfile-annotated-tag &&
482 get_tag_msg blankfile-annotated-tag >actual &&
483 test_cmp expect actual
486 printf ' ' >blanknonlfile
487 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
488 test_expect_success \
489 'creating a tag with -F file of spaces and no newline should succeed' '
490 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
491 get_tag_msg blanknonlfile-annotated-tag >actual &&
492 test_cmp expect actual
495 # messages with commented lines:
497 cat >commentsfile <<EOF
498 # A comment
500 ############
501 The message.
502 ############
503 One line.
506 # commented lines
507 # commented lines
509 Another line.
510 # comments
512 Last line.
514 get_tag_header comments-annotated-tag $commit commit $time >expect
515 cat >>expect <<EOF
516 The message.
517 One line.
519 Another line.
521 Last line.
523 test_expect_success \
524 'creating a tag using a -F messagefile with #comments should succeed' '
525 git tag -F commentsfile comments-annotated-tag &&
526 get_tag_msg comments-annotated-tag >actual &&
527 test_cmp expect actual
530 get_tag_header comment-annotated-tag $commit commit $time >expect
531 test_expect_success \
532 'creating a tag with a #comment in the -m message should succeed' '
533 git tag -m "#comment" comment-annotated-tag &&
534 get_tag_msg comment-annotated-tag >actual &&
535 test_cmp expect actual
538 echo '#comment' >commentfile
539 echo '' >>commentfile
540 echo '####' >>commentfile
541 get_tag_header commentfile-annotated-tag $commit commit $time >expect
542 test_expect_success \
543 'creating a tag with #comments in the -F messagefile should succeed' '
544 git tag -F commentfile commentfile-annotated-tag &&
545 get_tag_msg commentfile-annotated-tag >actual &&
546 test_cmp expect actual
549 printf '#comment' >commentnonlfile
550 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
551 test_expect_success \
552 'creating a tag with a file of #comment and no newline should succeed' '
553 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
554 get_tag_msg commentnonlfile-annotated-tag >actual &&
555 test_cmp expect actual
558 # listing messages for annotated non-signed tags:
560 test_expect_success \
561 'listing the one-line message of a non-signed tag should succeed' '
562 git tag -m "A msg" tag-one-line &&
564 echo "tag-one-line" >expect &&
565 git tag -l | grep "^tag-one-line" >actual &&
566 test_cmp expect actual &&
567 git tag -n0 -l | grep "^tag-one-line" >actual &&
568 test_cmp expect actual &&
569 git tag -n0 -l tag-one-line >actual &&
570 test_cmp expect actual &&
572 echo "tag-one-line A msg" >expect &&
573 git tag -n1 -l | grep "^tag-one-line" >actual &&
574 test_cmp expect actual &&
575 git tag -n -l | grep "^tag-one-line" >actual &&
576 test_cmp expect actual &&
577 git tag -n1 -l tag-one-line >actual &&
578 test_cmp expect actual &&
579 git tag -n2 -l tag-one-line >actual &&
580 test_cmp expect actual &&
581 git tag -n999 -l tag-one-line >actual &&
582 test_cmp expect actual
585 test_expect_success \
586 'listing the zero-lines message of a non-signed tag should succeed' '
587 git tag -m "" tag-zero-lines &&
589 echo "tag-zero-lines" >expect &&
590 git tag -l | grep "^tag-zero-lines" >actual &&
591 test_cmp expect actual &&
592 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
593 test_cmp expect actual &&
594 git tag -n0 -l tag-zero-lines >actual &&
595 test_cmp expect actual &&
597 echo "tag-zero-lines " >expect &&
598 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
599 test_cmp expect actual &&
600 git tag -n -l | grep "^tag-zero-lines" >actual &&
601 test_cmp expect actual &&
602 git tag -n1 -l tag-zero-lines >actual &&
603 test_cmp expect actual &&
604 git tag -n2 -l tag-zero-lines >actual &&
605 test_cmp expect actual &&
606 git tag -n999 -l tag-zero-lines >actual &&
607 test_cmp expect actual
610 echo 'tag line one' >annotagmsg
611 echo 'tag line two' >>annotagmsg
612 echo 'tag line three' >>annotagmsg
613 test_expect_success \
614 'listing many message lines of a non-signed tag should succeed' '
615 git tag -F annotagmsg tag-lines &&
617 echo "tag-lines" >expect &&
618 git tag -l | grep "^tag-lines" >actual &&
619 test_cmp expect actual &&
620 git tag -n0 -l | grep "^tag-lines" >actual &&
621 test_cmp expect actual &&
622 git tag -n0 -l tag-lines >actual &&
623 test_cmp expect actual &&
625 echo "tag-lines tag line one" >expect &&
626 git tag -n1 -l | grep "^tag-lines" >actual &&
627 test_cmp expect actual &&
628 git tag -n -l | grep "^tag-lines" >actual &&
629 test_cmp expect actual &&
630 git tag -n1 -l tag-lines >actual &&
631 test_cmp expect actual &&
633 echo " tag line two" >>expect &&
634 git tag -n2 -l | grep "^ *tag.line" >actual &&
635 test_cmp expect actual &&
636 git tag -n2 -l tag-lines >actual &&
637 test_cmp expect actual &&
639 echo " tag line three" >>expect &&
640 git tag -n3 -l | grep "^ *tag.line" >actual &&
641 test_cmp expect actual &&
642 git tag -n3 -l tag-lines >actual &&
643 test_cmp expect actual &&
644 git tag -n4 -l | grep "^ *tag.line" >actual &&
645 test_cmp expect actual &&
646 git tag -n4 -l tag-lines >actual &&
647 test_cmp expect actual &&
648 git tag -n99 -l | grep "^ *tag.line" >actual &&
649 test_cmp expect actual &&
650 git tag -n99 -l tag-lines >actual &&
651 test_cmp expect actual
654 test_expect_success 'annotations for blobs are empty' '
655 blob=$(git hash-object -w --stdin <<-\EOF
656 Blob paragraph 1.
658 Blob paragraph 2.
660 ) &&
661 git tag tag-blob $blob &&
662 echo "tag-blob " >expect &&
663 git tag -n1 -l tag-blob >actual &&
664 test_cmp expect actual
667 # trying to verify annotated non-signed tags:
669 test_expect_success GPG \
670 'trying to verify an annotated non-signed tag should fail' '
671 tag_exists annotated-tag &&
672 test_must_fail git tag -v annotated-tag
675 test_expect_success GPG \
676 'trying to verify a file-annotated non-signed tag should fail' '
677 tag_exists file-annotated-tag &&
678 test_must_fail git tag -v file-annotated-tag
681 test_expect_success GPG \
682 'trying to verify two annotated non-signed tags should fail' '
683 tag_exists annotated-tag file-annotated-tag &&
684 test_must_fail git tag -v annotated-tag file-annotated-tag
687 # creating and verifying signed tags:
689 get_tag_header signed-tag $commit commit $time >expect
690 echo 'A signed tag message' >>expect
691 echo '-----BEGIN PGP SIGNATURE-----' >>expect
692 test_expect_success GPG 'creating a signed tag with -m message should succeed' '
693 git tag -s -m "A signed tag message" signed-tag &&
694 get_tag_msg signed-tag >actual &&
695 test_cmp expect actual
698 get_tag_header u-signed-tag $commit commit $time >expect
699 echo 'Another message' >>expect
700 echo '-----BEGIN PGP SIGNATURE-----' >>expect
701 test_expect_success GPG 'sign with a given key id' '
703 git tag -u committer@example.com -m "Another message" u-signed-tag &&
704 get_tag_msg u-signed-tag >actual &&
705 test_cmp expect actual
709 test_expect_success GPG 'sign with an unknown id (1)' '
711 test_must_fail git tag -u author@example.com \
712 -m "Another message" o-signed-tag
716 test_expect_success GPG 'sign with an unknown id (2)' '
718 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
722 cat >fakeeditor <<'EOF'
723 #!/bin/sh
724 test -n "$1" && exec >"$1"
725 echo A signed tag message
726 echo from a fake editor.
728 chmod +x fakeeditor
730 get_tag_header implied-sign $commit commit $time >expect
731 ./fakeeditor >>expect
732 echo '-----BEGIN PGP SIGNATURE-----' >>expect
733 test_expect_success GPG '-u implies signed tag' '
734 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
735 get_tag_msg implied-sign >actual &&
736 test_cmp expect actual
739 cat >sigmsgfile <<EOF
740 Another signed tag
741 message in a file.
743 get_tag_header file-signed-tag $commit commit $time >expect
744 cat sigmsgfile >>expect
745 echo '-----BEGIN PGP SIGNATURE-----' >>expect
746 test_expect_success GPG \
747 'creating a signed tag with -F messagefile should succeed' '
748 git tag -s -F sigmsgfile file-signed-tag &&
749 get_tag_msg file-signed-tag >actual &&
750 test_cmp expect actual
753 cat >siginputmsg <<EOF
754 A signed tag message from
755 the standard input
757 get_tag_header stdin-signed-tag $commit commit $time >expect
758 cat siginputmsg >>expect
759 echo '-----BEGIN PGP SIGNATURE-----' >>expect
760 test_expect_success GPG 'creating a signed tag with -F - should succeed' '
761 git tag -s -F - stdin-signed-tag <siginputmsg &&
762 get_tag_msg stdin-signed-tag >actual &&
763 test_cmp expect actual
766 get_tag_header implied-annotate $commit commit $time >expect
767 ./fakeeditor >>expect
768 echo '-----BEGIN PGP SIGNATURE-----' >>expect
769 test_expect_success GPG '-s implies annotated tag' '
770 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
771 get_tag_msg implied-annotate >actual &&
772 test_cmp expect actual
775 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
776 echo "A message" >>expect
777 echo '-----BEGIN PGP SIGNATURE-----' >>expect
778 test_expect_success GPG \
779 'git tag -s implied if configured with tag.forcesignannotated' \
780 'test_config tag.forcesignannotated true &&
781 git tag -m "A message" forcesignannotated-implied-sign &&
782 get_tag_msg forcesignannotated-implied-sign >actual &&
783 test_cmp expect actual
786 test_expect_success GPG \
787 'lightweight with no message when configured with tag.forcesignannotated' \
788 'test_config tag.forcesignannotated true &&
789 git tag forcesignannotated-lightweight &&
790 tag_exists forcesignannotated-lightweight &&
791 test_must_fail git tag -v forcesignannotated-no-message
794 get_tag_header forcesignannotated-annotate $commit commit $time >expect
795 echo "A message" >>expect
796 test_expect_success GPG \
797 'git tag -a disable configured tag.forcesignannotated' \
798 'test_config tag.forcesignannotated true &&
799 git tag -a -m "A message" forcesignannotated-annotate &&
800 get_tag_msg forcesignannotated-annotate >actual &&
801 test_cmp expect actual &&
802 test_must_fail git tag -v forcesignannotated-annotate
805 get_tag_header forcesignannotated-disabled $commit commit $time >expect
806 echo "A message" >>expect
807 echo '-----BEGIN PGP SIGNATURE-----' >>expect
808 test_expect_success GPG \
809 'git tag --sign enable GPG sign' \
810 'test_config tag.forcesignannotated false &&
811 git tag --sign -m "A message" forcesignannotated-disabled &&
812 get_tag_msg forcesignannotated-disabled >actual &&
813 test_cmp expect actual
816 test_expect_success GPG \
817 'trying to create a signed tag with non-existing -F file should fail' '
818 ! test -f nonexistingfile &&
819 ! tag_exists nosigtag &&
820 test_must_fail git tag -s -F nonexistingfile nosigtag &&
821 ! tag_exists nosigtag
824 test_expect_success GPG 'verifying a signed tag should succeed' \
825 'git tag -v signed-tag'
827 test_expect_success GPG 'verifying two signed tags in one command should succeed' \
828 'git tag -v signed-tag file-signed-tag'
830 test_expect_success GPG \
831 'verifying many signed and non-signed tags should fail' '
832 test_must_fail git tag -v signed-tag annotated-tag &&
833 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
834 test_must_fail git tag -v annotated-tag \
835 file-signed-tag file-annotated-tag &&
836 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
839 test_expect_success GPG 'verifying a forged tag should fail' '
840 forged=$(git cat-file tag signed-tag |
841 sed -e "s/signed-tag/forged-tag/" |
842 git mktag) &&
843 git tag forged-tag $forged &&
844 test_must_fail git tag -v forged-tag
847 # blank and empty messages for signed tags:
849 get_tag_header empty-signed-tag $commit commit $time >expect
850 echo '-----BEGIN PGP SIGNATURE-----' >>expect
851 test_expect_success GPG \
852 'creating a signed tag with an empty -m message should succeed' '
853 git tag -s -m "" empty-signed-tag &&
854 get_tag_msg empty-signed-tag >actual &&
855 test_cmp expect actual &&
856 git tag -v empty-signed-tag
859 >sigemptyfile
860 get_tag_header emptyfile-signed-tag $commit commit $time >expect
861 echo '-----BEGIN PGP SIGNATURE-----' >>expect
862 test_expect_success GPG \
863 'creating a signed tag with an empty -F messagefile should succeed' '
864 git tag -s -F sigemptyfile emptyfile-signed-tag &&
865 get_tag_msg emptyfile-signed-tag >actual &&
866 test_cmp expect actual &&
867 git tag -v emptyfile-signed-tag
870 printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
871 printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
872 printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
873 printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
874 get_tag_header blanks-signed-tag $commit commit $time >expect
875 cat >>expect <<EOF
876 Leading blank lines
878 Repeated blank lines
880 Trailing spaces
882 Trailing blank lines
884 echo '-----BEGIN PGP SIGNATURE-----' >>expect
885 test_expect_success GPG \
886 'extra blanks in the message for a signed tag should be removed' '
887 git tag -s -F sigblanksfile blanks-signed-tag &&
888 get_tag_msg blanks-signed-tag >actual &&
889 test_cmp expect actual &&
890 git tag -v blanks-signed-tag
893 get_tag_header blank-signed-tag $commit commit $time >expect
894 echo '-----BEGIN PGP SIGNATURE-----' >>expect
895 test_expect_success GPG \
896 'creating a signed tag with a blank -m message should succeed' '
897 git tag -s -m " " blank-signed-tag &&
898 get_tag_msg blank-signed-tag >actual &&
899 test_cmp expect actual &&
900 git tag -v blank-signed-tag
903 echo ' ' >sigblankfile
904 echo '' >>sigblankfile
905 echo ' ' >>sigblankfile
906 get_tag_header blankfile-signed-tag $commit commit $time >expect
907 echo '-----BEGIN PGP SIGNATURE-----' >>expect
908 test_expect_success GPG \
909 'creating a signed tag with blank -F file with spaces should succeed' '
910 git tag -s -F sigblankfile blankfile-signed-tag &&
911 get_tag_msg blankfile-signed-tag >actual &&
912 test_cmp expect actual &&
913 git tag -v blankfile-signed-tag
916 printf ' ' >sigblanknonlfile
917 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
918 echo '-----BEGIN PGP SIGNATURE-----' >>expect
919 test_expect_success GPG \
920 'creating a signed tag with spaces and no newline should succeed' '
921 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
922 get_tag_msg blanknonlfile-signed-tag >actual &&
923 test_cmp expect actual &&
924 git tag -v signed-tag
927 # messages with commented lines for signed tags:
929 cat >sigcommentsfile <<EOF
930 # A comment
932 ############
933 The message.
934 ############
935 One line.
938 # commented lines
939 # commented lines
941 Another line.
942 # comments
944 Last line.
946 get_tag_header comments-signed-tag $commit commit $time >expect
947 cat >>expect <<EOF
948 The message.
949 One line.
951 Another line.
953 Last line.
955 echo '-----BEGIN PGP SIGNATURE-----' >>expect
956 test_expect_success GPG \
957 'creating a signed tag with a -F file with #comments should succeed' '
958 git tag -s -F sigcommentsfile comments-signed-tag &&
959 get_tag_msg comments-signed-tag >actual &&
960 test_cmp expect actual &&
961 git tag -v comments-signed-tag
964 get_tag_header comment-signed-tag $commit commit $time >expect
965 echo '-----BEGIN PGP SIGNATURE-----' >>expect
966 test_expect_success GPG \
967 'creating a signed tag with #commented -m message should succeed' '
968 git tag -s -m "#comment" comment-signed-tag &&
969 get_tag_msg comment-signed-tag >actual &&
970 test_cmp expect actual &&
971 git tag -v comment-signed-tag
974 echo '#comment' >sigcommentfile
975 echo '' >>sigcommentfile
976 echo '####' >>sigcommentfile
977 get_tag_header commentfile-signed-tag $commit commit $time >expect
978 echo '-----BEGIN PGP SIGNATURE-----' >>expect
979 test_expect_success GPG \
980 'creating a signed tag with #commented -F messagefile should succeed' '
981 git tag -s -F sigcommentfile commentfile-signed-tag &&
982 get_tag_msg commentfile-signed-tag >actual &&
983 test_cmp expect actual &&
984 git tag -v commentfile-signed-tag
987 printf '#comment' >sigcommentnonlfile
988 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
989 echo '-----BEGIN PGP SIGNATURE-----' >>expect
990 test_expect_success GPG \
991 'creating a signed tag with a #comment and no newline should succeed' '
992 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
993 get_tag_msg commentnonlfile-signed-tag >actual &&
994 test_cmp expect actual &&
995 git tag -v commentnonlfile-signed-tag
998 # listing messages for signed tags:
1000 test_expect_success GPG \
1001 'listing the one-line message of a signed tag should succeed' '
1002 git tag -s -m "A message line signed" stag-one-line &&
1004 echo "stag-one-line" >expect &&
1005 git tag -l | grep "^stag-one-line" >actual &&
1006 test_cmp expect actual &&
1007 git tag -n0 -l | grep "^stag-one-line" >actual &&
1008 test_cmp expect actual &&
1009 git tag -n0 -l stag-one-line >actual &&
1010 test_cmp expect actual &&
1012 echo "stag-one-line A message line signed" >expect &&
1013 git tag -n1 -l | grep "^stag-one-line" >actual &&
1014 test_cmp expect actual &&
1015 git tag -n -l | grep "^stag-one-line" >actual &&
1016 test_cmp expect actual &&
1017 git tag -n1 -l stag-one-line >actual &&
1018 test_cmp expect actual &&
1019 git tag -n2 -l stag-one-line >actual &&
1020 test_cmp expect actual &&
1021 git tag -n999 -l stag-one-line >actual &&
1022 test_cmp expect actual
1025 test_expect_success GPG \
1026 'listing the zero-lines message of a signed tag should succeed' '
1027 git tag -s -m "" stag-zero-lines &&
1029 echo "stag-zero-lines" >expect &&
1030 git tag -l | grep "^stag-zero-lines" >actual &&
1031 test_cmp expect actual &&
1032 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1033 test_cmp expect actual &&
1034 git tag -n0 -l stag-zero-lines >actual &&
1035 test_cmp expect actual &&
1037 echo "stag-zero-lines " >expect &&
1038 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1039 test_cmp expect actual &&
1040 git tag -n -l | grep "^stag-zero-lines" >actual &&
1041 test_cmp expect actual &&
1042 git tag -n1 -l stag-zero-lines >actual &&
1043 test_cmp expect actual &&
1044 git tag -n2 -l stag-zero-lines >actual &&
1045 test_cmp expect actual &&
1046 git tag -n999 -l stag-zero-lines >actual &&
1047 test_cmp expect actual
1050 echo 'stag line one' >sigtagmsg
1051 echo 'stag line two' >>sigtagmsg
1052 echo 'stag line three' >>sigtagmsg
1053 test_expect_success GPG \
1054 'listing many message lines of a signed tag should succeed' '
1055 git tag -s -F sigtagmsg stag-lines &&
1057 echo "stag-lines" >expect &&
1058 git tag -l | grep "^stag-lines" >actual &&
1059 test_cmp expect actual &&
1060 git tag -n0 -l | grep "^stag-lines" >actual &&
1061 test_cmp expect actual &&
1062 git tag -n0 -l stag-lines >actual &&
1063 test_cmp expect actual &&
1065 echo "stag-lines stag line one" >expect &&
1066 git tag -n1 -l | grep "^stag-lines" >actual &&
1067 test_cmp expect actual &&
1068 git tag -n -l | grep "^stag-lines" >actual &&
1069 test_cmp expect actual &&
1070 git tag -n1 -l stag-lines >actual &&
1071 test_cmp expect actual &&
1073 echo " stag line two" >>expect &&
1074 git tag -n2 -l | grep "^ *stag.line" >actual &&
1075 test_cmp expect actual &&
1076 git tag -n2 -l stag-lines >actual &&
1077 test_cmp expect actual &&
1079 echo " stag line three" >>expect &&
1080 git tag -n3 -l | grep "^ *stag.line" >actual &&
1081 test_cmp expect actual &&
1082 git tag -n3 -l stag-lines >actual &&
1083 test_cmp expect actual &&
1084 git tag -n4 -l | grep "^ *stag.line" >actual &&
1085 test_cmp expect actual &&
1086 git tag -n4 -l stag-lines >actual &&
1087 test_cmp expect actual &&
1088 git tag -n99 -l | grep "^ *stag.line" >actual &&
1089 test_cmp expect actual &&
1090 git tag -n99 -l stag-lines >actual &&
1091 test_cmp expect actual
1094 # tags pointing to objects different from commits:
1096 tree=$(git rev-parse HEAD^{tree})
1097 blob=$(git rev-parse HEAD:foo)
1098 tag=$(git rev-parse signed-tag 2>/dev/null)
1100 get_tag_header tree-signed-tag $tree tree $time >expect
1101 echo "A message for a tree" >>expect
1102 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1103 test_expect_success GPG \
1104 'creating a signed tag pointing to a tree should succeed' '
1105 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1106 get_tag_msg tree-signed-tag >actual &&
1107 test_cmp expect actual
1110 get_tag_header blob-signed-tag $blob blob $time >expect
1111 echo "A message for a blob" >>expect
1112 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1113 test_expect_success GPG \
1114 'creating a signed tag pointing to a blob should succeed' '
1115 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1116 get_tag_msg blob-signed-tag >actual &&
1117 test_cmp expect actual
1120 get_tag_header tag-signed-tag $tag tag $time >expect
1121 echo "A message for another tag" >>expect
1122 echo '-----BEGIN PGP SIGNATURE-----' >>expect
1123 test_expect_success GPG \
1124 'creating a signed tag pointing to another tag should succeed' '
1125 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1126 get_tag_msg tag-signed-tag >actual &&
1127 test_cmp expect actual
1130 # usage with rfc1991 signatures
1131 get_tag_header rfc1991-signed-tag $commit commit $time >expect
1132 echo "RFC1991 signed tag" >>expect
1133 echo '-----BEGIN PGP MESSAGE-----' >>expect
1134 test_expect_success GPG,RFC1991 \
1135 'creating a signed tag with rfc1991' '
1136 echo "rfc1991" >gpghome/gpg.conf &&
1137 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1138 get_tag_msg rfc1991-signed-tag >actual &&
1139 test_cmp expect actual
1142 cat >fakeeditor <<'EOF'
1143 #!/bin/sh
1144 cp "$1" actual
1146 chmod +x fakeeditor
1148 test_expect_success GPG,RFC1991 \
1149 'reediting a signed tag body omits signature' '
1150 echo "rfc1991" >gpghome/gpg.conf &&
1151 echo "RFC1991 signed tag" >expect &&
1152 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1153 test_cmp expect actual
1156 test_expect_success GPG,RFC1991 \
1157 'verifying rfc1991 signature' '
1158 echo "rfc1991" >gpghome/gpg.conf &&
1159 git tag -v rfc1991-signed-tag
1162 test_expect_success GPG,RFC1991 \
1163 'list tag with rfc1991 signature' '
1164 echo "rfc1991" >gpghome/gpg.conf &&
1165 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1166 git tag -l -n1 rfc1991-signed-tag >actual &&
1167 test_cmp expect actual &&
1168 git tag -l -n2 rfc1991-signed-tag >actual &&
1169 test_cmp expect actual &&
1170 git tag -l -n999 rfc1991-signed-tag >actual &&
1171 test_cmp expect actual
1174 rm -f gpghome/gpg.conf
1176 test_expect_success GPG,RFC1991 \
1177 'verifying rfc1991 signature without --rfc1991' '
1178 git tag -v rfc1991-signed-tag
1181 test_expect_success GPG,RFC1991 \
1182 'list tag with rfc1991 signature without --rfc1991' '
1183 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1184 git tag -l -n1 rfc1991-signed-tag >actual &&
1185 test_cmp expect actual &&
1186 git tag -l -n2 rfc1991-signed-tag >actual &&
1187 test_cmp expect actual &&
1188 git tag -l -n999 rfc1991-signed-tag >actual &&
1189 test_cmp expect actual
1192 test_expect_success GPG,RFC1991 \
1193 'reediting a signed tag body omits signature' '
1194 echo "RFC1991 signed tag" >expect &&
1195 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1196 test_cmp expect actual
1199 # try to sign with bad user.signingkey
1200 test_expect_success GPG \
1201 'git tag -s fails if gpg is misconfigured (bad key)' \
1202 'test_config user.signingkey BobTheMouse &&
1203 test_must_fail git tag -s -m tail tag-gpg-failure'
1205 # try to produce invalid signature
1206 test_expect_success GPG \
1207 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1208 'test_config gpg.program echo &&
1209 test_must_fail git tag -s -m tail tag-gpg-failure'
1212 # try to verify without gpg:
1214 rm -rf gpghome
1215 test_expect_success GPG \
1216 'verify signed tag fails when public key is not present' \
1217 'test_must_fail git tag -v signed-tag'
1219 test_expect_success \
1220 'git tag -a fails if tag annotation is empty' '
1221 ! (GIT_EDITOR=cat git tag -a initial-comment)
1224 test_expect_success \
1225 'message in editor has initial comment' '
1226 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1229 test_expect_success 'message in editor has initial comment: first line' '
1230 # check the first line --- should be empty
1231 echo >first.expect &&
1232 sed -e 1q <actual >first.actual &&
1233 test_i18ncmp first.expect first.actual
1236 test_expect_success \
1237 'message in editor has initial comment: remainder' '
1238 # remove commented lines from the remainder -- should be empty
1239 >rest.expect &&
1240 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1241 test_cmp rest.expect rest.actual
1244 get_tag_header reuse $commit commit $time >expect
1245 echo "An annotation to be reused" >> expect
1246 test_expect_success \
1247 'overwriting an annoted tag should use its previous body' '
1248 git tag -a -m "An annotation to be reused" reuse &&
1249 GIT_EDITOR=true git tag -f -a reuse &&
1250 get_tag_msg reuse >actual &&
1251 test_cmp expect actual
1254 test_expect_success 'filename for the message is relative to cwd' '
1255 mkdir subdir &&
1256 echo "Tag message in top directory" >msgfile-5 &&
1257 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1259 cd subdir &&
1260 git tag -a -F msgfile-5 tag-from-subdir
1261 ) &&
1262 git cat-file tag tag-from-subdir | grep "in sub directory"
1265 test_expect_success 'filename for the message is relative to cwd' '
1266 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1268 cd subdir &&
1269 git tag -a -F msgfile-6 tag-from-subdir-2
1270 ) &&
1271 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1274 # create a few more commits to test --contains
1276 hash1=$(git rev-parse HEAD)
1278 test_expect_success 'creating second commit and tag' '
1279 echo foo-2.0 >foo &&
1280 git add foo &&
1281 git commit -m second &&
1282 git tag v2.0
1285 hash2=$(git rev-parse HEAD)
1287 test_expect_success 'creating third commit without tag' '
1288 echo foo-dev >foo &&
1289 git add foo &&
1290 git commit -m third
1293 hash3=$(git rev-parse HEAD)
1295 # simple linear checks of --continue
1297 cat > expected <<EOF
1298 v0.2.1
1299 v1.0
1300 v1.0.1
1301 v1.1.3
1302 v2.0
1305 test_expect_success 'checking that first commit is in all tags (hash)' "
1306 git tag -l --contains $hash1 v* >actual &&
1307 test_cmp expected actual
1310 # other ways of specifying the commit
1311 test_expect_success 'checking that first commit is in all tags (tag)' "
1312 git tag -l --contains v1.0 v* >actual &&
1313 test_cmp expected actual
1316 test_expect_success 'checking that first commit is in all tags (relative)' "
1317 git tag -l --contains HEAD~2 v* >actual &&
1318 test_cmp expected actual
1321 cat > expected <<EOF
1322 v2.0
1325 test_expect_success 'checking that second commit only has one tag' "
1326 git tag -l --contains $hash2 v* >actual &&
1327 test_cmp expected actual
1331 cat > expected <<EOF
1334 test_expect_success 'checking that third commit has no tags' "
1335 git tag -l --contains $hash3 v* >actual &&
1336 test_cmp expected actual
1339 # how about a simple merge?
1341 test_expect_success 'creating simple branch' '
1342 git branch stable v2.0 &&
1343 git checkout stable &&
1344 echo foo-3.0 > foo &&
1345 git commit foo -m fourth &&
1346 git tag v3.0
1349 hash4=$(git rev-parse HEAD)
1351 cat > expected <<EOF
1352 v3.0
1355 test_expect_success 'checking that branch head only has one tag' "
1356 git tag -l --contains $hash4 v* >actual &&
1357 test_cmp expected actual
1360 test_expect_success 'merging original branch into this branch' '
1361 git merge --strategy=ours master &&
1362 git tag v4.0
1365 cat > expected <<EOF
1366 v4.0
1369 test_expect_success 'checking that original branch head has one tag now' "
1370 git tag -l --contains $hash3 v* >actual &&
1371 test_cmp expected actual
1374 cat > expected <<EOF
1375 v0.2.1
1376 v1.0
1377 v1.0.1
1378 v1.1.3
1379 v2.0
1380 v3.0
1381 v4.0
1384 test_expect_success 'checking that initial commit is in all tags' "
1385 git tag -l --contains $hash1 v* >actual &&
1386 test_cmp expected actual
1389 # mixing modes and options:
1391 test_expect_success 'mixing incompatibles modes and options is forbidden' '
1392 test_must_fail git tag -a &&
1393 test_must_fail git tag -l -v &&
1394 test_must_fail git tag -n 100 &&
1395 test_must_fail git tag -l -m msg &&
1396 test_must_fail git tag -l -F some file &&
1397 test_must_fail git tag -v -s
1400 # check points-at
1402 test_expect_success '--points-at cannot be used in non-list mode' '
1403 test_must_fail git tag --points-at=v4.0 foo
1406 test_expect_success '--points-at finds lightweight tags' '
1407 echo v4.0 >expect &&
1408 git tag --points-at v4.0 >actual &&
1409 test_cmp expect actual
1412 test_expect_success '--points-at finds annotated tags of commits' '
1413 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1414 echo annotated-v4.0 >expect &&
1415 git tag -l --points-at v4.0 "annotated*" >actual &&
1416 test_cmp expect actual
1419 test_expect_success '--points-at finds annotated tags of tags' '
1420 git tag -m "describing the v4.0 tag object" \
1421 annotated-again-v4.0 annotated-v4.0 &&
1422 cat >expect <<-\EOF &&
1423 annotated-again-v4.0
1424 annotated-v4.0
1426 git tag --points-at=annotated-v4.0 >actual &&
1427 test_cmp expect actual
1430 test_expect_success 'multiple --points-at are OR-ed together' '
1431 cat >expect <<-\EOF &&
1432 v2.0
1433 v3.0
1435 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1436 test_cmp expect actual
1439 test_expect_success 'lexical sort' '
1440 git tag foo1.3 &&
1441 git tag foo1.6 &&
1442 git tag foo1.10 &&
1443 git tag -l --sort=refname "foo*" >actual &&
1444 cat >expect <<-\EOF &&
1445 foo1.10
1446 foo1.3
1447 foo1.6
1449 test_cmp expect actual
1452 test_expect_success 'version sort' '
1453 git tag -l --sort=version:refname "foo*" >actual &&
1454 cat >expect <<-\EOF &&
1455 foo1.3
1456 foo1.6
1457 foo1.10
1459 test_cmp expect actual
1462 test_expect_success 'reverse version sort' '
1463 git tag -l --sort=-version:refname "foo*" >actual &&
1464 cat >expect <<-\EOF &&
1465 foo1.10
1466 foo1.6
1467 foo1.3
1469 test_cmp expect actual
1472 test_expect_success 'reverse lexical sort' '
1473 git tag -l --sort=-refname "foo*" >actual &&
1474 cat >expect <<-\EOF &&
1475 foo1.6
1476 foo1.3
1477 foo1.10
1479 test_cmp expect actual
1482 test_expect_success 'configured lexical sort' '
1483 test_config tag.sort "v:refname" &&
1484 git tag -l "foo*" >actual &&
1485 cat >expect <<-\EOF &&
1486 foo1.3
1487 foo1.6
1488 foo1.10
1490 test_cmp expect actual
1493 test_expect_success 'option override configured sort' '
1494 test_config tag.sort "v:refname" &&
1495 git tag -l --sort=-refname "foo*" >actual &&
1496 cat >expect <<-\EOF &&
1497 foo1.6
1498 foo1.3
1499 foo1.10
1501 test_cmp expect actual
1504 test_expect_success 'invalid sort parameter on command line' '
1505 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1508 test_expect_success 'invalid sort parameter in configuratoin' '
1509 test_config tag.sort "v:notvalid" &&
1510 test_must_fail git tag -l "foo*"
1513 test_expect_success 'version sort with prerelease reordering' '
1514 test_config versionsort.prereleaseSuffix -rc &&
1515 git tag foo1.6-rc1 &&
1516 git tag foo1.6-rc2 &&
1517 git tag -l --sort=version:refname "foo*" >actual &&
1518 cat >expect <<-\EOF &&
1519 foo1.3
1520 foo1.6-rc1
1521 foo1.6-rc2
1522 foo1.6
1523 foo1.10
1525 test_cmp expect actual
1528 test_expect_success 'reverse version sort with prerelease reordering' '
1529 test_config versionsort.prereleaseSuffix -rc &&
1530 git tag -l --sort=-version:refname "foo*" >actual &&
1531 cat >expect <<-\EOF &&
1532 foo1.10
1533 foo1.6
1534 foo1.6-rc2
1535 foo1.6-rc1
1536 foo1.3
1538 test_cmp expect actual
1541 run_with_limited_stack () {
1542 (ulimit -s 128 && "$@")
1545 test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1547 # we require ulimit, this excludes Windows
1548 test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1549 >expect &&
1550 i=1 &&
1551 while test $i -lt 8000
1553 echo "commit refs/heads/master
1554 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1555 data <<EOF
1556 commit #$i
1557 EOF"
1558 test $i = 1 && echo "from refs/heads/master^0"
1559 i=$(($i + 1))
1560 done | git fast-import &&
1561 git checkout master &&
1562 git tag far-far-away HEAD^ &&
1563 run_with_limited_stack git tag --contains HEAD >actual &&
1564 test_cmp expect actual
1567 test_expect_success '--format should list tags as per format given' '
1568 cat >expect <<-\EOF &&
1569 refname : refs/tags/foo1.10
1570 refname : refs/tags/foo1.3
1571 refname : refs/tags/foo1.6
1572 refname : refs/tags/foo1.6-rc1
1573 refname : refs/tags/foo1.6-rc2
1575 git tag -l --format="refname : %(refname)" "foo*" >actual &&
1576 test_cmp expect actual
1579 test_expect_success 'setup --merged test tags' '
1580 git tag mergetest-1 HEAD~2 &&
1581 git tag mergetest-2 HEAD~1 &&
1582 git tag mergetest-3 HEAD
1585 test_expect_success '--merged cannot be used in non-list mode' '
1586 test_must_fail git tag --merged=mergetest-2 foo
1589 test_expect_success '--merged shows merged tags' '
1590 cat >expect <<-\EOF &&
1591 mergetest-1
1592 mergetest-2
1594 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1595 test_cmp expect actual
1598 test_expect_success '--no-merged show unmerged tags' '
1599 cat >expect <<-\EOF &&
1600 mergetest-3
1602 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1603 test_cmp expect actual
1606 test_expect_success 'ambiguous branch/tags not marked' '
1607 git tag ambiguous &&
1608 git branch ambiguous &&
1609 echo ambiguous >expect &&
1610 git tag -l ambiguous >actual &&
1611 test_cmp expect actual
1614 test_done