]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7004-tag.sh
The sixth batch
[thirdparty/git.git] / t / t7004-tag.sh
CommitLineData
ef5a6fb5
CR
1#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
d592b315 6test_description='git tag
ef5a6fb5 7
62e09ce9 8Tests for operations with tags.'
ef5a6fb5
CR
9
10. ./test-lib.sh
37d3e859 11. "$TEST_DIRECTORY"/lib-gpg.sh
11b087ad 12. "$TEST_DIRECTORY"/lib-terminal.sh
ef5a6fb5
CR
13
14# creating and listing lightweight tags:
15
16tag_exists () {
17 git show-ref --quiet --verify refs/tags/"$1"
18}
19
62e09ce9
CR
20test_expect_success 'listing all tags in an empty tree should succeed' '
21 git tag -l &&
22 git tag
23'
ef5a6fb5 24
62e09ce9 25test_expect_success 'listing all tags in an empty tree should output nothing' '
63873a0a
EP
26 test $(git tag -l | wc -l) -eq 0 &&
27 test $(git tag | wc -l) -eq 0
62e09ce9 28'
ef5a6fb5 29
3bb16a8b
NTND
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
41ac414e
JH
54test_expect_success 'looking for a tag in an empty tree should fail' \
55 '! (tag_exists mytag)'
ef5a6fb5
CR
56
57test_expect_success 'creating a tag in an empty tree should fail' '
d592b315 58 test_must_fail git tag mynotag &&
ef5a6fb5
CR
59 ! tag_exists mynotag
60'
61
62test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
d592b315 63 test_must_fail git tag mytaghead HEAD &&
ef5a6fb5
CR
64 ! tag_exists mytaghead
65'
66
67test_expect_success 'creating a tag for an unknown revision should fail' '
d592b315 68 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
ef5a6fb5
CR
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' '
341fb286 74 test_config core.logAllRefUpdates true &&
ef5a6fb5
CR
75 test_tick &&
76 echo foo >foo &&
77 git add foo &&
78 git commit -m Foo &&
144c76fa
DT
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' '
df8512ed
CW
84 git log -1 \
85 --format="format:tag: tagging %h (%s, %cd)%n" \
86 --date=format:%Y-%m-%d >expected &&
144c76fa
DT
87 test_when_finished "git tag -d tag_with_reflog" &&
88 git tag --create-reflog tag_with_reflog &&
df8512ed
CW
89 git reflog exists refs/tags/tag_with_reflog &&
90 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
0d75bfe6 91 test_i18ncmp expected actual
df8512ed
CW
92'
93
94test_expect_success 'annotated tag with --create-reflog has correct message' '
95 git log -1 \
96 --format="format:tag: tagging %h (%s, %cd)%n" \
97 --date=format:%Y-%m-%d >expected &&
98 test_when_finished "git tag -d tag_with_reflog" &&
99 git tag -m "annotated tag" --create-reflog tag_with_reflog &&
100 git reflog exists refs/tags/tag_with_reflog &&
101 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual &&
0d75bfe6 102 test_i18ncmp expected actual
144c76fa
DT
103'
104
105test_expect_success '--create-reflog does not create reflog on failure' '
106 test_must_fail git tag --create-reflog mytag &&
107 test_must_fail git reflog exists refs/tags/mytag
ef5a6fb5
CR
108'
109
341fb286
CW
110test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
111 test_when_finished "git tag -d tag_with_reflog" &&
112 test_config core.logAllRefUpdates always &&
113 git tag tag_with_reflog &&
114 git reflog exists refs/tags/tag_with_reflog
115'
116
62e09ce9 117test_expect_success 'listing all tags if one exists should succeed' '
d592b315
NS
118 git tag -l &&
119 git tag
62e09ce9 120'
ef5a6fb5 121
c485b24c
ÆAB
122cat >expect <<EOF
123mytag
124EOF
125test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
126 git tag -l -l >actual &&
127 test_cmp expect actual &&
128 git tag --list --list >actual &&
129 test_cmp expect actual &&
130 git tag --list -l --list >actual &&
131 test_cmp expect actual
132'
133
62e09ce9 134test_expect_success 'listing all tags if one exists should output that tag' '
63873a0a
EP
135 test $(git tag -l) = mytag &&
136 test $(git tag) = mytag
62e09ce9 137'
ef5a6fb5
CR
138
139# pattern matching:
140
141test_expect_success 'listing a tag using a matching pattern should succeed' \
d592b315 142 'git tag -l mytag'
ef5a6fb5 143
3bb16a8b
NTND
144test_expect_success 'listing a tag with --ignore-case' \
145 'test $(git tag -l --ignore-case MYTAG) = mytag'
146
ef5a6fb5
CR
147test_expect_success \
148 'listing a tag using a matching pattern should output that tag' \
63873a0a 149 'test $(git tag -l mytag) = mytag'
ef5a6fb5 150
ef5a6fb5 151test_expect_success \
682b29f9 152 'listing tags using a non-matching pattern should succeed' \
d592b315 153 'git tag -l xxx'
ef5a6fb5
CR
154
155test_expect_success \
156 'listing tags using a non-matching pattern should output nothing' \
63873a0a 157 'test $(git tag -l xxx | wc -l) -eq 0'
ef5a6fb5
CR
158
159# special cases for creating tags:
160
41ac414e 161test_expect_success \
ef5a6fb5 162 'trying to create a tag with the name of one existing should fail' \
d492b31c 163 'test_must_fail git tag mytag'
ef5a6fb5
CR
164
165test_expect_success \
166 'trying to create a tag with a non-valid name should fail' '
63873a0a 167 test $(git tag -l | wc -l) -eq 1 &&
d492b31c
SB
168 test_must_fail git tag "" &&
169 test_must_fail git tag .othertag &&
170 test_must_fail git tag "other tag" &&
171 test_must_fail git tag "othertag^" &&
172 test_must_fail git tag "other~tag" &&
63873a0a 173 test $(git tag -l | wc -l) -eq 1
ef5a6fb5
CR
174'
175
176test_expect_success 'creating a tag using HEAD directly should succeed' '
177 git tag myhead HEAD &&
178 tag_exists myhead
179'
180
3ae851e6
PH
181test_expect_success '--force can create a tag with the name of one existing' '
182 tag_exists mytag &&
183 git tag --force mytag &&
184 tag_exists mytag'
185
186test_expect_success '--force is moot with a non-existing tag name' '
eba286e3 187 test_when_finished git tag -d newtag forcetag &&
3ae851e6
PH
188 git tag newtag >expect &&
189 git tag --force forcetag >actual &&
190 test_cmp expect actual
191'
3ae851e6 192
ef5a6fb5
CR
193# deleting tags:
194
195test_expect_success 'trying to delete an unknown tag should fail' '
196 ! tag_exists unknown-tag &&
d592b315 197 test_must_fail git tag -d unknown-tag
ef5a6fb5
CR
198'
199
200cat >expect <<EOF
201myhead
202mytag
203EOF
204test_expect_success \
205 'trying to delete tags without params should succeed and do nothing' '
3af82863 206 git tag -l > actual && test_cmp expect actual &&
d592b315 207 git tag -d &&
3af82863 208 git tag -l > actual && test_cmp expect actual
ef5a6fb5
CR
209'
210
211test_expect_success \
212 'deleting two existing tags in one command should succeed' '
213 tag_exists mytag &&
214 tag_exists myhead &&
d592b315 215 git tag -d mytag myhead &&
ef5a6fb5
CR
216 ! tag_exists mytag &&
217 ! tag_exists myhead
218'
219
220test_expect_success \
221 'creating a tag with the name of another deleted one should succeed' '
222 ! tag_exists mytag &&
d592b315 223 git tag mytag &&
ef5a6fb5
CR
224 tag_exists mytag
225'
226
227test_expect_success \
228 'trying to delete two tags, existing and not, should fail in the 2nd' '
229 tag_exists mytag &&
b0187199
230 ! tag_exists nonexistingtag &&
231 test_must_fail git tag -d mytag nonexistingtag &&
ef5a6fb5 232 ! tag_exists mytag &&
b0187199 233 ! tag_exists nonexistingtag
ef5a6fb5
CR
234'
235
41ac414e 236test_expect_success 'trying to delete an already deleted tag should fail' \
d592b315 237 'test_must_fail git tag -d mytag'
ef5a6fb5
CR
238
239# listing various tags with pattern matching:
240
241cat >expect <<EOF
242a1
243aa1
244cba
245t210
246t211
247v0.2.1
248v1.0
249v1.0.1
250v1.1.3
251EOF
252test_expect_success 'listing all tags should print them ordered' '
253 git tag v1.0.1 &&
254 git tag t211 &&
255 git tag aa1 &&
256 git tag v0.2.1 &&
257 git tag v1.1.3 &&
258 git tag cba &&
259 git tag a1 &&
260 git tag v1.0 &&
261 git tag t210 &&
5206d130 262 git tag -l > actual &&
3af82863 263 test_cmp expect actual &&
62e09ce9 264 git tag > actual &&
3af82863 265 test_cmp expect actual
ef5a6fb5
CR
266'
267
268cat >expect <<EOF
269a1
270aa1
271cba
272EOF
273test_expect_success \
274 'listing tags with substring as pattern must print those matching' '
0aaaef7b
JS
275 rm *a* &&
276 git tag -l "*a*" > current &&
277 test_cmp expect current
ef5a6fb5
CR
278'
279
280cat >expect <<EOF
281v0.2.1
282v1.0.1
ef5a6fb5
CR
283EOF
284test_expect_success \
18e32b5b 285 'listing tags with a suffix as pattern must print those matching' '
d592b315 286 git tag -l "*.1" > actual &&
3af82863 287 test_cmp expect actual
ef5a6fb5
CR
288'
289
290cat >expect <<EOF
291t210
292t211
293EOF
294test_expect_success \
18e32b5b 295 'listing tags with a prefix as pattern must print those matching' '
d592b315 296 git tag -l "t21*" > actual &&
3af82863 297 test_cmp expect actual
ef5a6fb5
CR
298'
299
300cat >expect <<EOF
301a1
ef5a6fb5
CR
302EOF
303test_expect_success \
18e32b5b 304 'listing tags using a name as pattern must print that one matching' '
d592b315 305 git tag -l a1 > actual &&
3af82863 306 test_cmp expect actual
ef5a6fb5
CR
307'
308
309cat >expect <<EOF
310v1.0
ef5a6fb5
CR
311EOF
312test_expect_success \
18e32b5b 313 'listing tags using a name as pattern must print that one matching' '
d592b315 314 git tag -l v1.0 > actual &&
3af82863 315 test_cmp expect actual
ef5a6fb5
CR
316'
317
318cat >expect <<EOF
18e32b5b 319v1.0.1
ef5a6fb5
CR
320v1.1.3
321EOF
322test_expect_success \
323 'listing tags with ? in the pattern should print those matching' '
d592b315 324 git tag -l "v1.?.?" > actual &&
3af82863 325 test_cmp expect actual
ef5a6fb5
CR
326'
327
ef5a6fb5
CR
328test_expect_success \
329 'listing tags using v.* should print nothing because none have v.' '
d592b315 330 git tag -l "v.*" > actual &&
1c5e94f4 331 test_must_be_empty actual
ef5a6fb5
CR
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' '
d592b315 342 git tag -l "v*" > actual &&
3af82863 343 test_cmp expect actual
ef5a6fb5
CR
344'
345
588d0e83
JK
346test_expect_success 'tag -l can accept multiple patterns' '
347 git tag -l "v1*" "v0*" >actual &&
348 test_cmp expect actual
349'
350
c485b24c
ÆAB
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
d96e3c15 364test_expect_success 'listing tags in column' '
b5d5a567 365 COLUMNS=41 git tag -l --column=row >actual &&
d96e3c15
NTND
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.*' '
9ffda48f
SG
374 test_config column.tag row &&
375 test_config column.ui dense &&
d96e3c15 376 COLUMNS=40 git tag -l >actual &&
d96e3c15
NTND
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' '
9ffda48f 389 test_config column.ui "row dense" &&
d96e3c15 390 COLUMNS=40 git tag -l -n >actual &&
d96e3c15
NTND
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
ef5a6fb5
CR
405# creating and verifying lightweight tags:
406
407test_expect_success \
408 'a non-annotated tag created without parameters should point to HEAD' '
d592b315 409 git tag non-annotated-tag &&
5be60078
JH
410 test $(git cat-file -t non-annotated-tag) = commit &&
411 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
ef5a6fb5
CR
412'
413
41ac414e 414test_expect_success 'trying to verify an unknown tag should fail' \
d592b315 415 'test_must_fail git tag -v unknown-tag'
ef5a6fb5 416
41ac414e 417test_expect_success \
ef5a6fb5 418 'trying to verify a non-annotated and non-signed tag should fail' \
d592b315 419 'test_must_fail git tag -v non-annotated-tag'
ef5a6fb5 420
41ac414e 421test_expect_success \
62e09ce9 422 'trying to verify many non-annotated or unknown tags, should fail' \
d592b315 423 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
62e09ce9 424
ef5a6fb5
CR
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' '
d592b315 449 git tag -m "A message" annotated-tag &&
ef5a6fb5 450 get_tag_msg annotated-tag >actual &&
3af82863 451 test_cmp expect actual
ef5a6fb5
CR
452'
453
9eed6e40
NMC
454get_tag_header annotated-tag-edit $commit commit $time >expect
455echo "An edited message" >>expect
456test_expect_success 'set up editor' '
457 write_script fakeeditor <<-\EOF
458 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
459 mv "$1-" "$1"
460 EOF
461'
462test_expect_success \
463 'creating an annotated tag with -m message --edit should succeed' '
464 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
465 get_tag_msg annotated-tag-edit >actual &&
466 test_cmp expect actual
467'
468
ef5a6fb5
CR
469cat >msgfile <<EOF
470Another message
471in a file.
472EOF
473get_tag_header file-annotated-tag $commit commit $time >expect
474cat msgfile >>expect
475test_expect_success \
476 'creating an annotated tag with -F messagefile should succeed' '
d592b315 477 git tag -F msgfile file-annotated-tag &&
ef5a6fb5 478 get_tag_msg file-annotated-tag >actual &&
3af82863 479 test_cmp expect actual
ef5a6fb5
CR
480'
481
9eed6e40
NMC
482get_tag_header file-annotated-tag-edit $commit commit $time >expect
483sed -e "s/Another message/Another edited message/g" msgfile >>expect
484test_expect_success 'set up editor' '
485 write_script fakeeditor <<-\EOF
486 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
487 mv "$1-" "$1"
488 EOF
489'
490test_expect_success \
491 'creating an annotated tag with -F messagefile --edit should succeed' '
492 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
493 get_tag_msg file-annotated-tag-edit >actual &&
494 test_cmp expect actual
495'
496
62e09ce9
CR
497cat >inputmsg <<EOF
498A message from the
499standard input
500EOF
501get_tag_header stdin-annotated-tag $commit commit $time >expect
502cat inputmsg >>expect
503test_expect_success 'creating an annotated tag with -F - should succeed' '
d592b315 504 git tag -F - stdin-annotated-tag <inputmsg &&
62e09ce9 505 get_tag_msg stdin-annotated-tag >actual &&
3af82863 506 test_cmp expect actual
62e09ce9
CR
507'
508
e317cfaf
CR
509test_expect_success \
510 'trying to create a tag with a non-existing -F file should fail' '
511 ! test -f nonexistingfile &&
512 ! tag_exists notag &&
d592b315 513 test_must_fail git tag -F nonexistingfile notag &&
e317cfaf
CR
514 ! tag_exists notag
515'
516
517test_expect_success \
39686585 518 'trying to create tags giving both -m or -F options should fail' '
e317cfaf 519 echo "message file 1" >msgfile1 &&
e317cfaf 520 ! tag_exists msgtag &&
d592b315 521 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
e317cfaf 522 ! tag_exists msgtag &&
d592b315 523 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
e317cfaf 524 ! tag_exists msgtag &&
d592b315 525 test_must_fail git tag -m "message 1" -F msgfile1 \
d492b31c 526 -m "message 2" msgtag &&
e317cfaf
CR
527 ! tag_exists msgtag
528'
529
ef5a6fb5
CR
530# blank and empty messages:
531
532get_tag_header empty-annotated-tag $commit commit $time >expect
533test_expect_success \
534 'creating a tag with an empty -m message should succeed' '
d592b315 535 git tag -m "" empty-annotated-tag &&
ef5a6fb5 536 get_tag_msg empty-annotated-tag >actual &&
3af82863 537 test_cmp expect actual
ef5a6fb5
CR
538'
539
540>emptyfile
541get_tag_header emptyfile-annotated-tag $commit commit $time >expect
542test_expect_success \
543 'creating a tag with an empty -F messagefile should succeed' '
d592b315 544 git tag -F emptyfile emptyfile-annotated-tag &&
ef5a6fb5 545 get_tag_msg emptyfile-annotated-tag >actual &&
3af82863 546 test_cmp expect actual
ef5a6fb5
CR
547'
548
549printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
550printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
551printf '\n\n\nTrailing spaces \t \n' >>blanksfile
552printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
553get_tag_header blanks-annotated-tag $commit commit $time >expect
554cat >>expect <<EOF
555Leading blank lines
556
557Repeated blank lines
558
559Trailing spaces
560
561Trailing blank lines
562EOF
563test_expect_success \
564 'extra blanks in the message for an annotated tag should be removed' '
d592b315 565 git tag -F blanksfile blanks-annotated-tag &&
ef5a6fb5 566 get_tag_msg blanks-annotated-tag >actual &&
3af82863 567 test_cmp expect actual
ef5a6fb5
CR
568'
569
570get_tag_header blank-annotated-tag $commit commit $time >expect
571test_expect_success \
572 'creating a tag with blank -m message with spaces should succeed' '
d592b315 573 git tag -m " " blank-annotated-tag &&
ef5a6fb5 574 get_tag_msg blank-annotated-tag >actual &&
3af82863 575 test_cmp expect actual
ef5a6fb5
CR
576'
577
578echo ' ' >blankfile
579echo '' >>blankfile
580echo ' ' >>blankfile
581get_tag_header blankfile-annotated-tag $commit commit $time >expect
582test_expect_success \
583 'creating a tag with blank -F messagefile with spaces should succeed' '
d592b315 584 git tag -F blankfile blankfile-annotated-tag &&
ef5a6fb5 585 get_tag_msg blankfile-annotated-tag >actual &&
3af82863 586 test_cmp expect actual
ef5a6fb5
CR
587'
588
589printf ' ' >blanknonlfile
590get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
591test_expect_success \
592 'creating a tag with -F file of spaces and no newline should succeed' '
d592b315 593 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
ef5a6fb5 594 get_tag_msg blanknonlfile-annotated-tag >actual &&
3af82863 595 test_cmp expect actual
ef5a6fb5
CR
596'
597
598# messages with commented lines:
599
600cat >commentsfile <<EOF
601# A comment
602
603############
604The message.
605############
606One line.
607
608
609# commented lines
610# commented lines
611
612Another line.
613# comments
614
615Last line.
616EOF
617get_tag_header comments-annotated-tag $commit commit $time >expect
618cat >>expect <<EOF
619The message.
620One line.
621
622Another line.
623
624Last line.
625EOF
626test_expect_success \
627 'creating a tag using a -F messagefile with #comments should succeed' '
d592b315 628 git tag -F commentsfile comments-annotated-tag &&
ef5a6fb5 629 get_tag_msg comments-annotated-tag >actual &&
3af82863 630 test_cmp expect actual
ef5a6fb5
CR
631'
632
633get_tag_header comment-annotated-tag $commit commit $time >expect
634test_expect_success \
635 'creating a tag with a #comment in the -m message should succeed' '
d592b315 636 git tag -m "#comment" comment-annotated-tag &&
ef5a6fb5 637 get_tag_msg comment-annotated-tag >actual &&
3af82863 638 test_cmp expect actual
ef5a6fb5
CR
639'
640
641echo '#comment' >commentfile
642echo '' >>commentfile
643echo '####' >>commentfile
644get_tag_header commentfile-annotated-tag $commit commit $time >expect
645test_expect_success \
646 'creating a tag with #comments in the -F messagefile should succeed' '
d592b315 647 git tag -F commentfile commentfile-annotated-tag &&
ef5a6fb5 648 get_tag_msg commentfile-annotated-tag >actual &&
3af82863 649 test_cmp expect actual
ef5a6fb5
CR
650'
651
652printf '#comment' >commentnonlfile
653get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
654test_expect_success \
655 'creating a tag with a file of #comment and no newline should succeed' '
d592b315 656 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
ef5a6fb5 657 get_tag_msg commentnonlfile-annotated-tag >actual &&
3af82863 658 test_cmp expect actual
ef5a6fb5
CR
659'
660
5206d130
CR
661# listing messages for annotated non-signed tags:
662
663test_expect_success \
664 'listing the one-line message of a non-signed tag should succeed' '
d592b315 665 git tag -m "A msg" tag-one-line &&
5206d130
CR
666
667 echo "tag-one-line" >expect &&
d592b315 668 git tag -l | grep "^tag-one-line" >actual &&
3af82863 669 test_cmp expect actual &&
d592b315 670 git tag -n0 -l | grep "^tag-one-line" >actual &&
3af82863 671 test_cmp expect actual &&
d592b315 672 git tag -n0 -l tag-one-line >actual &&
3af82863 673 test_cmp expect actual &&
5206d130 674
6a338149
ÆAB
675 git tag -n0 | grep "^tag-one-line" >actual &&
676 test_cmp expect actual &&
677 git tag -n0 tag-one-line >actual &&
678 test_cmp expect actual &&
679
5206d130 680 echo "tag-one-line A msg" >expect &&
d592b315 681 git tag -n1 -l | grep "^tag-one-line" >actual &&
3af82863 682 test_cmp expect actual &&
d592b315 683 git tag -n -l | grep "^tag-one-line" >actual &&
3af82863 684 test_cmp expect actual &&
d592b315 685 git tag -n1 -l tag-one-line >actual &&
3af82863 686 test_cmp expect actual &&
d592b315 687 git tag -n2 -l tag-one-line >actual &&
3af82863 688 test_cmp expect actual &&
d592b315 689 git tag -n999 -l tag-one-line >actual &&
3af82863 690 test_cmp expect actual
5206d130
CR
691'
692
6a338149 693test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
6a338149 694 git tag -n 100 >actual &&
d3c6751b 695 test_must_be_empty actual &&
6a338149
ÆAB
696
697 git tag -m "A msg" 100 &&
698 echo "100 A msg" >expect &&
699 git tag -n 100 >actual &&
700 test_cmp expect actual
701'
702
5206d130
CR
703test_expect_success \
704 'listing the zero-lines message of a non-signed tag should succeed' '
d592b315 705 git tag -m "" tag-zero-lines &&
5206d130
CR
706
707 echo "tag-zero-lines" >expect &&
d592b315 708 git tag -l | grep "^tag-zero-lines" >actual &&
3af82863 709 test_cmp expect actual &&
d592b315 710 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
3af82863 711 test_cmp expect actual &&
d592b315 712 git tag -n0 -l tag-zero-lines >actual &&
3af82863 713 test_cmp expect actual &&
5206d130
CR
714
715 echo "tag-zero-lines " >expect &&
d592b315 716 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
3af82863 717 test_cmp expect actual &&
d592b315 718 git tag -n -l | grep "^tag-zero-lines" >actual &&
3af82863 719 test_cmp expect actual &&
d592b315 720 git tag -n1 -l tag-zero-lines >actual &&
3af82863 721 test_cmp expect actual &&
d592b315 722 git tag -n2 -l tag-zero-lines >actual &&
3af82863 723 test_cmp expect actual &&
d592b315 724 git tag -n999 -l tag-zero-lines >actual &&
3af82863 725 test_cmp expect actual
5206d130
CR
726'
727
728echo 'tag line one' >annotagmsg
729echo 'tag line two' >>annotagmsg
730echo 'tag line three' >>annotagmsg
731test_expect_success \
732 'listing many message lines of a non-signed tag should succeed' '
d592b315 733 git tag -F annotagmsg tag-lines &&
5206d130
CR
734
735 echo "tag-lines" >expect &&
d592b315 736 git tag -l | grep "^tag-lines" >actual &&
3af82863 737 test_cmp expect actual &&
d592b315 738 git tag -n0 -l | grep "^tag-lines" >actual &&
3af82863 739 test_cmp expect actual &&
d592b315 740 git tag -n0 -l tag-lines >actual &&
3af82863 741 test_cmp expect actual &&
5206d130
CR
742
743 echo "tag-lines tag line one" >expect &&
d592b315 744 git tag -n1 -l | grep "^tag-lines" >actual &&
3af82863 745 test_cmp expect actual &&
d592b315 746 git tag -n -l | grep "^tag-lines" >actual &&
3af82863 747 test_cmp expect actual &&
d592b315 748 git tag -n1 -l tag-lines >actual &&
3af82863 749 test_cmp expect actual &&
5206d130
CR
750
751 echo " tag line two" >>expect &&
d592b315 752 git tag -n2 -l | grep "^ *tag.line" >actual &&
3af82863 753 test_cmp expect actual &&
d592b315 754 git tag -n2 -l tag-lines >actual &&
3af82863 755 test_cmp expect actual &&
5206d130
CR
756
757 echo " tag line three" >>expect &&
d592b315 758 git tag -n3 -l | grep "^ *tag.line" >actual &&
3af82863 759 test_cmp expect actual &&
d592b315 760 git tag -n3 -l tag-lines >actual &&
3af82863 761 test_cmp expect actual &&
d592b315 762 git tag -n4 -l | grep "^ *tag.line" >actual &&
3af82863 763 test_cmp expect actual &&
d592b315 764 git tag -n4 -l tag-lines >actual &&
3af82863 765 test_cmp expect actual &&
d592b315 766 git tag -n99 -l | grep "^ *tag.line" >actual &&
3af82863 767 test_cmp expect actual &&
d592b315 768 git tag -n99 -l tag-lines >actual &&
3af82863 769 test_cmp expect actual
5206d130
CR
770'
771
31fd8d72
JH
772test_expect_success 'annotations for blobs are empty' '
773 blob=$(git hash-object -w --stdin <<-\EOF
774 Blob paragraph 1.
775
776 Blob paragraph 2.
777 EOF
778 ) &&
779 git tag tag-blob $blob &&
780 echo "tag-blob " >expect &&
781 git tag -n1 -l tag-blob >actual &&
782 test_cmp expect actual
783'
784
ef5a6fb5
CR
785# trying to verify annotated non-signed tags:
786
a4df22ce 787test_expect_success GPG \
ef5a6fb5
CR
788 'trying to verify an annotated non-signed tag should fail' '
789 tag_exists annotated-tag &&
d592b315 790 test_must_fail git tag -v annotated-tag
ef5a6fb5
CR
791'
792
a4df22ce 793test_expect_success GPG \
ef5a6fb5
CR
794 'trying to verify a file-annotated non-signed tag should fail' '
795 tag_exists file-annotated-tag &&
d592b315 796 test_must_fail git tag -v file-annotated-tag
ef5a6fb5
CR
797'
798
a4df22ce 799test_expect_success GPG \
62e09ce9
CR
800 'trying to verify two annotated non-signed tags should fail' '
801 tag_exists annotated-tag file-annotated-tag &&
d592b315 802 test_must_fail git tag -v annotated-tag file-annotated-tag
62e09ce9
CR
803'
804
ef5a6fb5
CR
805# creating and verifying signed tags:
806
ef5a6fb5
CR
807get_tag_header signed-tag $commit commit $time >expect
808echo 'A signed tag message' >>expect
809echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 810test_expect_success GPG 'creating a signed tag with -m message should succeed' '
d592b315 811 git tag -s -m "A signed tag message" signed-tag &&
ef5a6fb5 812 get_tag_msg signed-tag >actual &&
3af82863 813 test_cmp expect actual
ef5a6fb5
CR
814'
815
be15f505
LT
816get_tag_header u-signed-tag $commit commit $time >expect
817echo 'Another message' >>expect
818echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 819test_expect_success GPG 'sign with a given key id' '
be15f505
LT
820
821 git tag -u committer@example.com -m "Another message" u-signed-tag &&
822 get_tag_msg u-signed-tag >actual &&
3af82863 823 test_cmp expect actual
be15f505
LT
824
825'
826
a4df22ce 827test_expect_success GPG 'sign with an unknown id (1)' '
be15f505 828
d492b31c
SB
829 test_must_fail git tag -u author@example.com \
830 -m "Another message" o-signed-tag
be15f505
LT
831
832'
833
a4df22ce 834test_expect_success GPG 'sign with an unknown id (2)' '
be15f505 835
d492b31c 836 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
be15f505
LT
837
838'
839
840cat >fakeeditor <<'EOF'
841#!/bin/sh
842test -n "$1" && exec >"$1"
843echo A signed tag message
844echo from a fake editor.
845EOF
846chmod +x fakeeditor
847
848get_tag_header implied-sign $commit commit $time >expect
849./fakeeditor >>expect
850echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 851test_expect_success GPG '-u implies signed tag' '
d592b315 852 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
be15f505 853 get_tag_msg implied-sign >actual &&
3af82863 854 test_cmp expect actual
be15f505
LT
855'
856
62e09ce9
CR
857cat >sigmsgfile <<EOF
858Another signed tag
859message in a file.
860EOF
861get_tag_header file-signed-tag $commit commit $time >expect
862cat sigmsgfile >>expect
863echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 864test_expect_success GPG \
62e09ce9 865 'creating a signed tag with -F messagefile should succeed' '
d592b315 866 git tag -s -F sigmsgfile file-signed-tag &&
62e09ce9 867 get_tag_msg file-signed-tag >actual &&
3af82863 868 test_cmp expect actual
62e09ce9
CR
869'
870
871cat >siginputmsg <<EOF
872A signed tag message from
873the standard input
874EOF
875get_tag_header stdin-signed-tag $commit commit $time >expect
876cat siginputmsg >>expect
877echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 878test_expect_success GPG 'creating a signed tag with -F - should succeed' '
d592b315 879 git tag -s -F - stdin-signed-tag <siginputmsg &&
62e09ce9 880 get_tag_msg stdin-signed-tag >actual &&
3af82863 881 test_cmp expect actual
62e09ce9
CR
882'
883
10507857
JK
884get_tag_header implied-annotate $commit commit $time >expect
885./fakeeditor >>expect
886echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 887test_expect_success GPG '-s implies annotated tag' '
d592b315 888 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
10507857 889 get_tag_msg implied-annotate >actual &&
3af82863 890 test_cmp expect actual
10507857
JK
891'
892
61c2fe0c
LA
893get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
894echo "A message" >>expect
895echo '-----BEGIN PGP SIGNATURE-----' >>expect
896test_expect_success GPG \
897 'git tag -s implied if configured with tag.forcesignannotated' \
898 'test_config tag.forcesignannotated true &&
899 git tag -m "A message" forcesignannotated-implied-sign &&
900 get_tag_msg forcesignannotated-implied-sign >actual &&
901 test_cmp expect actual
902'
903
904test_expect_success GPG \
905 'lightweight with no message when configured with tag.forcesignannotated' \
906 'test_config tag.forcesignannotated true &&
907 git tag forcesignannotated-lightweight &&
908 tag_exists forcesignannotated-lightweight &&
909 test_must_fail git tag -v forcesignannotated-no-message
910'
911
912get_tag_header forcesignannotated-annotate $commit commit $time >expect
913echo "A message" >>expect
914test_expect_success GPG \
915 'git tag -a disable configured tag.forcesignannotated' \
916 'test_config tag.forcesignannotated true &&
917 git tag -a -m "A message" forcesignannotated-annotate &&
918 get_tag_msg forcesignannotated-annotate >actual &&
919 test_cmp expect actual &&
920 test_must_fail git tag -v forcesignannotated-annotate
921'
922
923get_tag_header forcesignannotated-disabled $commit commit $time >expect
924echo "A message" >>expect
925echo '-----BEGIN PGP SIGNATURE-----' >>expect
926test_expect_success GPG \
927 'git tag --sign enable GPG sign' \
928 'test_config tag.forcesignannotated false &&
929 git tag --sign -m "A message" forcesignannotated-disabled &&
930 get_tag_msg forcesignannotated-disabled >actual &&
931 test_cmp expect actual
932'
933
1c6b565f
TM
934get_tag_header gpgsign-enabled $commit commit $time >expect
935echo "A message" >>expect
936echo '-----BEGIN PGP SIGNATURE-----' >>expect
937test_expect_success GPG \
938 'git tag configured tag.gpgsign enables GPG sign' \
939 'test_config tag.gpgsign true &&
940 git tag -m "A message" gpgsign-enabled &&
941 get_tag_msg gpgsign-enabled>actual &&
942 test_cmp expect actual
943'
944
945get_tag_header no-sign $commit commit $time >expect
946echo "A message" >>expect
947test_expect_success GPG \
948 'git tag --no-sign configured tag.gpgsign skip GPG sign' \
949 'test_config tag.gpgsign true &&
950 git tag -a --no-sign -m "A message" no-sign &&
951 get_tag_msg no-sign>actual &&
952 test_cmp expect actual
953'
954
a4df22ce 955test_expect_success GPG \
e317cfaf
CR
956 'trying to create a signed tag with non-existing -F file should fail' '
957 ! test -f nonexistingfile &&
958 ! tag_exists nosigtag &&
d592b315 959 test_must_fail git tag -s -F nonexistingfile nosigtag &&
e317cfaf
CR
960 ! tag_exists nosigtag
961'
962
a4df22ce 963test_expect_success GPG 'verifying a signed tag should succeed' \
d592b315 964 'git tag -v signed-tag'
ef5a6fb5 965
a4df22ce 966test_expect_success GPG 'verifying two signed tags in one command should succeed' \
d592b315 967 'git tag -v signed-tag file-signed-tag'
62e09ce9 968
a4df22ce 969test_expect_success GPG \
62e09ce9 970 'verifying many signed and non-signed tags should fail' '
d592b315
NS
971 test_must_fail git tag -v signed-tag annotated-tag &&
972 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
973 test_must_fail git tag -v annotated-tag \
d492b31c 974 file-signed-tag file-annotated-tag &&
d592b315 975 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
62e09ce9
CR
976'
977
a4df22ce 978test_expect_success GPG 'verifying a forged tag should fail' '
ef5a6fb5
CR
979 forged=$(git cat-file tag signed-tag |
980 sed -e "s/signed-tag/forged-tag/" |
981 git mktag) &&
982 git tag forged-tag $forged &&
d592b315 983 test_must_fail git tag -v forged-tag
ef5a6fb5
CR
984'
985
b42ca35e
ST
986test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
987 cat >expect <<-\EOF &&
4fea72f4 988 tagname : signed-tag
b42ca35e 989 EOF
4fea72f4
ST
990 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
991 test_cmp expect actual
992'
993
b42ca35e 994test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
4fea72f4 995 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
d3c6751b 996 test_must_be_empty actual
4fea72f4
ST
997'
998
ef5a6fb5
CR
999# blank and empty messages for signed tags:
1000
1001get_tag_header empty-signed-tag $commit commit $time >expect
1002echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1003test_expect_success GPG \
ef5a6fb5 1004 'creating a signed tag with an empty -m message should succeed' '
d592b315 1005 git tag -s -m "" empty-signed-tag &&
ef5a6fb5 1006 get_tag_msg empty-signed-tag >actual &&
3af82863 1007 test_cmp expect actual &&
d592b315 1008 git tag -v empty-signed-tag
ef5a6fb5
CR
1009'
1010
1011>sigemptyfile
1012get_tag_header emptyfile-signed-tag $commit commit $time >expect
1013echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1014test_expect_success GPG \
ef5a6fb5 1015 'creating a signed tag with an empty -F messagefile should succeed' '
d592b315 1016 git tag -s -F sigemptyfile emptyfile-signed-tag &&
ef5a6fb5 1017 get_tag_msg emptyfile-signed-tag >actual &&
3af82863 1018 test_cmp expect actual &&
d592b315 1019 git tag -v emptyfile-signed-tag
ef5a6fb5
CR
1020'
1021
1022printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
1023printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
1024printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
1025printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1026get_tag_header blanks-signed-tag $commit commit $time >expect
1027cat >>expect <<EOF
1028Leading blank lines
1029
1030Repeated blank lines
1031
1032Trailing spaces
1033
1034Trailing blank lines
1035EOF
1036echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1037test_expect_success GPG \
ef5a6fb5 1038 'extra blanks in the message for a signed tag should be removed' '
d592b315 1039 git tag -s -F sigblanksfile blanks-signed-tag &&
ef5a6fb5 1040 get_tag_msg blanks-signed-tag >actual &&
3af82863 1041 test_cmp expect actual &&
d592b315 1042 git tag -v blanks-signed-tag
ef5a6fb5
CR
1043'
1044
1045get_tag_header blank-signed-tag $commit commit $time >expect
1046echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1047test_expect_success GPG \
ef5a6fb5 1048 'creating a signed tag with a blank -m message should succeed' '
d592b315 1049 git tag -s -m " " blank-signed-tag &&
ef5a6fb5 1050 get_tag_msg blank-signed-tag >actual &&
3af82863 1051 test_cmp expect actual &&
d592b315 1052 git tag -v blank-signed-tag
ef5a6fb5
CR
1053'
1054
1055echo ' ' >sigblankfile
1056echo '' >>sigblankfile
1057echo ' ' >>sigblankfile
1058get_tag_header blankfile-signed-tag $commit commit $time >expect
1059echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1060test_expect_success GPG \
ef5a6fb5 1061 'creating a signed tag with blank -F file with spaces should succeed' '
d592b315 1062 git tag -s -F sigblankfile blankfile-signed-tag &&
ef5a6fb5 1063 get_tag_msg blankfile-signed-tag >actual &&
3af82863 1064 test_cmp expect actual &&
d592b315 1065 git tag -v blankfile-signed-tag
ef5a6fb5
CR
1066'
1067
1068printf ' ' >sigblanknonlfile
1069get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1070echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1071test_expect_success GPG \
ef5a6fb5 1072 'creating a signed tag with spaces and no newline should succeed' '
d592b315 1073 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
ef5a6fb5 1074 get_tag_msg blanknonlfile-signed-tag >actual &&
3af82863 1075 test_cmp expect actual &&
cf98a52b 1076 git tag -v blanknonlfile-signed-tag
ef5a6fb5
CR
1077'
1078
8b44b2be
JK
1079test_expect_success GPG 'signed tag with embedded PGP message' '
1080 cat >msg <<-\EOF &&
1081 -----BEGIN PGP MESSAGE-----
1082
1083 this is not a real PGP message
1084 -----END PGP MESSAGE-----
1085 EOF
1086 git tag -s -F msg confusing-pgp-message &&
1087 git tag -v confusing-pgp-message
1088'
1089
ef5a6fb5
CR
1090# messages with commented lines for signed tags:
1091
1092cat >sigcommentsfile <<EOF
1093# A comment
1094
1095############
1096The message.
1097############
1098One line.
1099
1100
1101# commented lines
1102# commented lines
1103
1104Another line.
1105# comments
1106
1107Last line.
1108EOF
1109get_tag_header comments-signed-tag $commit commit $time >expect
1110cat >>expect <<EOF
1111The message.
1112One line.
1113
1114Another line.
1115
1116Last line.
1117EOF
1118echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1119test_expect_success GPG \
ef5a6fb5 1120 'creating a signed tag with a -F file with #comments should succeed' '
d592b315 1121 git tag -s -F sigcommentsfile comments-signed-tag &&
ef5a6fb5 1122 get_tag_msg comments-signed-tag >actual &&
3af82863 1123 test_cmp expect actual &&
d592b315 1124 git tag -v comments-signed-tag
ef5a6fb5
CR
1125'
1126
1127get_tag_header comment-signed-tag $commit commit $time >expect
1128echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1129test_expect_success GPG \
ef5a6fb5 1130 'creating a signed tag with #commented -m message should succeed' '
d592b315 1131 git tag -s -m "#comment" comment-signed-tag &&
ef5a6fb5 1132 get_tag_msg comment-signed-tag >actual &&
3af82863 1133 test_cmp expect actual &&
d592b315 1134 git tag -v comment-signed-tag
ef5a6fb5
CR
1135'
1136
1137echo '#comment' >sigcommentfile
1138echo '' >>sigcommentfile
1139echo '####' >>sigcommentfile
1140get_tag_header commentfile-signed-tag $commit commit $time >expect
1141echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1142test_expect_success GPG \
ef5a6fb5 1143 'creating a signed tag with #commented -F messagefile should succeed' '
d592b315 1144 git tag -s -F sigcommentfile commentfile-signed-tag &&
ef5a6fb5 1145 get_tag_msg commentfile-signed-tag >actual &&
3af82863 1146 test_cmp expect actual &&
d592b315 1147 git tag -v commentfile-signed-tag
ef5a6fb5
CR
1148'
1149
1150printf '#comment' >sigcommentnonlfile
1151get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1152echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1153test_expect_success GPG \
ef5a6fb5 1154 'creating a signed tag with a #comment and no newline should succeed' '
d592b315 1155 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
ef5a6fb5 1156 get_tag_msg commentnonlfile-signed-tag >actual &&
3af82863 1157 test_cmp expect actual &&
d592b315 1158 git tag -v commentnonlfile-signed-tag
ef5a6fb5
CR
1159'
1160
5206d130
CR
1161# listing messages for signed tags:
1162
a4df22ce 1163test_expect_success GPG \
5206d130 1164 'listing the one-line message of a signed tag should succeed' '
d592b315 1165 git tag -s -m "A message line signed" stag-one-line &&
5206d130
CR
1166
1167 echo "stag-one-line" >expect &&
d592b315 1168 git tag -l | grep "^stag-one-line" >actual &&
3af82863 1169 test_cmp expect actual &&
d592b315 1170 git tag -n0 -l | grep "^stag-one-line" >actual &&
3af82863 1171 test_cmp expect actual &&
d592b315 1172 git tag -n0 -l stag-one-line >actual &&
3af82863 1173 test_cmp expect actual &&
5206d130
CR
1174
1175 echo "stag-one-line A message line signed" >expect &&
d592b315 1176 git tag -n1 -l | grep "^stag-one-line" >actual &&
3af82863 1177 test_cmp expect actual &&
d592b315 1178 git tag -n -l | grep "^stag-one-line" >actual &&
3af82863 1179 test_cmp expect actual &&
d592b315 1180 git tag -n1 -l stag-one-line >actual &&
3af82863 1181 test_cmp expect actual &&
d592b315 1182 git tag -n2 -l stag-one-line >actual &&
3af82863 1183 test_cmp expect actual &&
d592b315 1184 git tag -n999 -l stag-one-line >actual &&
3af82863 1185 test_cmp expect actual
5206d130
CR
1186'
1187
a4df22ce 1188test_expect_success GPG \
5206d130 1189 'listing the zero-lines message of a signed tag should succeed' '
d592b315 1190 git tag -s -m "" stag-zero-lines &&
5206d130
CR
1191
1192 echo "stag-zero-lines" >expect &&
d592b315 1193 git tag -l | grep "^stag-zero-lines" >actual &&
3af82863 1194 test_cmp expect actual &&
d592b315 1195 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
3af82863 1196 test_cmp expect actual &&
d592b315 1197 git tag -n0 -l stag-zero-lines >actual &&
3af82863 1198 test_cmp expect actual &&
5206d130
CR
1199
1200 echo "stag-zero-lines " >expect &&
d592b315 1201 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
3af82863 1202 test_cmp expect actual &&
d592b315 1203 git tag -n -l | grep "^stag-zero-lines" >actual &&
3af82863 1204 test_cmp expect actual &&
d592b315 1205 git tag -n1 -l stag-zero-lines >actual &&
3af82863 1206 test_cmp expect actual &&
d592b315 1207 git tag -n2 -l stag-zero-lines >actual &&
3af82863 1208 test_cmp expect actual &&
d592b315 1209 git tag -n999 -l stag-zero-lines >actual &&
3af82863 1210 test_cmp expect actual
5206d130
CR
1211'
1212
1213echo 'stag line one' >sigtagmsg
1214echo 'stag line two' >>sigtagmsg
1215echo 'stag line three' >>sigtagmsg
a4df22ce 1216test_expect_success GPG \
5206d130 1217 'listing many message lines of a signed tag should succeed' '
d592b315 1218 git tag -s -F sigtagmsg stag-lines &&
5206d130
CR
1219
1220 echo "stag-lines" >expect &&
d592b315 1221 git tag -l | grep "^stag-lines" >actual &&
3af82863 1222 test_cmp expect actual &&
d592b315 1223 git tag -n0 -l | grep "^stag-lines" >actual &&
3af82863 1224 test_cmp expect actual &&
d592b315 1225 git tag -n0 -l stag-lines >actual &&
3af82863 1226 test_cmp expect actual &&
5206d130
CR
1227
1228 echo "stag-lines stag line one" >expect &&
d592b315 1229 git tag -n1 -l | grep "^stag-lines" >actual &&
3af82863 1230 test_cmp expect actual &&
d592b315 1231 git tag -n -l | grep "^stag-lines" >actual &&
3af82863 1232 test_cmp expect actual &&
d592b315 1233 git tag -n1 -l stag-lines >actual &&
3af82863 1234 test_cmp expect actual &&
5206d130
CR
1235
1236 echo " stag line two" >>expect &&
d592b315 1237 git tag -n2 -l | grep "^ *stag.line" >actual &&
3af82863 1238 test_cmp expect actual &&
d592b315 1239 git tag -n2 -l stag-lines >actual &&
3af82863 1240 test_cmp expect actual &&
5206d130
CR
1241
1242 echo " stag line three" >>expect &&
d592b315 1243 git tag -n3 -l | grep "^ *stag.line" >actual &&
3af82863 1244 test_cmp expect actual &&
d592b315 1245 git tag -n3 -l stag-lines >actual &&
3af82863 1246 test_cmp expect actual &&
d592b315 1247 git tag -n4 -l | grep "^ *stag.line" >actual &&
3af82863 1248 test_cmp expect actual &&
d592b315 1249 git tag -n4 -l stag-lines >actual &&
3af82863 1250 test_cmp expect actual &&
d592b315 1251 git tag -n99 -l | grep "^ *stag.line" >actual &&
3af82863 1252 test_cmp expect actual &&
d592b315 1253 git tag -n99 -l stag-lines >actual &&
3af82863 1254 test_cmp expect actual
5206d130
CR
1255'
1256
ef5a6fb5
CR
1257# tags pointing to objects different from commits:
1258
1259tree=$(git rev-parse HEAD^{tree})
1260blob=$(git rev-parse HEAD:foo)
a4df22ce 1261tag=$(git rev-parse signed-tag 2>/dev/null)
ef5a6fb5
CR
1262
1263get_tag_header tree-signed-tag $tree tree $time >expect
1264echo "A message for a tree" >>expect
1265echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1266test_expect_success GPG \
ef5a6fb5 1267 'creating a signed tag pointing to a tree should succeed' '
d592b315 1268 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
ef5a6fb5 1269 get_tag_msg tree-signed-tag >actual &&
3af82863 1270 test_cmp expect actual
ef5a6fb5
CR
1271'
1272
1273get_tag_header blob-signed-tag $blob blob $time >expect
1274echo "A message for a blob" >>expect
1275echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1276test_expect_success GPG \
ef5a6fb5 1277 'creating a signed tag pointing to a blob should succeed' '
d592b315 1278 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
ef5a6fb5 1279 get_tag_msg blob-signed-tag >actual &&
3af82863 1280 test_cmp expect actual
ef5a6fb5
CR
1281'
1282
1283get_tag_header tag-signed-tag $tag tag $time >expect
1284echo "A message for another tag" >>expect
1285echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1286test_expect_success GPG \
ef5a6fb5 1287 'creating a signed tag pointing to another tag should succeed' '
d592b315 1288 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
ef5a6fb5 1289 get_tag_msg tag-signed-tag >actual &&
3af82863 1290 test_cmp expect actual
ef5a6fb5
CR
1291'
1292
c8525c30 1293# usage with rfc1991 signatures
c8525c30
MG
1294get_tag_header rfc1991-signed-tag $commit commit $time >expect
1295echo "RFC1991 signed tag" >>expect
1296echo '-----BEGIN PGP MESSAGE-----' >>expect
c0e0ed6e 1297test_expect_success GPG,RFC1991 \
c8525c30 1298 'creating a signed tag with rfc1991' '
086cb911 1299 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1300 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1301 get_tag_msg rfc1991-signed-tag >actual &&
1302 test_cmp expect actual
1303'
1304
1305cat >fakeeditor <<'EOF'
1306#!/bin/sh
1307cp "$1" actual
1308EOF
1309chmod +x fakeeditor
1310
c0e0ed6e 1311test_expect_success GPG,RFC1991 \
c8525c30 1312 'reediting a signed tag body omits signature' '
086cb911 1313 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1314 echo "RFC1991 signed tag" >expect &&
1315 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1316 test_cmp expect actual
1317'
1318
c0e0ed6e 1319test_expect_success GPG,RFC1991 \
c8525c30 1320 'verifying rfc1991 signature' '
086cb911 1321 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1322 git tag -v rfc1991-signed-tag
1323'
1324
c0e0ed6e 1325test_expect_success GPG,RFC1991 \
c8525c30 1326 'list tag with rfc1991 signature' '
086cb911 1327 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1328 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1329 git tag -l -n1 rfc1991-signed-tag >actual &&
1330 test_cmp expect actual &&
1331 git tag -l -n2 rfc1991-signed-tag >actual &&
1332 test_cmp expect actual &&
1333 git tag -l -n999 rfc1991-signed-tag >actual &&
1334 test_cmp expect actual
1335'
1336
1337rm -f gpghome/gpg.conf
1338
c0e0ed6e 1339test_expect_success GPG,RFC1991 \
c8525c30
MG
1340 'verifying rfc1991 signature without --rfc1991' '
1341 git tag -v rfc1991-signed-tag
1342'
1343
c0e0ed6e 1344test_expect_success GPG,RFC1991 \
c8525c30
MG
1345 'list tag with rfc1991 signature without --rfc1991' '
1346 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1347 git tag -l -n1 rfc1991-signed-tag >actual &&
1348 test_cmp expect actual &&
1349 git tag -l -n2 rfc1991-signed-tag >actual &&
1350 test_cmp expect actual &&
1351 git tag -l -n999 rfc1991-signed-tag >actual &&
1352 test_cmp expect actual
1353'
1354
c0e0ed6e 1355test_expect_success GPG,RFC1991 \
c8525c30
MG
1356 'reediting a signed tag body omits signature' '
1357 echo "RFC1991 signed tag" >expect &&
1358 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1359 test_cmp expect actual
1360'
1361
aba91192 1362# try to sign with bad user.signingkey
a4df22ce 1363test_expect_success GPG \
efee9553 1364 'git tag -s fails if gpg is misconfigured (bad key)' \
9ffda48f
SG
1365 'test_config user.signingkey BobTheMouse &&
1366 test_must_fail git tag -s -m tail tag-gpg-failure'
aba91192 1367
efee9553
MG
1368# try to produce invalid signature
1369test_expect_success GPG \
1370 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1371 'test_config gpg.program echo &&
1372 test_must_fail git tag -s -m tail tag-gpg-failure'
1373
53fc9993
HS
1374# try to sign with bad user.signingkey
1375test_expect_success GPGSM \
1376 'git tag -s fails if gpgsm is misconfigured (bad key)' \
1377 'test_config user.signingkey BobTheMouse &&
1378 test_config gpg.format x509 &&
1379 test_must_fail git tag -s -m tail tag-gpg-failure'
1380
1381# try to produce invalid signature
1382test_expect_success GPGSM \
1383 'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1384 'test_config gpg.x509.program echo &&
1385 test_config gpg.format x509 &&
1386 test_must_fail git tag -s -m tail tag-gpg-failure'
efee9553 1387
ef5a6fb5
CR
1388# try to verify without gpg:
1389
1390rm -rf gpghome
a4df22ce 1391test_expect_success GPG \
ef5a6fb5 1392 'verify signed tag fails when public key is not present' \
d592b315 1393 'test_must_fail git tag -v signed-tag'
ef5a6fb5 1394
41ac414e 1395test_expect_success \
d592b315 1396 'git tag -a fails if tag annotation is empty' '
41ac414e 1397 ! (GIT_EDITOR=cat git tag -a initial-comment)
eb9d2b91
MH
1398'
1399
4d8b1dc8
MH
1400test_expect_success \
1401 'message in editor has initial comment' '
5649bd9a
ÆAB
1402 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1403'
1404
b3e1900a 1405test_expect_success 'message in editor has initial comment: first line' '
eb9d2b91 1406 # check the first line --- should be empty
5649bd9a
ÆAB
1407 echo >first.expect &&
1408 sed -e 1q <actual >first.actual &&
b3e1900a 1409 test_i18ncmp first.expect first.actual
5649bd9a
ÆAB
1410'
1411
1412test_expect_success \
1413 'message in editor has initial comment: remainder' '
eb9d2b91 1414 # remove commented lines from the remainder -- should be empty
11f228b0 1415 sed -e 1d -e "/^#/d" <actual >rest.actual &&
d3c6751b 1416 test_must_be_empty rest.actual
4d8b1dc8
MH
1417'
1418
1419get_tag_header reuse $commit commit $time >expect
1420echo "An annotation to be reused" >> expect
1421test_expect_success \
4dc8b1c1 1422 'overwriting an annotated tag should use its previous body' '
4d8b1dc8
MH
1423 git tag -a -m "An annotation to be reused" reuse &&
1424 GIT_EDITOR=true git tag -f -a reuse &&
1425 get_tag_msg reuse >actual &&
3af82863 1426 test_cmp expect actual
4d8b1dc8
MH
1427'
1428
dbd0f5c7
JH
1429test_expect_success 'filename for the message is relative to cwd' '
1430 mkdir subdir &&
1431 echo "Tag message in top directory" >msgfile-5 &&
1432 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1433 (
1434 cd subdir &&
1435 git tag -a -F msgfile-5 tag-from-subdir
1436 ) &&
1437 git cat-file tag tag-from-subdir | grep "in sub directory"
1438'
1439
1440test_expect_success 'filename for the message is relative to cwd' '
1441 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1442 (
1443 cd subdir &&
1444 git tag -a -F msgfile-6 tag-from-subdir-2
1445 ) &&
1446 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1447'
1448
32c35cfb
JG
1449# create a few more commits to test --contains
1450
1451hash1=$(git rev-parse HEAD)
1452
1453test_expect_success 'creating second commit and tag' '
1454 echo foo-2.0 >foo &&
1455 git add foo &&
2dec68cf 1456 git commit -m second &&
32c35cfb
JG
1457 git tag v2.0
1458'
1459
1460hash2=$(git rev-parse HEAD)
1461
1462test_expect_success 'creating third commit without tag' '
1463 echo foo-dev >foo &&
1464 git add foo &&
1465 git commit -m third
1466'
1467
1468hash3=$(git rev-parse HEAD)
1469
1470# simple linear checks of --continue
1471
1472cat > expected <<EOF
1473v0.2.1
1474v1.0
1475v1.0.1
1476v1.1.3
1477v2.0
1478EOF
1479
1480test_expect_success 'checking that first commit is in all tags (hash)' "
2dec68cf 1481 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1482 test_cmp expected actual
1483"
1484
1485# other ways of specifying the commit
1486test_expect_success 'checking that first commit is in all tags (tag)' "
2dec68cf 1487 git tag -l --contains v1.0 v* >actual &&
32c35cfb
JG
1488 test_cmp expected actual
1489"
1490
1491test_expect_success 'checking that first commit is in all tags (relative)' "
2dec68cf 1492 git tag -l --contains HEAD~2 v* >actual &&
32c35cfb
JG
1493 test_cmp expected actual
1494"
1495
ac3f5a34
ÆAB
1496# All the --contains tests above, but with --no-contains
1497test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
ac3f5a34 1498 git tag -l --no-contains $hash1 v* >actual &&
d3c6751b 1499 test_must_be_empty actual
ac3f5a34
ÆAB
1500"
1501
1502test_expect_success 'checking that first commit is in all tags (tag)' "
1503 git tag -l --no-contains v1.0 v* >actual &&
d3c6751b 1504 test_must_be_empty actual
ac3f5a34
ÆAB
1505"
1506
1507test_expect_success 'checking that first commit is in all tags (relative)' "
1508 git tag -l --no-contains HEAD~2 v* >actual &&
d3c6751b 1509 test_must_be_empty actual
ac3f5a34
ÆAB
1510"
1511
32c35cfb
JG
1512cat > expected <<EOF
1513v2.0
1514EOF
1515
1516test_expect_success 'checking that second commit only has one tag' "
2dec68cf 1517 git tag -l --contains $hash2 v* >actual &&
32c35cfb
JG
1518 test_cmp expected actual
1519"
1520
ac3f5a34
ÆAB
1521cat > expected <<EOF
1522v0.2.1
1523v1.0
1524v1.0.1
1525v1.1.3
1526EOF
1527
1528test_expect_success 'inverse of the last test, with --no-contains' "
1529 git tag -l --no-contains $hash2 v* >actual &&
1530 test_cmp expected actual
1531"
32c35cfb 1532
32c35cfb 1533test_expect_success 'checking that third commit has no tags' "
2dec68cf 1534 git tag -l --contains $hash3 v* >actual &&
1c5e94f4 1535 test_must_be_empty actual
32c35cfb
JG
1536"
1537
ac3f5a34
ÆAB
1538cat > expected <<EOF
1539v0.2.1
1540v1.0
1541v1.0.1
1542v1.1.3
1543v2.0
1544EOF
1545
1546test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1547 git tag -l --no-contains $hash3 v* >actual &&
1548 test_cmp expected actual
1549"
1550
32c35cfb
JG
1551# how about a simple merge?
1552
1553test_expect_success 'creating simple branch' '
1554 git branch stable v2.0 &&
1555 git checkout stable &&
1556 echo foo-3.0 > foo &&
2dec68cf 1557 git commit foo -m fourth &&
32c35cfb
JG
1558 git tag v3.0
1559'
1560
1561hash4=$(git rev-parse HEAD)
1562
1563cat > expected <<EOF
1564v3.0
1565EOF
1566
1567test_expect_success 'checking that branch head only has one tag' "
2dec68cf 1568 git tag -l --contains $hash4 v* >actual &&
32c35cfb
JG
1569 test_cmp expected actual
1570"
1571
ac3f5a34
ÆAB
1572cat > expected <<EOF
1573v0.2.1
1574v1.0
1575v1.0.1
1576v1.1.3
1577v2.0
1578EOF
1579
1580test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1581 git tag -l --no-contains $hash4 v* >actual &&
1582 test_cmp expected actual
1583"
1584
32c35cfb
JG
1585test_expect_success 'merging original branch into this branch' '
1586 git merge --strategy=ours master &&
1587 git tag v4.0
1588'
1589
1590cat > expected <<EOF
1591v4.0
1592EOF
1593
1594test_expect_success 'checking that original branch head has one tag now' "
2dec68cf 1595 git tag -l --contains $hash3 v* >actual &&
32c35cfb
JG
1596 test_cmp expected actual
1597"
1598
ac3f5a34
ÆAB
1599cat > expected <<EOF
1600v0.2.1
1601v1.0
1602v1.0.1
1603v1.1.3
1604v2.0
1605v3.0
1606EOF
1607
1608test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1609 git tag -l --no-contains $hash3 v* >actual &&
1610 test_cmp expected actual
1611"
1612
32c35cfb
JG
1613cat > expected <<EOF
1614v0.2.1
1615v1.0
1616v1.0.1
1617v1.1.3
1618v2.0
1619v3.0
1620v4.0
1621EOF
1622
1623test_expect_success 'checking that initial commit is in all tags' "
2dec68cf 1624 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1625 test_cmp expected actual
1626"
1627
6a338149
ÆAB
1628test_expect_success 'checking that --contains can be used in non-list mode' '
1629 git tag --contains $hash1 v* >actual &&
1630 test_cmp expected actual
1631'
1632
ac3f5a34 1633test_expect_success 'checking that initial commit is in all tags with --no-contains' "
ac3f5a34 1634 git tag -l --no-contains $hash1 v* >actual &&
d3c6751b 1635 test_must_be_empty actual
ac3f5a34
ÆAB
1636"
1637
e0e03a73
ST
1638# mixing modes and options:
1639
1640test_expect_success 'mixing incompatibles modes and options is forbidden' '
2dec68cf 1641 test_must_fail git tag -a &&
bf748049
ÆAB
1642 test_must_fail git tag -a -l &&
1643 test_must_fail git tag -s &&
1644 test_must_fail git tag -s -l &&
1645 test_must_fail git tag -m &&
1646 test_must_fail git tag -m -l &&
1647 test_must_fail git tag -m "hlagh" &&
1648 test_must_fail git tag -m "hlagh" -l &&
1649 test_must_fail git tag -F &&
1650 test_must_fail git tag -F -l &&
1651 test_must_fail git tag -f &&
1652 test_must_fail git tag -f -l &&
1653 test_must_fail git tag -a -s -m -F &&
1654 test_must_fail git tag -a -s -m -F -l &&
2dec68cf 1655 test_must_fail git tag -l -v &&
bf748049
ÆAB
1656 test_must_fail git tag -l -d &&
1657 test_must_fail git tag -l -v -d &&
bf748049 1658 test_must_fail git tag -n 100 -v &&
2dec68cf
JN
1659 test_must_fail git tag -l -m msg &&
1660 test_must_fail git tag -l -F some file &&
b643827b
ÆAB
1661 test_must_fail git tag -v -s &&
1662 test_must_fail git tag --contains tag-tree &&
ac3f5a34
ÆAB
1663 test_must_fail git tag --contains tag-blob &&
1664 test_must_fail git tag --no-contains tag-tree &&
1665 test_must_fail git tag --no-contains tag-blob &&
75057691
ÆAB
1666 test_must_fail git tag --contains --no-contains &&
1667 test_must_fail git tag --no-with HEAD &&
1668 test_must_fail git tag --no-without HEAD
e0e03a73
ST
1669'
1670
75057691 1671for option in --contains --with --no-contains --without --merged --no-merged --points-at
6a338149
ÆAB
1672do
1673 test_expect_success "mixing incompatible modes with $option is forbidden" "
1674 test_must_fail git tag -d $option HEAD &&
1675 test_must_fail git tag -d $option HEAD some-tag &&
1676 test_must_fail git tag -v $option HEAD
1677 "
1678 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1679 git tag -n $option HEAD HEAD &&
1e0c3b68
ÆAB
1680 git tag $option HEAD HEAD &&
1681 git tag $option
6a338149
ÆAB
1682 "
1683done
e0e03a73 1684
ae7706b9
TG
1685# check points-at
1686
6a338149
ÆAB
1687test_expect_success '--points-at can be used in non-list mode' '
1688 echo v4.0 >expect &&
1689 git tag --points-at=v4.0 "v*" >actual &&
1690 test_cmp expect actual
ae7706b9
TG
1691'
1692
1e0c3b68
ÆAB
1693test_expect_success '--points-at is a synonym for --points-at HEAD' '
1694 echo v4.0 >expect &&
1695 git tag --points-at >actual &&
1696 test_cmp expect actual
ae7706b9
TG
1697'
1698
1699test_expect_success '--points-at finds lightweight tags' '
1700 echo v4.0 >expect &&
1701 git tag --points-at v4.0 >actual &&
1702 test_cmp expect actual
1703'
1704
1705test_expect_success '--points-at finds annotated tags of commits' '
1706 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1707 echo annotated-v4.0 >expect &&
1708 git tag -l --points-at v4.0 "annotated*" >actual &&
1709 test_cmp expect actual
1710'
1711
1712test_expect_success '--points-at finds annotated tags of tags' '
1713 git tag -m "describing the v4.0 tag object" \
1714 annotated-again-v4.0 annotated-v4.0 &&
1715 cat >expect <<-\EOF &&
1716 annotated-again-v4.0
1717 annotated-v4.0
1718 EOF
1719 git tag --points-at=annotated-v4.0 >actual &&
1720 test_cmp expect actual
1721'
1722
eea9c1e7
DL
1723test_expect_success 'recursive tagging should give advice' '
1724 sed -e "s/|$//" <<-EOF >expect &&
a54b2ab3 1725 hint: You have created a nested tag. The object referred to by your new tag is
eea9c1e7
DL
1726 hint: already a tag. If you meant to tag the object that it points to, use:
1727 hint: |
1728 hint: git tag -f nested annotated-v4.0^{}
f665d63a 1729 hint: Disable this message with "git config advice.nestedTag false"
eea9c1e7
DL
1730 EOF
1731 git tag -m nested nested annotated-v4.0 2>actual &&
1732 test_i18ncmp expect actual
1733'
1734
ae7706b9
TG
1735test_expect_success 'multiple --points-at are OR-ed together' '
1736 cat >expect <<-\EOF &&
1737 v2.0
1738 v3.0
1739 EOF
1740 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1741 test_cmp expect actual
1742'
1743
9ef176b5
NTND
1744test_expect_success 'lexical sort' '
1745 git tag foo1.3 &&
1746 git tag foo1.6 &&
1747 git tag foo1.10 &&
1748 git tag -l --sort=refname "foo*" >actual &&
dc662d44
JK
1749 cat >expect <<-\EOF &&
1750 foo1.10
1751 foo1.3
1752 foo1.6
1753 EOF
9ef176b5
NTND
1754 test_cmp expect actual
1755'
1756
1757test_expect_success 'version sort' '
1758 git tag -l --sort=version:refname "foo*" >actual &&
dc662d44
JK
1759 cat >expect <<-\EOF &&
1760 foo1.3
1761 foo1.6
1762 foo1.10
1763 EOF
9ef176b5
NTND
1764 test_cmp expect actual
1765'
1766
1767test_expect_success 'reverse version sort' '
1768 git tag -l --sort=-version:refname "foo*" >actual &&
dc662d44
JK
1769 cat >expect <<-\EOF &&
1770 foo1.10
1771 foo1.6
1772 foo1.3
1773 EOF
9ef176b5
NTND
1774 test_cmp expect actual
1775'
1776
1777test_expect_success 'reverse lexical sort' '
1778 git tag -l --sort=-refname "foo*" >actual &&
dc662d44
JK
1779 cat >expect <<-\EOF &&
1780 foo1.6
1781 foo1.3
1782 foo1.10
1783 EOF
9ef176b5
NTND
1784 test_cmp expect actual
1785'
1786
b150794d 1787test_expect_success 'configured lexical sort' '
9ffda48f 1788 test_config tag.sort "v:refname" &&
b150794d
JK
1789 git tag -l "foo*" >actual &&
1790 cat >expect <<-\EOF &&
1791 foo1.3
1792 foo1.6
1793 foo1.10
1794 EOF
1795 test_cmp expect actual
1796'
1797
1798test_expect_success 'option override configured sort' '
9ffda48f 1799 test_config tag.sort "v:refname" &&
b150794d
JK
1800 git tag -l --sort=-refname "foo*" >actual &&
1801 cat >expect <<-\EOF &&
1802 foo1.6
1803 foo1.3
1804 foo1.10
1805 EOF
1806 test_cmp expect actual
1807'
1808
1809test_expect_success 'invalid sort parameter on command line' '
1810 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1811'
1812
1813test_expect_success 'invalid sort parameter in configuratoin' '
9ffda48f 1814 test_config tag.sort "v:notvalid" &&
b7cc53e9 1815 test_must_fail git tag -l "foo*"
b150794d
JK
1816'
1817
d811c8e1 1818test_expect_success 'version sort with prerelease reordering' '
9ffda48f 1819 test_config versionsort.prereleaseSuffix -rc &&
d811c8e1
NTND
1820 git tag foo1.6-rc1 &&
1821 git tag foo1.6-rc2 &&
1822 git tag -l --sort=version:refname "foo*" >actual &&
1823 cat >expect <<-\EOF &&
1824 foo1.3
1825 foo1.6-rc1
1826 foo1.6-rc2
1827 foo1.6
1828 foo1.10
1829 EOF
1830 test_cmp expect actual
1831'
1832
1833test_expect_success 'reverse version sort with prerelease reordering' '
9ffda48f 1834 test_config versionsort.prereleaseSuffix -rc &&
d811c8e1
NTND
1835 git tag -l --sort=-version:refname "foo*" >actual &&
1836 cat >expect <<-\EOF &&
1837 foo1.10
1838 foo1.6
1839 foo1.6-rc2
1840 foo1.6-rc1
1841 foo1.3
1842 EOF
1843 test_cmp expect actual
1844'
1845
b8231660 1846test_expect_success 'version sort with prerelease reordering and common leading character' '
0c1b4878
SG
1847 test_config versionsort.prereleaseSuffix -before &&
1848 git tag foo1.7-before1 &&
1849 git tag foo1.7 &&
1850 git tag foo1.7-after1 &&
1851 git tag -l --sort=version:refname "foo1.7*" >actual &&
1852 cat >expect <<-\EOF &&
1853 foo1.7-before1
1854 foo1.7
1855 foo1.7-after1
1856 EOF
1857 test_cmp expect actual
1858'
1859
b8231660 1860test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
0c1b4878
SG
1861 test_config versionsort.prereleaseSuffix -before &&
1862 git config --add versionsort.prereleaseSuffix -after &&
1863 git tag -l --sort=version:refname "foo1.7*" >actual &&
1864 cat >expect <<-\EOF &&
1865 foo1.7-before1
1866 foo1.7-after1
1867 foo1.7
1868 EOF
1869 test_cmp expect actual
1870'
1871
51acfa9d
SG
1872test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1873 test_config versionsort.prereleaseSuffix -bar &&
1874 git config --add versionsort.prereleaseSuffix -foo-baz &&
1875 git config --add versionsort.prereleaseSuffix -foo-bar &&
1876 git tag foo1.8-foo-bar &&
1877 git tag foo1.8-foo-baz &&
1878 git tag foo1.8 &&
1879 git tag -l --sort=version:refname "foo1.8*" >actual &&
1880 cat >expect <<-\EOF &&
1881 foo1.8-foo-baz
1882 foo1.8-foo-bar
1883 foo1.8
1884 EOF
1885 test_cmp expect actual
1886'
1887
1888test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1889 test_config versionsort.prereleaseSuffix -pre &&
1890 git config --add versionsort.prereleaseSuffix -prerelease &&
1891 git tag foo1.9-pre1 &&
1892 git tag foo1.9-pre2 &&
1893 git tag foo1.9-prerelease1 &&
1894 git tag -l --sort=version:refname "foo1.9*" >actual &&
1895 cat >expect <<-\EOF &&
1896 foo1.9-pre1
1897 foo1.9-pre2
1898 foo1.9-prerelease1
1899 EOF
1900 test_cmp expect actual
1901'
1902
c026557a
SG
1903test_expect_success 'version sort with general suffix reordering' '
1904 test_config versionsort.suffix -alpha &&
1905 git config --add versionsort.suffix -beta &&
1906 git config --add versionsort.suffix "" &&
1907 git config --add versionsort.suffix -gamma &&
1908 git config --add versionsort.suffix -delta &&
1909 git tag foo1.10-alpha &&
1910 git tag foo1.10-beta &&
1911 git tag foo1.10-gamma &&
1912 git tag foo1.10-delta &&
1913 git tag foo1.10-unlisted-suffix &&
1914 git tag -l --sort=version:refname "foo1.10*" >actual &&
1915 cat >expect <<-\EOF &&
1916 foo1.10-alpha
1917 foo1.10-beta
1918 foo1.10
1919 foo1.10-unlisted-suffix
1920 foo1.10-gamma
1921 foo1.10-delta
1922 EOF
1923 test_cmp expect actual
1924'
1925
1926test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1927 test_config versionsort.suffix -before &&
1928 test_config versionsort.prereleaseSuffix -after &&
1929 git tag -l --sort=version:refname "foo1.7*" >actual &&
1930 cat >expect <<-\EOF &&
1931 foo1.7-before1
1932 foo1.7
1933 foo1.7-after1
1934 EOF
1935 test_cmp expect actual
1936'
1937
b8231660
SG
1938test_expect_success 'version sort with very long prerelease suffix' '
1939 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1940 git tag -l --sort=version:refname
1941'
1942
ac3f5a34 1943test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
cbc60b67 1944 i=1 &&
b9a19078 1945 while test $i -lt 8000
cbc60b67
JJL
1946 do
1947 echo "commit refs/heads/master
1948committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1949data <<EOF
1950commit #$i
1951EOF"
1952 test $i = 1 && echo "from refs/heads/master^0"
1953 i=$(($i + 1))
1954 done | git fast-import &&
1955 git checkout master &&
1956 git tag far-far-away HEAD^ &&
1957 run_with_limited_stack git tag --contains HEAD >actual &&
d3c6751b 1958 test_must_be_empty actual &&
ac3f5a34 1959 run_with_limited_stack git tag --no-contains HEAD >actual &&
dff28133 1960 test_line_count "-gt" 10 actual
cbc60b67
JJL
1961'
1962
df094741
KN
1963test_expect_success '--format should list tags as per format given' '
1964 cat >expect <<-\EOF &&
0c1b4878
SG
1965 refname : refs/tags/v1.0
1966 refname : refs/tags/v1.0.1
1967 refname : refs/tags/v1.1.3
df094741 1968 EOF
0c1b4878 1969 git tag -l --format="refname : %(refname)" "v1*" >actual &&
df094741
KN
1970 test_cmp expect actual
1971'
1972
11b087ad
JK
1973test_expect_success "set up color tests" '
1974 echo "<RED>v1.0<RESET>" >expect.color &&
1975 echo "v1.0" >expect.bare &&
1976 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1977'
1978
1979test_expect_success '%(color) omitted without tty' '
1980 TERM=vt100 git tag $color_args >actual.raw &&
1981 test_decode_color <actual.raw >actual &&
1982 test_cmp expect.bare actual
1983'
1984
1985test_expect_success TTY '%(color) present with tty' '
e433749d 1986 test_terminal git tag $color_args >actual.raw &&
11b087ad
JK
1987 test_decode_color <actual.raw >actual &&
1988 test_cmp expect.color actual
1989'
1990
0c88bf50
JK
1991test_expect_success '--color overrides auto-color' '
1992 git tag --color $color_args >actual.raw &&
11b087ad
JK
1993 test_decode_color <actual.raw >actual &&
1994 test_cmp expect.color actual
1995'
1996
b521fd12
JK
1997test_expect_success 'color.ui=always overrides auto-color' '
1998 git -c color.ui=always tag $color_args >actual.raw &&
1999 test_decode_color <actual.raw >actual &&
2000 test_cmp expect.color actual
2001'
2002
5242860f
KN
2003test_expect_success 'setup --merged test tags' '
2004 git tag mergetest-1 HEAD~2 &&
2005 git tag mergetest-2 HEAD~1 &&
2006 git tag mergetest-3 HEAD
2007'
2008
6a338149
ÆAB
2009test_expect_success '--merged can be used in non-list mode' '
2010 cat >expect <<-\EOF &&
2011 mergetest-1
2012 mergetest-2
2013 EOF
2014 git tag --merged=mergetest-2 "mergetest*" >actual &&
2015 test_cmp expect actual
5242860f
KN
2016'
2017
17d6c744
ÆAB
2018test_expect_success '--merged is incompatible with --no-merged' '
2019 test_must_fail git tag --merged HEAD --no-merged HEAD
5242860f
KN
2020'
2021
2022test_expect_success '--merged shows merged tags' '
2023 cat >expect <<-\EOF &&
2024 mergetest-1
2025 mergetest-2
2026 EOF
2027 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2028 test_cmp expect actual
2029'
2030
2031test_expect_success '--no-merged show unmerged tags' '
2032 cat >expect <<-\EOF &&
2033 mergetest-3
2034 EOF
2035 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2036 test_cmp expect actual
2037'
2038
6a338149
ÆAB
2039test_expect_success '--no-merged can be used in non-list mode' '
2040 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2041 test_cmp expect actual
2042'
2043
0571979b
JK
2044test_expect_success 'ambiguous branch/tags not marked' '
2045 git tag ambiguous &&
2046 git branch ambiguous &&
2047 echo ambiguous >expect &&
2048 git tag -l ambiguous >actual &&
2049 test_cmp expect actual
2050'
2051
ac3f5a34
ÆAB
2052test_expect_success '--contains combined with --no-contains' '
2053 (
2054 git init no-contains &&
2055 cd no-contains &&
2056 test_commit v0.1 &&
2057 test_commit v0.2 &&
2058 test_commit v0.3 &&
2059 test_commit v0.4 &&
2060 test_commit v0.5 &&
2061 cat >expected <<-\EOF &&
2062 v0.2
2063 v0.3
2064 v0.4
2065 EOF
2066 git tag --contains v0.2 --no-contains v0.5 >actual &&
2067 test_cmp expected actual
2068 )
2069'
2070
2071# As the docs say, list tags which contain a specified *commit*. We
2072# don't recurse down to tags for trees or blobs pointed to by *those*
2073# commits.
2074test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2075 cd no-contains &&
2076 blob=$(git rev-parse v0.3:v0.3.t) &&
2077 tree=$(git rev-parse v0.3^{tree}) &&
2078 git tag tag-blob $blob &&
2079 git tag tag-tree $tree &&
2080 git tag --contains v0.3 >actual &&
2081 cat >expected <<-\EOF &&
2082 v0.3
2083 v0.4
2084 v0.5
2085 EOF
2086 test_cmp expected actual &&
2087 git tag --no-contains v0.3 >actual &&
2088 cat >expected <<-\EOF &&
2089 v0.1
2090 v0.2
2091 EOF
2092 test_cmp expected actual
2093'
2094
ef5a6fb5 2095test_done