1#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
6test_description='git tag
7
8Tests for operations with tags.'
9
10. ./test-lib.sh
11. "$TEST_DIRECTORY"/lib-gpg.sh
12
13# creating and listing lightweight tags:
14
15tag_exists () {
16 git show-ref --quiet --verify refs/tags/"$1"
17}
18
19# todo: git tag -l now returns always zero, when fixed, change this test
20test_expect_success 'listing all tags in an empty tree should succeed' '
21 git tag -l &&
22 git tag
23'
24
25test_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
28'
29
30test_expect_success 'sort tags, ignore case' '
31 (
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
51 )
52'
53
54test_expect_success 'looking for a tag in an empty tree should fail' \
55 '! (tag_exists mytag)'
56
57test_expect_success 'creating a tag in an empty tree should fail' '
58 test_must_fail git tag mynotag &&
59 ! tag_exists mynotag
60'
61
62test_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
65'
66
67test_expect_success 'creating a tag for an unknown revision should fail' '
68 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
69 ! tag_exists mytagnorev
70'
71
72# commit used in the tests, test_tick is also called here to freeze the date:
73test_expect_success 'creating a tag using default HEAD should succeed' '
74 test_tick &&
75 echo foo >foo &&
76 git add foo &&
77 git commit -m Foo &&
78 git tag mytag &&
79 test_must_fail git reflog exists refs/tags/mytag
80'
81
82test_expect_success 'creating a tag with --create-reflog should create reflog' '
83 test_when_finished "git tag -d tag_with_reflog" &&
84 git tag --create-reflog tag_with_reflog &&
85 git reflog exists refs/tags/tag_with_reflog
86'
87
88test_expect_success '--create-reflog does not create reflog on failure' '
89 test_must_fail git tag --create-reflog mytag &&
90 test_must_fail git reflog exists refs/tags/mytag
91'
92
93test_expect_success 'listing all tags if one exists should succeed' '
94 git tag -l &&
95 git tag
96'
97
98test_expect_success 'listing all tags if one exists should output that tag' '
99 test $(git tag -l) = mytag &&
100 test $(git tag) = mytag
101'
102
103# pattern matching:
104
105test_expect_success 'listing a tag using a matching pattern should succeed' \
106 'git tag -l mytag'
107
108test_expect_success 'listing a tag with --ignore-case' \
109 'test $(git tag -l --ignore-case MYTAG) = mytag'
110
111test_expect_success \
112 'listing a tag using a matching pattern should output that tag' \
113 'test $(git tag -l mytag) = mytag'
114
115# todo: git tag -l now returns always zero, when fixed, change this test
116test_expect_success \
117 'listing tags using a non-matching pattern should suceed' \
118 'git tag -l xxx'
119
120test_expect_success \
121 'listing tags using a non-matching pattern should output nothing' \
122 'test $(git tag -l xxx | wc -l) -eq 0'
123
124# special cases for creating tags:
125
126test_expect_success \
127 'trying to create a tag with the name of one existing should fail' \
128 'test_must_fail git tag mytag'
129
130test_expect_success \
131 'trying to create a tag with a non-valid name should fail' '
132 test $(git tag -l | wc -l) -eq 1 &&
133 test_must_fail git tag "" &&
134 test_must_fail git tag .othertag &&
135 test_must_fail git tag "other tag" &&
136 test_must_fail git tag "othertag^" &&
137 test_must_fail git tag "other~tag" &&
138 test $(git tag -l | wc -l) -eq 1
139'
140
141test_expect_success 'creating a tag using HEAD directly should succeed' '
142 git tag myhead HEAD &&
143 tag_exists myhead
144'
145
146test_expect_success '--force can create a tag with the name of one existing' '
147 tag_exists mytag &&
148 git tag --force mytag &&
149 tag_exists mytag'
150
151test_expect_success '--force is moot with a non-existing tag name' '
152 test_when_finished git tag -d newtag forcetag &&
153 git tag newtag >expect &&
154 git tag --force forcetag >actual &&
155 test_cmp expect actual
156'
157
158# deleting tags:
159
160test_expect_success 'trying to delete an unknown tag should fail' '
161 ! tag_exists unknown-tag &&
162 test_must_fail git tag -d unknown-tag
163'
164
165cat >expect <<EOF
166myhead
167mytag
168EOF
169test_expect_success \
170 'trying to delete tags without params should succeed and do nothing' '
171 git tag -l > actual && test_cmp expect actual &&
172 git tag -d &&
173 git tag -l > actual && test_cmp expect actual
174'
175
176test_expect_success \
177 'deleting two existing tags in one command should succeed' '
178 tag_exists mytag &&
179 tag_exists myhead &&
180 git tag -d mytag myhead &&
181 ! tag_exists mytag &&
182 ! tag_exists myhead
183'
184
185test_expect_success \
186 'creating a tag with the name of another deleted one should succeed' '
187 ! tag_exists mytag &&
188 git tag mytag &&
189 tag_exists mytag
190'
191
192test_expect_success \
193 'trying to delete two tags, existing and not, should fail in the 2nd' '
194 tag_exists mytag &&
195 ! tag_exists myhead &&
196 test_must_fail git tag -d mytag anothertag &&
197 ! tag_exists mytag &&
198 ! tag_exists myhead
199'
200
201test_expect_success 'trying to delete an already deleted tag should fail' \
202 'test_must_fail git tag -d mytag'
203
204# listing various tags with pattern matching:
205
206cat >expect <<EOF
207a1
208aa1
209cba
210t210
211t211
212v0.2.1
213v1.0
214v1.0.1
215v1.1.3
216EOF
217test_expect_success 'listing all tags should print them ordered' '
218 git tag v1.0.1 &&
219 git tag t211 &&
220 git tag aa1 &&
221 git tag v0.2.1 &&
222 git tag v1.1.3 &&
223 git tag cba &&
224 git tag a1 &&
225 git tag v1.0 &&
226 git tag t210 &&
227 git tag -l > actual &&
228 test_cmp expect actual &&
229 git tag > actual &&
230 test_cmp expect actual
231'
232
233cat >expect <<EOF
234a1
235aa1
236cba
237EOF
238test_expect_success \
239 'listing tags with substring as pattern must print those matching' '
240 rm *a* &&
241 git tag -l "*a*" > current &&
242 test_cmp expect current
243'
244
245cat >expect <<EOF
246v0.2.1
247v1.0.1
248EOF
249test_expect_success \
250 'listing tags with a suffix as pattern must print those matching' '
251 git tag -l "*.1" > actual &&
252 test_cmp expect actual
253'
254
255cat >expect <<EOF
256t210
257t211
258EOF
259test_expect_success \
260 'listing tags with a prefix as pattern must print those matching' '
261 git tag -l "t21*" > actual &&
262 test_cmp expect actual
263'
264
265cat >expect <<EOF
266a1
267EOF
268test_expect_success \
269 'listing tags using a name as pattern must print that one matching' '
270 git tag -l a1 > actual &&
271 test_cmp expect actual
272'
273
274cat >expect <<EOF
275v1.0
276EOF
277test_expect_success \
278 'listing tags using a name as pattern must print that one matching' '
279 git tag -l v1.0 > actual &&
280 test_cmp expect actual
281'
282
283cat >expect <<EOF
284v1.0.1
285v1.1.3
286EOF
287test_expect_success \
288 'listing tags with ? in the pattern should print those matching' '
289 git tag -l "v1.?.?" > actual &&
290 test_cmp expect actual
291'
292
293>expect
294test_expect_success \
295 'listing tags using v.* should print nothing because none have v.' '
296 git tag -l "v.*" > actual &&
297 test_cmp expect actual
298'
299
300cat >expect <<EOF
301v0.2.1
302v1.0
303v1.0.1
304v1.1.3
305EOF
306test_expect_success \
307 'listing tags using v* should print only those having v' '
308 git tag -l "v*" > actual &&
309 test_cmp expect actual
310'
311
312test_expect_success 'tag -l can accept multiple patterns' '
313 git tag -l "v1*" "v0*" >actual &&
314 test_cmp expect actual
315'
316
317test_expect_success 'listing tags in column' '
318 COLUMNS=40 git tag -l --column=row >actual &&
319 cat >expected <<\EOF &&
320a1 aa1 cba t210 t211
321v0.2.1 v1.0 v1.0.1 v1.1.3
322EOF
323 test_cmp expected actual
324'
325
326test_expect_success 'listing tags in column with column.*' '
327 test_config column.tag row &&
328 test_config column.ui dense &&
329 COLUMNS=40 git tag -l >actual &&
330 cat >expected <<\EOF &&
331a1 aa1 cba t210 t211
332v0.2.1 v1.0 v1.0.1 v1.1.3
333EOF
334 test_cmp expected actual
335'
336
337test_expect_success 'listing tag with -n --column should fail' '
338 test_must_fail git tag --column -n
339'
340
341test_expect_success 'listing tags -n in column with column.ui ignored' '
342 test_config column.ui "row dense" &&
343 COLUMNS=40 git tag -l -n >actual &&
344 cat >expected <<\EOF &&
345a1 Foo
346aa1 Foo
347cba Foo
348t210 Foo
349t211 Foo
350v0.2.1 Foo
351v1.0 Foo
352v1.0.1 Foo
353v1.1.3 Foo
354EOF
355 test_cmp expected actual
356'
357
358# creating and verifying lightweight tags:
359
360test_expect_success \
361 'a non-annotated tag created without parameters should point to HEAD' '
362 git tag non-annotated-tag &&
363 test $(git cat-file -t non-annotated-tag) = commit &&
364 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
365'
366
367test_expect_success 'trying to verify an unknown tag should fail' \
368 'test_must_fail git tag -v unknown-tag'
369
370test_expect_success \
371 'trying to verify a non-annotated and non-signed tag should fail' \
372 'test_must_fail git tag -v non-annotated-tag'
373
374test_expect_success \
375 'trying to verify many non-annotated or unknown tags, should fail' \
376 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
377
378# creating annotated tags:
379
380get_tag_msg () {
381 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
382}
383
384# run test_tick before committing always gives the time in that timezone
385get_tag_header () {
386cat <<EOF
387object $2
388type $3
389tag $1
390tagger C O Mitter <committer@example.com> $4 -0700
391
392EOF
393}
394
395commit=$(git rev-parse HEAD)
396time=$test_tick
397
398get_tag_header annotated-tag $commit commit $time >expect
399echo "A message" >>expect
400test_expect_success \
401 'creating an annotated tag with -m message should succeed' '
402 git tag -m "A message" annotated-tag &&
403 get_tag_msg annotated-tag >actual &&
404 test_cmp expect actual
405'
406
407cat >msgfile <<EOF
408Another message
409in a file.
410EOF
411get_tag_header file-annotated-tag $commit commit $time >expect
412cat msgfile >>expect
413test_expect_success \
414 'creating an annotated tag with -F messagefile should succeed' '
415 git tag -F msgfile file-annotated-tag &&
416 get_tag_msg file-annotated-tag >actual &&
417 test_cmp expect actual
418'
419
420cat >inputmsg <<EOF
421A message from the
422standard input
423EOF
424get_tag_header stdin-annotated-tag $commit commit $time >expect
425cat inputmsg >>expect
426test_expect_success 'creating an annotated tag with -F - should succeed' '
427 git tag -F - stdin-annotated-tag <inputmsg &&
428 get_tag_msg stdin-annotated-tag >actual &&
429 test_cmp expect actual
430'
431
432test_expect_success \
433 'trying to create a tag with a non-existing -F file should fail' '
434 ! test -f nonexistingfile &&
435 ! tag_exists notag &&
436 test_must_fail git tag -F nonexistingfile notag &&
437 ! tag_exists notag
438'
439
440test_expect_success \
441 'trying to create tags giving both -m or -F options should fail' '
442 echo "message file 1" >msgfile1 &&
443 echo "message file 2" >msgfile2 &&
444 ! tag_exists msgtag &&
445 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
446 ! tag_exists msgtag &&
447 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
448 ! tag_exists msgtag &&
449 test_must_fail git tag -m "message 1" -F msgfile1 \
450 -m "message 2" msgtag &&
451 ! tag_exists msgtag
452'
453
454# blank and empty messages:
455
456get_tag_header empty-annotated-tag $commit commit $time >expect
457test_expect_success \
458 'creating a tag with an empty -m message should succeed' '
459 git tag -m "" empty-annotated-tag &&
460 get_tag_msg empty-annotated-tag >actual &&
461 test_cmp expect actual
462'
463
464>emptyfile
465get_tag_header emptyfile-annotated-tag $commit commit $time >expect
466test_expect_success \
467 'creating a tag with an empty -F messagefile should succeed' '
468 git tag -F emptyfile emptyfile-annotated-tag &&
469 get_tag_msg emptyfile-annotated-tag >actual &&
470 test_cmp expect actual
471'
472
473printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
474printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
475printf '\n\n\nTrailing spaces \t \n' >>blanksfile
476printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
477get_tag_header blanks-annotated-tag $commit commit $time >expect
478cat >>expect <<EOF
479Leading blank lines
480
481Repeated blank lines
482
483Trailing spaces
484
485Trailing blank lines
486EOF
487test_expect_success \
488 'extra blanks in the message for an annotated tag should be removed' '
489 git tag -F blanksfile blanks-annotated-tag &&
490 get_tag_msg blanks-annotated-tag >actual &&
491 test_cmp expect actual
492'
493
494get_tag_header blank-annotated-tag $commit commit $time >expect
495test_expect_success \
496 'creating a tag with blank -m message with spaces should succeed' '
497 git tag -m " " blank-annotated-tag &&
498 get_tag_msg blank-annotated-tag >actual &&
499 test_cmp expect actual
500'
501
502echo ' ' >blankfile
503echo '' >>blankfile
504echo ' ' >>blankfile
505get_tag_header blankfile-annotated-tag $commit commit $time >expect
506test_expect_success \
507 'creating a tag with blank -F messagefile with spaces should succeed' '
508 git tag -F blankfile blankfile-annotated-tag &&
509 get_tag_msg blankfile-annotated-tag >actual &&
510 test_cmp expect actual
511'
512
513printf ' ' >blanknonlfile
514get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
515test_expect_success \
516 'creating a tag with -F file of spaces and no newline should succeed' '
517 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
518 get_tag_msg blanknonlfile-annotated-tag >actual &&
519 test_cmp expect actual
520'
521
522# messages with commented lines:
523
524cat >commentsfile <<EOF
525# A comment
526
527############
528The message.
529############
530One line.
531
532
533# commented lines
534# commented lines
535
536Another line.
537# comments
538
539Last line.
540EOF
541get_tag_header comments-annotated-tag $commit commit $time >expect
542cat >>expect <<EOF
543The message.
544One line.
545
546Another line.
547
548Last line.
549EOF
550test_expect_success \
551 'creating a tag using a -F messagefile with #comments should succeed' '
552 git tag -F commentsfile comments-annotated-tag &&
553 get_tag_msg comments-annotated-tag >actual &&
554 test_cmp expect actual
555'
556
557get_tag_header comment-annotated-tag $commit commit $time >expect
558test_expect_success \
559 'creating a tag with a #comment in the -m message should succeed' '
560 git tag -m "#comment" comment-annotated-tag &&
561 get_tag_msg comment-annotated-tag >actual &&
562 test_cmp expect actual
563'
564
565echo '#comment' >commentfile
566echo '' >>commentfile
567echo '####' >>commentfile
568get_tag_header commentfile-annotated-tag $commit commit $time >expect
569test_expect_success \
570 'creating a tag with #comments in the -F messagefile should succeed' '
571 git tag -F commentfile commentfile-annotated-tag &&
572 get_tag_msg commentfile-annotated-tag >actual &&
573 test_cmp expect actual
574'
575
576printf '#comment' >commentnonlfile
577get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
578test_expect_success \
579 'creating a tag with a file of #comment and no newline should succeed' '
580 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
581 get_tag_msg commentnonlfile-annotated-tag >actual &&
582 test_cmp expect actual
583'
584
585# listing messages for annotated non-signed tags:
586
587test_expect_success \
588 'listing the one-line message of a non-signed tag should succeed' '
589 git tag -m "A msg" tag-one-line &&
590
591 echo "tag-one-line" >expect &&
592 git tag -l | grep "^tag-one-line" >actual &&
593 test_cmp expect actual &&
594 git tag -n0 -l | grep "^tag-one-line" >actual &&
595 test_cmp expect actual &&
596 git tag -n0 -l tag-one-line >actual &&
597 test_cmp expect actual &&
598
599 echo "tag-one-line A msg" >expect &&
600 git tag -n1 -l | grep "^tag-one-line" >actual &&
601 test_cmp expect actual &&
602 git tag -n -l | grep "^tag-one-line" >actual &&
603 test_cmp expect actual &&
604 git tag -n1 -l tag-one-line >actual &&
605 test_cmp expect actual &&
606 git tag -n2 -l tag-one-line >actual &&
607 test_cmp expect actual &&
608 git tag -n999 -l tag-one-line >actual &&
609 test_cmp expect actual
610'
611
612test_expect_success \
613 'listing the zero-lines message of a non-signed tag should succeed' '
614 git tag -m "" tag-zero-lines &&
615
616 echo "tag-zero-lines" >expect &&
617 git tag -l | grep "^tag-zero-lines" >actual &&
618 test_cmp expect actual &&
619 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
620 test_cmp expect actual &&
621 git tag -n0 -l tag-zero-lines >actual &&
622 test_cmp expect actual &&
623
624 echo "tag-zero-lines " >expect &&
625 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
626 test_cmp expect actual &&
627 git tag -n -l | grep "^tag-zero-lines" >actual &&
628 test_cmp expect actual &&
629 git tag -n1 -l tag-zero-lines >actual &&
630 test_cmp expect actual &&
631 git tag -n2 -l tag-zero-lines >actual &&
632 test_cmp expect actual &&
633 git tag -n999 -l tag-zero-lines >actual &&
634 test_cmp expect actual
635'
636
637echo 'tag line one' >annotagmsg
638echo 'tag line two' >>annotagmsg
639echo 'tag line three' >>annotagmsg
640test_expect_success \
641 'listing many message lines of a non-signed tag should succeed' '
642 git tag -F annotagmsg tag-lines &&
643
644 echo "tag-lines" >expect &&
645 git tag -l | grep "^tag-lines" >actual &&
646 test_cmp expect actual &&
647 git tag -n0 -l | grep "^tag-lines" >actual &&
648 test_cmp expect actual &&
649 git tag -n0 -l tag-lines >actual &&
650 test_cmp expect actual &&
651
652 echo "tag-lines tag line one" >expect &&
653 git tag -n1 -l | grep "^tag-lines" >actual &&
654 test_cmp expect actual &&
655 git tag -n -l | grep "^tag-lines" >actual &&
656 test_cmp expect actual &&
657 git tag -n1 -l tag-lines >actual &&
658 test_cmp expect actual &&
659
660 echo " tag line two" >>expect &&
661 git tag -n2 -l | grep "^ *tag.line" >actual &&
662 test_cmp expect actual &&
663 git tag -n2 -l tag-lines >actual &&
664 test_cmp expect actual &&
665
666 echo " tag line three" >>expect &&
667 git tag -n3 -l | grep "^ *tag.line" >actual &&
668 test_cmp expect actual &&
669 git tag -n3 -l tag-lines >actual &&
670 test_cmp expect actual &&
671 git tag -n4 -l | grep "^ *tag.line" >actual &&
672 test_cmp expect actual &&
673 git tag -n4 -l tag-lines >actual &&
674 test_cmp expect actual &&
675 git tag -n99 -l | grep "^ *tag.line" >actual &&
676 test_cmp expect actual &&
677 git tag -n99 -l tag-lines >actual &&
678 test_cmp expect actual
679'
680
681test_expect_success 'annotations for blobs are empty' '
682 blob=$(git hash-object -w --stdin <<-\EOF
683 Blob paragraph 1.
684
685 Blob paragraph 2.
686 EOF
687 ) &&
688 git tag tag-blob $blob &&
689 echo "tag-blob " >expect &&
690 git tag -n1 -l tag-blob >actual &&
691 test_cmp expect actual
692'
693
694# trying to verify annotated non-signed tags:
695
696test_expect_success GPG \
697 'trying to verify an annotated non-signed tag should fail' '
698 tag_exists annotated-tag &&
699 test_must_fail git tag -v annotated-tag
700'
701
702test_expect_success GPG \
703 'trying to verify a file-annotated non-signed tag should fail' '
704 tag_exists file-annotated-tag &&
705 test_must_fail git tag -v file-annotated-tag
706'
707
708test_expect_success GPG \
709 'trying to verify two annotated non-signed tags should fail' '
710 tag_exists annotated-tag file-annotated-tag &&
711 test_must_fail git tag -v annotated-tag file-annotated-tag
712'
713
714# creating and verifying signed tags:
715
716get_tag_header signed-tag $commit commit $time >expect
717echo 'A signed tag message' >>expect
718echo '-----BEGIN PGP SIGNATURE-----' >>expect
719test_expect_success GPG 'creating a signed tag with -m message should succeed' '
720 git tag -s -m "A signed tag message" signed-tag &&
721 get_tag_msg signed-tag >actual &&
722 test_cmp expect actual
723'
724
725get_tag_header u-signed-tag $commit commit $time >expect
726echo 'Another message' >>expect
727echo '-----BEGIN PGP SIGNATURE-----' >>expect
728test_expect_success GPG 'sign with a given key id' '
729
730 git tag -u committer@example.com -m "Another message" u-signed-tag &&
731 get_tag_msg u-signed-tag >actual &&
732 test_cmp expect actual
733
734'
735
736test_expect_success GPG 'sign with an unknown id (1)' '
737
738 test_must_fail git tag -u author@example.com \
739 -m "Another message" o-signed-tag
740
741'
742
743test_expect_success GPG 'sign with an unknown id (2)' '
744
745 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
746
747'
748
749cat >fakeeditor <<'EOF'
750#!/bin/sh
751test -n "$1" && exec >"$1"
752echo A signed tag message
753echo from a fake editor.
754EOF
755chmod +x fakeeditor
756
757get_tag_header implied-sign $commit commit $time >expect
758./fakeeditor >>expect
759echo '-----BEGIN PGP SIGNATURE-----' >>expect
760test_expect_success GPG '-u implies signed tag' '
761 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
762 get_tag_msg implied-sign >actual &&
763 test_cmp expect actual
764'
765
766cat >sigmsgfile <<EOF
767Another signed tag
768message in a file.
769EOF
770get_tag_header file-signed-tag $commit commit $time >expect
771cat sigmsgfile >>expect
772echo '-----BEGIN PGP SIGNATURE-----' >>expect
773test_expect_success GPG \
774 'creating a signed tag with -F messagefile should succeed' '
775 git tag -s -F sigmsgfile file-signed-tag &&
776 get_tag_msg file-signed-tag >actual &&
777 test_cmp expect actual
778'
779
780cat >siginputmsg <<EOF
781A signed tag message from
782the standard input
783EOF
784get_tag_header stdin-signed-tag $commit commit $time >expect
785cat siginputmsg >>expect
786echo '-----BEGIN PGP SIGNATURE-----' >>expect
787test_expect_success GPG 'creating a signed tag with -F - should succeed' '
788 git tag -s -F - stdin-signed-tag <siginputmsg &&
789 get_tag_msg stdin-signed-tag >actual &&
790 test_cmp expect actual
791'
792
793get_tag_header implied-annotate $commit commit $time >expect
794./fakeeditor >>expect
795echo '-----BEGIN PGP SIGNATURE-----' >>expect
796test_expect_success GPG '-s implies annotated tag' '
797 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
798 get_tag_msg implied-annotate >actual &&
799 test_cmp expect actual
800'
801
802get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
803echo "A message" >>expect
804echo '-----BEGIN PGP SIGNATURE-----' >>expect
805test_expect_success GPG \
806 'git tag -s implied if configured with tag.forcesignannotated' \
807 'test_config tag.forcesignannotated true &&
808 git tag -m "A message" forcesignannotated-implied-sign &&
809 get_tag_msg forcesignannotated-implied-sign >actual &&
810 test_cmp expect actual
811'
812
813test_expect_success GPG \
814 'lightweight with no message when configured with tag.forcesignannotated' \
815 'test_config tag.forcesignannotated true &&
816 git tag forcesignannotated-lightweight &&
817 tag_exists forcesignannotated-lightweight &&
818 test_must_fail git tag -v forcesignannotated-no-message
819'
820
821get_tag_header forcesignannotated-annotate $commit commit $time >expect
822echo "A message" >>expect
823test_expect_success GPG \
824 'git tag -a disable configured tag.forcesignannotated' \
825 'test_config tag.forcesignannotated true &&
826 git tag -a -m "A message" forcesignannotated-annotate &&
827 get_tag_msg forcesignannotated-annotate >actual &&
828 test_cmp expect actual &&
829 test_must_fail git tag -v forcesignannotated-annotate
830'
831
832get_tag_header forcesignannotated-disabled $commit commit $time >expect
833echo "A message" >>expect
834echo '-----BEGIN PGP SIGNATURE-----' >>expect
835test_expect_success GPG \
836 'git tag --sign enable GPG sign' \
837 'test_config tag.forcesignannotated false &&
838 git tag --sign -m "A message" forcesignannotated-disabled &&
839 get_tag_msg forcesignannotated-disabled >actual &&
840 test_cmp expect actual
841'
842
843test_expect_success GPG \
844 'trying to create a signed tag with non-existing -F file should fail' '
845 ! test -f nonexistingfile &&
846 ! tag_exists nosigtag &&
847 test_must_fail git tag -s -F nonexistingfile nosigtag &&
848 ! tag_exists nosigtag
849'
850
851test_expect_success GPG 'verifying a signed tag should succeed' \
852 'git tag -v signed-tag'
853
854test_expect_success GPG 'verifying two signed tags in one command should succeed' \
855 'git tag -v signed-tag file-signed-tag'
856
857test_expect_success GPG \
858 'verifying many signed and non-signed tags should fail' '
859 test_must_fail git tag -v signed-tag annotated-tag &&
860 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
861 test_must_fail git tag -v annotated-tag \
862 file-signed-tag file-annotated-tag &&
863 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
864'
865
866test_expect_success GPG 'verifying a forged tag should fail' '
867 forged=$(git cat-file tag signed-tag |
868 sed -e "s/signed-tag/forged-tag/" |
869 git mktag) &&
870 git tag forged-tag $forged &&
871 test_must_fail git tag -v forged-tag
872'
873
874# blank and empty messages for signed tags:
875
876get_tag_header empty-signed-tag $commit commit $time >expect
877echo '-----BEGIN PGP SIGNATURE-----' >>expect
878test_expect_success GPG \
879 'creating a signed tag with an empty -m message should succeed' '
880 git tag -s -m "" empty-signed-tag &&
881 get_tag_msg empty-signed-tag >actual &&
882 test_cmp expect actual &&
883 git tag -v empty-signed-tag
884'
885
886>sigemptyfile
887get_tag_header emptyfile-signed-tag $commit commit $time >expect
888echo '-----BEGIN PGP SIGNATURE-----' >>expect
889test_expect_success GPG \
890 'creating a signed tag with an empty -F messagefile should succeed' '
891 git tag -s -F sigemptyfile emptyfile-signed-tag &&
892 get_tag_msg emptyfile-signed-tag >actual &&
893 test_cmp expect actual &&
894 git tag -v emptyfile-signed-tag
895'
896
897printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
898printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
899printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
900printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
901get_tag_header blanks-signed-tag $commit commit $time >expect
902cat >>expect <<EOF
903Leading blank lines
904
905Repeated blank lines
906
907Trailing spaces
908
909Trailing blank lines
910EOF
911echo '-----BEGIN PGP SIGNATURE-----' >>expect
912test_expect_success GPG \
913 'extra blanks in the message for a signed tag should be removed' '
914 git tag -s -F sigblanksfile blanks-signed-tag &&
915 get_tag_msg blanks-signed-tag >actual &&
916 test_cmp expect actual &&
917 git tag -v blanks-signed-tag
918'
919
920get_tag_header blank-signed-tag $commit commit $time >expect
921echo '-----BEGIN PGP SIGNATURE-----' >>expect
922test_expect_success GPG \
923 'creating a signed tag with a blank -m message should succeed' '
924 git tag -s -m " " blank-signed-tag &&
925 get_tag_msg blank-signed-tag >actual &&
926 test_cmp expect actual &&
927 git tag -v blank-signed-tag
928'
929
930echo ' ' >sigblankfile
931echo '' >>sigblankfile
932echo ' ' >>sigblankfile
933get_tag_header blankfile-signed-tag $commit commit $time >expect
934echo '-----BEGIN PGP SIGNATURE-----' >>expect
935test_expect_success GPG \
936 'creating a signed tag with blank -F file with spaces should succeed' '
937 git tag -s -F sigblankfile blankfile-signed-tag &&
938 get_tag_msg blankfile-signed-tag >actual &&
939 test_cmp expect actual &&
940 git tag -v blankfile-signed-tag
941'
942
943printf ' ' >sigblanknonlfile
944get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
945echo '-----BEGIN PGP SIGNATURE-----' >>expect
946test_expect_success GPG \
947 'creating a signed tag with spaces and no newline should succeed' '
948 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
949 get_tag_msg blanknonlfile-signed-tag >actual &&
950 test_cmp expect actual &&
951 git tag -v signed-tag
952'
953
954# messages with commented lines for signed tags:
955
956cat >sigcommentsfile <<EOF
957# A comment
958
959############
960The message.
961############
962One line.
963
964
965# commented lines
966# commented lines
967
968Another line.
969# comments
970
971Last line.
972EOF
973get_tag_header comments-signed-tag $commit commit $time >expect
974cat >>expect <<EOF
975The message.
976One line.
977
978Another line.
979
980Last line.
981EOF
982echo '-----BEGIN PGP SIGNATURE-----' >>expect
983test_expect_success GPG \
984 'creating a signed tag with a -F file with #comments should succeed' '
985 git tag -s -F sigcommentsfile comments-signed-tag &&
986 get_tag_msg comments-signed-tag >actual &&
987 test_cmp expect actual &&
988 git tag -v comments-signed-tag
989'
990
991get_tag_header comment-signed-tag $commit commit $time >expect
992echo '-----BEGIN PGP SIGNATURE-----' >>expect
993test_expect_success GPG \
994 'creating a signed tag with #commented -m message should succeed' '
995 git tag -s -m "#comment" comment-signed-tag &&
996 get_tag_msg comment-signed-tag >actual &&
997 test_cmp expect actual &&
998 git tag -v comment-signed-tag
999'
1000
1001echo '#comment' >sigcommentfile
1002echo '' >>sigcommentfile
1003echo '####' >>sigcommentfile
1004get_tag_header commentfile-signed-tag $commit commit $time >expect
1005echo '-----BEGIN PGP SIGNATURE-----' >>expect
1006test_expect_success GPG \
1007 'creating a signed tag with #commented -F messagefile should succeed' '
1008 git tag -s -F sigcommentfile commentfile-signed-tag &&
1009 get_tag_msg commentfile-signed-tag >actual &&
1010 test_cmp expect actual &&
1011 git tag -v commentfile-signed-tag
1012'
1013
1014printf '#comment' >sigcommentnonlfile
1015get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1016echo '-----BEGIN PGP SIGNATURE-----' >>expect
1017test_expect_success GPG \
1018 'creating a signed tag with a #comment and no newline should succeed' '
1019 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1020 get_tag_msg commentnonlfile-signed-tag >actual &&
1021 test_cmp expect actual &&
1022 git tag -v commentnonlfile-signed-tag
1023'
1024
1025# listing messages for signed tags:
1026
1027test_expect_success GPG \
1028 'listing the one-line message of a signed tag should succeed' '
1029 git tag -s -m "A message line signed" stag-one-line &&
1030
1031 echo "stag-one-line" >expect &&
1032 git tag -l | grep "^stag-one-line" >actual &&
1033 test_cmp expect actual &&
1034 git tag -n0 -l | grep "^stag-one-line" >actual &&
1035 test_cmp expect actual &&
1036 git tag -n0 -l stag-one-line >actual &&
1037 test_cmp expect actual &&
1038
1039 echo "stag-one-line A message line signed" >expect &&
1040 git tag -n1 -l | grep "^stag-one-line" >actual &&
1041 test_cmp expect actual &&
1042 git tag -n -l | grep "^stag-one-line" >actual &&
1043 test_cmp expect actual &&
1044 git tag -n1 -l stag-one-line >actual &&
1045 test_cmp expect actual &&
1046 git tag -n2 -l stag-one-line >actual &&
1047 test_cmp expect actual &&
1048 git tag -n999 -l stag-one-line >actual &&
1049 test_cmp expect actual
1050'
1051
1052test_expect_success GPG \
1053 'listing the zero-lines message of a signed tag should succeed' '
1054 git tag -s -m "" stag-zero-lines &&
1055
1056 echo "stag-zero-lines" >expect &&
1057 git tag -l | grep "^stag-zero-lines" >actual &&
1058 test_cmp expect actual &&
1059 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1060 test_cmp expect actual &&
1061 git tag -n0 -l stag-zero-lines >actual &&
1062 test_cmp expect actual &&
1063
1064 echo "stag-zero-lines " >expect &&
1065 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1066 test_cmp expect actual &&
1067 git tag -n -l | grep "^stag-zero-lines" >actual &&
1068 test_cmp expect actual &&
1069 git tag -n1 -l stag-zero-lines >actual &&
1070 test_cmp expect actual &&
1071 git tag -n2 -l stag-zero-lines >actual &&
1072 test_cmp expect actual &&
1073 git tag -n999 -l stag-zero-lines >actual &&
1074 test_cmp expect actual
1075'
1076
1077echo 'stag line one' >sigtagmsg
1078echo 'stag line two' >>sigtagmsg
1079echo 'stag line three' >>sigtagmsg
1080test_expect_success GPG \
1081 'listing many message lines of a signed tag should succeed' '
1082 git tag -s -F sigtagmsg stag-lines &&
1083
1084 echo "stag-lines" >expect &&
1085 git tag -l | grep "^stag-lines" >actual &&
1086 test_cmp expect actual &&
1087 git tag -n0 -l | grep "^stag-lines" >actual &&
1088 test_cmp expect actual &&
1089 git tag -n0 -l stag-lines >actual &&
1090 test_cmp expect actual &&
1091
1092 echo "stag-lines stag line one" >expect &&
1093 git tag -n1 -l | grep "^stag-lines" >actual &&
1094 test_cmp expect actual &&
1095 git tag -n -l | grep "^stag-lines" >actual &&
1096 test_cmp expect actual &&
1097 git tag -n1 -l stag-lines >actual &&
1098 test_cmp expect actual &&
1099
1100 echo " stag line two" >>expect &&
1101 git tag -n2 -l | grep "^ *stag.line" >actual &&
1102 test_cmp expect actual &&
1103 git tag -n2 -l stag-lines >actual &&
1104 test_cmp expect actual &&
1105
1106 echo " stag line three" >>expect &&
1107 git tag -n3 -l | grep "^ *stag.line" >actual &&
1108 test_cmp expect actual &&
1109 git tag -n3 -l stag-lines >actual &&
1110 test_cmp expect actual &&
1111 git tag -n4 -l | grep "^ *stag.line" >actual &&
1112 test_cmp expect actual &&
1113 git tag -n4 -l stag-lines >actual &&
1114 test_cmp expect actual &&
1115 git tag -n99 -l | grep "^ *stag.line" >actual &&
1116 test_cmp expect actual &&
1117 git tag -n99 -l stag-lines >actual &&
1118 test_cmp expect actual
1119'
1120
1121# tags pointing to objects different from commits:
1122
1123tree=$(git rev-parse HEAD^{tree})
1124blob=$(git rev-parse HEAD:foo)
1125tag=$(git rev-parse signed-tag 2>/dev/null)
1126
1127get_tag_header tree-signed-tag $tree tree $time >expect
1128echo "A message for a tree" >>expect
1129echo '-----BEGIN PGP SIGNATURE-----' >>expect
1130test_expect_success GPG \
1131 'creating a signed tag pointing to a tree should succeed' '
1132 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1133 get_tag_msg tree-signed-tag >actual &&
1134 test_cmp expect actual
1135'
1136
1137get_tag_header blob-signed-tag $blob blob $time >expect
1138echo "A message for a blob" >>expect
1139echo '-----BEGIN PGP SIGNATURE-----' >>expect
1140test_expect_success GPG \
1141 'creating a signed tag pointing to a blob should succeed' '
1142 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1143 get_tag_msg blob-signed-tag >actual &&
1144 test_cmp expect actual
1145'
1146
1147get_tag_header tag-signed-tag $tag tag $time >expect
1148echo "A message for another tag" >>expect
1149echo '-----BEGIN PGP SIGNATURE-----' >>expect
1150test_expect_success GPG \
1151 'creating a signed tag pointing to another tag should succeed' '
1152 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1153 get_tag_msg tag-signed-tag >actual &&
1154 test_cmp expect actual
1155'
1156
1157# usage with rfc1991 signatures
1158get_tag_header rfc1991-signed-tag $commit commit $time >expect
1159echo "RFC1991 signed tag" >>expect
1160echo '-----BEGIN PGP MESSAGE-----' >>expect
1161test_expect_success GPG,RFC1991 \
1162 'creating a signed tag with rfc1991' '
1163 echo "rfc1991" >gpghome/gpg.conf &&
1164 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1165 get_tag_msg rfc1991-signed-tag >actual &&
1166 test_cmp expect actual
1167'
1168
1169cat >fakeeditor <<'EOF'
1170#!/bin/sh
1171cp "$1" actual
1172EOF
1173chmod +x fakeeditor
1174
1175test_expect_success GPG,RFC1991 \
1176 'reediting a signed tag body omits signature' '
1177 echo "rfc1991" >gpghome/gpg.conf &&
1178 echo "RFC1991 signed tag" >expect &&
1179 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1180 test_cmp expect actual
1181'
1182
1183test_expect_success GPG,RFC1991 \
1184 'verifying rfc1991 signature' '
1185 echo "rfc1991" >gpghome/gpg.conf &&
1186 git tag -v rfc1991-signed-tag
1187'
1188
1189test_expect_success GPG,RFC1991 \
1190 'list tag with rfc1991 signature' '
1191 echo "rfc1991" >gpghome/gpg.conf &&
1192 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1193 git tag -l -n1 rfc1991-signed-tag >actual &&
1194 test_cmp expect actual &&
1195 git tag -l -n2 rfc1991-signed-tag >actual &&
1196 test_cmp expect actual &&
1197 git tag -l -n999 rfc1991-signed-tag >actual &&
1198 test_cmp expect actual
1199'
1200
1201rm -f gpghome/gpg.conf
1202
1203test_expect_success GPG,RFC1991 \
1204 'verifying rfc1991 signature without --rfc1991' '
1205 git tag -v rfc1991-signed-tag
1206'
1207
1208test_expect_success GPG,RFC1991 \
1209 'list tag with rfc1991 signature without --rfc1991' '
1210 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1211 git tag -l -n1 rfc1991-signed-tag >actual &&
1212 test_cmp expect actual &&
1213 git tag -l -n2 rfc1991-signed-tag >actual &&
1214 test_cmp expect actual &&
1215 git tag -l -n999 rfc1991-signed-tag >actual &&
1216 test_cmp expect actual
1217'
1218
1219test_expect_success GPG,RFC1991 \
1220 'reediting a signed tag body omits signature' '
1221 echo "RFC1991 signed tag" >expect &&
1222 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1223 test_cmp expect actual
1224'
1225
1226# try to sign with bad user.signingkey
1227test_expect_success GPG \
1228 'git tag -s fails if gpg is misconfigured (bad key)' \
1229 'test_config user.signingkey BobTheMouse &&
1230 test_must_fail git tag -s -m tail tag-gpg-failure'
1231
1232# try to produce invalid signature
1233test_expect_success GPG \
1234 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1235 'test_config gpg.program echo &&
1236 test_must_fail git tag -s -m tail tag-gpg-failure'
1237
1238
1239# try to verify without gpg:
1240
1241rm -rf gpghome
1242test_expect_success GPG \
1243 'verify signed tag fails when public key is not present' \
1244 'test_must_fail git tag -v signed-tag'
1245
1246test_expect_success \
1247 'git tag -a fails if tag annotation is empty' '
1248 ! (GIT_EDITOR=cat git tag -a initial-comment)
1249'
1250
1251test_expect_success \
1252 'message in editor has initial comment' '
1253 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1254'
1255
1256test_expect_success 'message in editor has initial comment: first line' '
1257 # check the first line --- should be empty
1258 echo >first.expect &&
1259 sed -e 1q <actual >first.actual &&
1260 test_i18ncmp first.expect first.actual
1261'
1262
1263test_expect_success \
1264 'message in editor has initial comment: remainder' '
1265 # remove commented lines from the remainder -- should be empty
1266 >rest.expect &&
1267 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1268 test_cmp rest.expect rest.actual
1269'
1270
1271get_tag_header reuse $commit commit $time >expect
1272echo "An annotation to be reused" >> expect
1273test_expect_success \
1274 'overwriting an annoted tag should use its previous body' '
1275 git tag -a -m "An annotation to be reused" reuse &&
1276 GIT_EDITOR=true git tag -f -a reuse &&
1277 get_tag_msg reuse >actual &&
1278 test_cmp expect actual
1279'
1280
1281test_expect_success 'filename for the message is relative to cwd' '
1282 mkdir subdir &&
1283 echo "Tag message in top directory" >msgfile-5 &&
1284 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1285 (
1286 cd subdir &&
1287 git tag -a -F msgfile-5 tag-from-subdir
1288 ) &&
1289 git cat-file tag tag-from-subdir | grep "in sub directory"
1290'
1291
1292test_expect_success 'filename for the message is relative to cwd' '
1293 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1294 (
1295 cd subdir &&
1296 git tag -a -F msgfile-6 tag-from-subdir-2
1297 ) &&
1298 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1299'
1300
1301# create a few more commits to test --contains
1302
1303hash1=$(git rev-parse HEAD)
1304
1305test_expect_success 'creating second commit and tag' '
1306 echo foo-2.0 >foo &&
1307 git add foo &&
1308 git commit -m second &&
1309 git tag v2.0
1310'
1311
1312hash2=$(git rev-parse HEAD)
1313
1314test_expect_success 'creating third commit without tag' '
1315 echo foo-dev >foo &&
1316 git add foo &&
1317 git commit -m third
1318'
1319
1320hash3=$(git rev-parse HEAD)
1321
1322# simple linear checks of --continue
1323
1324cat > expected <<EOF
1325v0.2.1
1326v1.0
1327v1.0.1
1328v1.1.3
1329v2.0
1330EOF
1331
1332test_expect_success 'checking that first commit is in all tags (hash)' "
1333 git tag -l --contains $hash1 v* >actual &&
1334 test_cmp expected actual
1335"
1336
1337# other ways of specifying the commit
1338test_expect_success 'checking that first commit is in all tags (tag)' "
1339 git tag -l --contains v1.0 v* >actual &&
1340 test_cmp expected actual
1341"
1342
1343test_expect_success 'checking that first commit is in all tags (relative)' "
1344 git tag -l --contains HEAD~2 v* >actual &&
1345 test_cmp expected actual
1346"
1347
1348cat > expected <<EOF
1349v2.0
1350EOF
1351
1352test_expect_success 'checking that second commit only has one tag' "
1353 git tag -l --contains $hash2 v* >actual &&
1354 test_cmp expected actual
1355"
1356
1357
1358cat > expected <<EOF
1359EOF
1360
1361test_expect_success 'checking that third commit has no tags' "
1362 git tag -l --contains $hash3 v* >actual &&
1363 test_cmp expected actual
1364"
1365
1366# how about a simple merge?
1367
1368test_expect_success 'creating simple branch' '
1369 git branch stable v2.0 &&
1370 git checkout stable &&
1371 echo foo-3.0 > foo &&
1372 git commit foo -m fourth &&
1373 git tag v3.0
1374'
1375
1376hash4=$(git rev-parse HEAD)
1377
1378cat > expected <<EOF
1379v3.0
1380EOF
1381
1382test_expect_success 'checking that branch head only has one tag' "
1383 git tag -l --contains $hash4 v* >actual &&
1384 test_cmp expected actual
1385"
1386
1387test_expect_success 'merging original branch into this branch' '
1388 git merge --strategy=ours master &&
1389 git tag v4.0
1390'
1391
1392cat > expected <<EOF
1393v4.0
1394EOF
1395
1396test_expect_success 'checking that original branch head has one tag now' "
1397 git tag -l --contains $hash3 v* >actual &&
1398 test_cmp expected actual
1399"
1400
1401cat > expected <<EOF
1402v0.2.1
1403v1.0
1404v1.0.1
1405v1.1.3
1406v2.0
1407v3.0
1408v4.0
1409EOF
1410
1411test_expect_success 'checking that initial commit is in all tags' "
1412 git tag -l --contains $hash1 v* >actual &&
1413 test_cmp expected actual
1414"
1415
1416# mixing modes and options:
1417
1418test_expect_success 'mixing incompatibles modes and options is forbidden' '
1419 test_must_fail git tag -a &&
1420 test_must_fail git tag -l -v &&
1421 test_must_fail git tag -n 100 &&
1422 test_must_fail git tag -l -m msg &&
1423 test_must_fail git tag -l -F some file &&
1424 test_must_fail git tag -v -s
1425'
1426
1427# check points-at
1428
1429test_expect_success '--points-at cannot be used in non-list mode' '
1430 test_must_fail git tag --points-at=v4.0 foo
1431'
1432
1433test_expect_success '--points-at finds lightweight tags' '
1434 echo v4.0 >expect &&
1435 git tag --points-at v4.0 >actual &&
1436 test_cmp expect actual
1437'
1438
1439test_expect_success '--points-at finds annotated tags of commits' '
1440 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1441 echo annotated-v4.0 >expect &&
1442 git tag -l --points-at v4.0 "annotated*" >actual &&
1443 test_cmp expect actual
1444'
1445
1446test_expect_success '--points-at finds annotated tags of tags' '
1447 git tag -m "describing the v4.0 tag object" \
1448 annotated-again-v4.0 annotated-v4.0 &&
1449 cat >expect <<-\EOF &&
1450 annotated-again-v4.0
1451 annotated-v4.0
1452 EOF
1453 git tag --points-at=annotated-v4.0 >actual &&
1454 test_cmp expect actual
1455'
1456
1457test_expect_success 'multiple --points-at are OR-ed together' '
1458 cat >expect <<-\EOF &&
1459 v2.0
1460 v3.0
1461 EOF
1462 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1463 test_cmp expect actual
1464'
1465
1466test_expect_success 'lexical sort' '
1467 git tag foo1.3 &&
1468 git tag foo1.6 &&
1469 git tag foo1.10 &&
1470 git tag -l --sort=refname "foo*" >actual &&
1471 cat >expect <<-\EOF &&
1472 foo1.10
1473 foo1.3
1474 foo1.6
1475 EOF
1476 test_cmp expect actual
1477'
1478
1479test_expect_success 'version sort' '
1480 git tag -l --sort=version:refname "foo*" >actual &&
1481 cat >expect <<-\EOF &&
1482 foo1.3
1483 foo1.6
1484 foo1.10
1485 EOF
1486 test_cmp expect actual
1487'
1488
1489test_expect_success 'reverse version sort' '
1490 git tag -l --sort=-version:refname "foo*" >actual &&
1491 cat >expect <<-\EOF &&
1492 foo1.10
1493 foo1.6
1494 foo1.3
1495 EOF
1496 test_cmp expect actual
1497'
1498
1499test_expect_success 'reverse lexical sort' '
1500 git tag -l --sort=-refname "foo*" >actual &&
1501 cat >expect <<-\EOF &&
1502 foo1.6
1503 foo1.3
1504 foo1.10
1505 EOF
1506 test_cmp expect actual
1507'
1508
1509test_expect_success 'configured lexical sort' '
1510 test_config tag.sort "v:refname" &&
1511 git tag -l "foo*" >actual &&
1512 cat >expect <<-\EOF &&
1513 foo1.3
1514 foo1.6
1515 foo1.10
1516 EOF
1517 test_cmp expect actual
1518'
1519
1520test_expect_success 'option override configured sort' '
1521 test_config tag.sort "v:refname" &&
1522 git tag -l --sort=-refname "foo*" >actual &&
1523 cat >expect <<-\EOF &&
1524 foo1.6
1525 foo1.3
1526 foo1.10
1527 EOF
1528 test_cmp expect actual
1529'
1530
1531test_expect_success 'invalid sort parameter on command line' '
1532 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1533'
1534
1535test_expect_success 'invalid sort parameter in configuratoin' '
1536 test_config tag.sort "v:notvalid" &&
1537 test_must_fail git tag -l "foo*"
1538'
1539
1540test_expect_success 'version sort with prerelease reordering' '
1541 test_config versionsort.prereleaseSuffix -rc &&
1542 git tag foo1.6-rc1 &&
1543 git tag foo1.6-rc2 &&
1544 git tag -l --sort=version:refname "foo*" >actual &&
1545 cat >expect <<-\EOF &&
1546 foo1.3
1547 foo1.6-rc1
1548 foo1.6-rc2
1549 foo1.6
1550 foo1.10
1551 EOF
1552 test_cmp expect actual
1553'
1554
1555test_expect_success 'reverse version sort with prerelease reordering' '
1556 test_config versionsort.prereleaseSuffix -rc &&
1557 git tag -l --sort=-version:refname "foo*" >actual &&
1558 cat >expect <<-\EOF &&
1559 foo1.10
1560 foo1.6
1561 foo1.6-rc2
1562 foo1.6-rc1
1563 foo1.3
1564 EOF
1565 test_cmp expect actual
1566'
1567
1568test_expect_success 'version sort with prerelease reordering and common leading character' '
1569 test_config versionsort.prereleaseSuffix -before &&
1570 git tag foo1.7-before1 &&
1571 git tag foo1.7 &&
1572 git tag foo1.7-after1 &&
1573 git tag -l --sort=version:refname "foo1.7*" >actual &&
1574 cat >expect <<-\EOF &&
1575 foo1.7-before1
1576 foo1.7
1577 foo1.7-after1
1578 EOF
1579 test_cmp expect actual
1580'
1581
1582test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1583 test_config versionsort.prereleaseSuffix -before &&
1584 git config --add versionsort.prereleaseSuffix -after &&
1585 git tag -l --sort=version:refname "foo1.7*" >actual &&
1586 cat >expect <<-\EOF &&
1587 foo1.7-before1
1588 foo1.7-after1
1589 foo1.7
1590 EOF
1591 test_cmp expect actual
1592'
1593
1594test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1595 test_config versionsort.prereleaseSuffix -bar &&
1596 git config --add versionsort.prereleaseSuffix -foo-baz &&
1597 git config --add versionsort.prereleaseSuffix -foo-bar &&
1598 git tag foo1.8-foo-bar &&
1599 git tag foo1.8-foo-baz &&
1600 git tag foo1.8 &&
1601 git tag -l --sort=version:refname "foo1.8*" >actual &&
1602 cat >expect <<-\EOF &&
1603 foo1.8-foo-baz
1604 foo1.8-foo-bar
1605 foo1.8
1606 EOF
1607 test_cmp expect actual
1608'
1609
1610test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1611 test_config versionsort.prereleaseSuffix -pre &&
1612 git config --add versionsort.prereleaseSuffix -prerelease &&
1613 git tag foo1.9-pre1 &&
1614 git tag foo1.9-pre2 &&
1615 git tag foo1.9-prerelease1 &&
1616 git tag -l --sort=version:refname "foo1.9*" >actual &&
1617 cat >expect <<-\EOF &&
1618 foo1.9-pre1
1619 foo1.9-pre2
1620 foo1.9-prerelease1
1621 EOF
1622 test_cmp expect actual
1623'
1624
1625test_expect_success 'version sort with general suffix reordering' '
1626 test_config versionsort.suffix -alpha &&
1627 git config --add versionsort.suffix -beta &&
1628 git config --add versionsort.suffix "" &&
1629 git config --add versionsort.suffix -gamma &&
1630 git config --add versionsort.suffix -delta &&
1631 git tag foo1.10-alpha &&
1632 git tag foo1.10-beta &&
1633 git tag foo1.10-gamma &&
1634 git tag foo1.10-delta &&
1635 git tag foo1.10-unlisted-suffix &&
1636 git tag -l --sort=version:refname "foo1.10*" >actual &&
1637 cat >expect <<-\EOF &&
1638 foo1.10-alpha
1639 foo1.10-beta
1640 foo1.10
1641 foo1.10-unlisted-suffix
1642 foo1.10-gamma
1643 foo1.10-delta
1644 EOF
1645 test_cmp expect actual
1646'
1647
1648test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1649 test_config versionsort.suffix -before &&
1650 test_config versionsort.prereleaseSuffix -after &&
1651 git tag -l --sort=version:refname "foo1.7*" >actual &&
1652 cat >expect <<-\EOF &&
1653 foo1.7-before1
1654 foo1.7
1655 foo1.7-after1
1656 EOF
1657 test_cmp expect actual
1658'
1659
1660test_expect_success 'version sort with very long prerelease suffix' '
1661 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1662 git tag -l --sort=version:refname
1663'
1664
1665run_with_limited_stack () {
1666 (ulimit -s 128 && "$@")
1667}
1668
1669test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1670
1671# we require ulimit, this excludes Windows
1672test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' '
1673 >expect &&
1674 i=1 &&
1675 while test $i -lt 8000
1676 do
1677 echo "commit refs/heads/master
1678committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1679data <<EOF
1680commit #$i
1681EOF"
1682 test $i = 1 && echo "from refs/heads/master^0"
1683 i=$(($i + 1))
1684 done | git fast-import &&
1685 git checkout master &&
1686 git tag far-far-away HEAD^ &&
1687 run_with_limited_stack git tag --contains HEAD >actual &&
1688 test_cmp expect actual
1689'
1690
1691test_expect_success '--format should list tags as per format given' '
1692 cat >expect <<-\EOF &&
1693 refname : refs/tags/v1.0
1694 refname : refs/tags/v1.0.1
1695 refname : refs/tags/v1.1.3
1696 EOF
1697 git tag -l --format="refname : %(refname)" "v1*" >actual &&
1698 test_cmp expect actual
1699'
1700
1701test_expect_success 'setup --merged test tags' '
1702 git tag mergetest-1 HEAD~2 &&
1703 git tag mergetest-2 HEAD~1 &&
1704 git tag mergetest-3 HEAD
1705'
1706
1707test_expect_success '--merged cannot be used in non-list mode' '
1708 test_must_fail git tag --merged=mergetest-2 foo
1709'
1710
1711test_expect_success '--merged shows merged tags' '
1712 cat >expect <<-\EOF &&
1713 mergetest-1
1714 mergetest-2
1715 EOF
1716 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1717 test_cmp expect actual
1718'
1719
1720test_expect_success '--no-merged show unmerged tags' '
1721 cat >expect <<-\EOF &&
1722 mergetest-3
1723 EOF
1724 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1725 test_cmp expect actual
1726'
1727
1728test_expect_success 'ambiguous branch/tags not marked' '
1729 git tag ambiguous &&
1730 git branch ambiguous &&
1731 echo ambiguous >expect &&
1732 git tag -l ambiguous >actual &&
1733 test_cmp expect actual
1734'
1735
1736test_done