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