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