]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7004-tag.sh
test-terminal: set TERM=vt100
[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 &&
230 ! tag_exists myhead &&
d592b315 231 test_must_fail git tag -d mytag anothertag &&
ef5a6fb5
CR
232 ! tag_exists mytag &&
233 ! tag_exists myhead
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
328>expect
329test_expect_success \
330 'listing tags using v.* should print nothing because none have v.' '
d592b315 331 git tag -l "v.*" > actual &&
3af82863 332 test_cmp expect actual
ef5a6fb5
CR
333'
334
335cat >expect <<EOF
336v0.2.1
337v1.0
338v1.0.1
339v1.1.3
340EOF
341test_expect_success \
342 'listing tags using v* should print only those having v' '
d592b315 343 git tag -l "v*" > actual &&
3af82863 344 test_cmp expect actual
ef5a6fb5
CR
345'
346
588d0e83
JK
347test_expect_success 'tag -l can accept multiple patterns' '
348 git tag -l "v1*" "v0*" >actual &&
349 test_cmp expect actual
350'
351
c485b24c
ÆAB
352# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
353# could leave you with the impression that "-l <pattern> -l <pattern>"
354# was how we wanted to accept multiple patterns.
355#
356# This test should not imply that this is a sane thing to support. but
357# since the documentation was worded like it was let's at least find
358# out if we're going to break this long-documented form of taking
359# multiple patterns.
360test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
361 git tag -l "v1*" -l "v0*" >actual &&
362 test_cmp expect actual
363'
364
d96e3c15
NTND
365test_expect_success 'listing tags in column' '
366 COLUMNS=40 git tag -l --column=row >actual &&
367 cat >expected <<\EOF &&
368a1 aa1 cba t210 t211
369v0.2.1 v1.0 v1.0.1 v1.1.3
370EOF
371 test_cmp expected actual
372'
373
374test_expect_success 'listing tags in column with column.*' '
9ffda48f
SG
375 test_config column.tag row &&
376 test_config column.ui dense &&
d96e3c15 377 COLUMNS=40 git tag -l >actual &&
d96e3c15
NTND
378 cat >expected <<\EOF &&
379a1 aa1 cba t210 t211
380v0.2.1 v1.0 v1.0.1 v1.1.3
381EOF
382 test_cmp expected actual
383'
384
385test_expect_success 'listing tag with -n --column should fail' '
386 test_must_fail git tag --column -n
387'
388
389test_expect_success 'listing tags -n in column with column.ui ignored' '
9ffda48f 390 test_config column.ui "row dense" &&
d96e3c15 391 COLUMNS=40 git tag -l -n >actual &&
d96e3c15
NTND
392 cat >expected <<\EOF &&
393a1 Foo
394aa1 Foo
395cba Foo
396t210 Foo
397t211 Foo
398v0.2.1 Foo
399v1.0 Foo
400v1.0.1 Foo
401v1.1.3 Foo
402EOF
403 test_cmp expected actual
404'
405
ef5a6fb5
CR
406# creating and verifying lightweight tags:
407
408test_expect_success \
409 'a non-annotated tag created without parameters should point to HEAD' '
d592b315 410 git tag non-annotated-tag &&
5be60078
JH
411 test $(git cat-file -t non-annotated-tag) = commit &&
412 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
ef5a6fb5
CR
413'
414
41ac414e 415test_expect_success 'trying to verify an unknown tag should fail' \
d592b315 416 'test_must_fail git tag -v unknown-tag'
ef5a6fb5 417
41ac414e 418test_expect_success \
ef5a6fb5 419 'trying to verify a non-annotated and non-signed tag should fail' \
d592b315 420 'test_must_fail git tag -v non-annotated-tag'
ef5a6fb5 421
41ac414e 422test_expect_success \
62e09ce9 423 'trying to verify many non-annotated or unknown tags, should fail' \
d592b315 424 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
62e09ce9 425
ef5a6fb5
CR
426# creating annotated tags:
427
428get_tag_msg () {
429 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
430}
431
432# run test_tick before committing always gives the time in that timezone
433get_tag_header () {
434cat <<EOF
435object $2
436type $3
437tag $1
438tagger C O Mitter <committer@example.com> $4 -0700
439
440EOF
441}
442
443commit=$(git rev-parse HEAD)
444time=$test_tick
445
446get_tag_header annotated-tag $commit commit $time >expect
447echo "A message" >>expect
448test_expect_success \
449 'creating an annotated tag with -m message should succeed' '
d592b315 450 git tag -m "A message" annotated-tag &&
ef5a6fb5 451 get_tag_msg annotated-tag >actual &&
3af82863 452 test_cmp expect actual
ef5a6fb5
CR
453'
454
455cat >msgfile <<EOF
456Another message
457in a file.
458EOF
459get_tag_header file-annotated-tag $commit commit $time >expect
460cat msgfile >>expect
461test_expect_success \
462 'creating an annotated tag with -F messagefile should succeed' '
d592b315 463 git tag -F msgfile file-annotated-tag &&
ef5a6fb5 464 get_tag_msg file-annotated-tag >actual &&
3af82863 465 test_cmp expect actual
ef5a6fb5
CR
466'
467
62e09ce9
CR
468cat >inputmsg <<EOF
469A message from the
470standard input
471EOF
472get_tag_header stdin-annotated-tag $commit commit $time >expect
473cat inputmsg >>expect
474test_expect_success 'creating an annotated tag with -F - should succeed' '
d592b315 475 git tag -F - stdin-annotated-tag <inputmsg &&
62e09ce9 476 get_tag_msg stdin-annotated-tag >actual &&
3af82863 477 test_cmp expect actual
62e09ce9
CR
478'
479
e317cfaf
CR
480test_expect_success \
481 'trying to create a tag with a non-existing -F file should fail' '
482 ! test -f nonexistingfile &&
483 ! tag_exists notag &&
d592b315 484 test_must_fail git tag -F nonexistingfile notag &&
e317cfaf
CR
485 ! tag_exists notag
486'
487
488test_expect_success \
39686585 489 'trying to create tags giving both -m or -F options should fail' '
e317cfaf
CR
490 echo "message file 1" >msgfile1 &&
491 echo "message file 2" >msgfile2 &&
492 ! tag_exists msgtag &&
d592b315 493 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
e317cfaf 494 ! tag_exists msgtag &&
d592b315 495 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
e317cfaf 496 ! tag_exists msgtag &&
d592b315 497 test_must_fail git tag -m "message 1" -F msgfile1 \
d492b31c 498 -m "message 2" msgtag &&
e317cfaf
CR
499 ! tag_exists msgtag
500'
501
ef5a6fb5
CR
502# blank and empty messages:
503
504get_tag_header empty-annotated-tag $commit commit $time >expect
505test_expect_success \
506 'creating a tag with an empty -m message should succeed' '
d592b315 507 git tag -m "" empty-annotated-tag &&
ef5a6fb5 508 get_tag_msg empty-annotated-tag >actual &&
3af82863 509 test_cmp expect actual
ef5a6fb5
CR
510'
511
512>emptyfile
513get_tag_header emptyfile-annotated-tag $commit commit $time >expect
514test_expect_success \
515 'creating a tag with an empty -F messagefile should succeed' '
d592b315 516 git tag -F emptyfile emptyfile-annotated-tag &&
ef5a6fb5 517 get_tag_msg emptyfile-annotated-tag >actual &&
3af82863 518 test_cmp expect actual
ef5a6fb5
CR
519'
520
521printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
522printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
523printf '\n\n\nTrailing spaces \t \n' >>blanksfile
524printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
525get_tag_header blanks-annotated-tag $commit commit $time >expect
526cat >>expect <<EOF
527Leading blank lines
528
529Repeated blank lines
530
531Trailing spaces
532
533Trailing blank lines
534EOF
535test_expect_success \
536 'extra blanks in the message for an annotated tag should be removed' '
d592b315 537 git tag -F blanksfile blanks-annotated-tag &&
ef5a6fb5 538 get_tag_msg blanks-annotated-tag >actual &&
3af82863 539 test_cmp expect actual
ef5a6fb5
CR
540'
541
542get_tag_header blank-annotated-tag $commit commit $time >expect
543test_expect_success \
544 'creating a tag with blank -m message with spaces should succeed' '
d592b315 545 git tag -m " " blank-annotated-tag &&
ef5a6fb5 546 get_tag_msg blank-annotated-tag >actual &&
3af82863 547 test_cmp expect actual
ef5a6fb5
CR
548'
549
550echo ' ' >blankfile
551echo '' >>blankfile
552echo ' ' >>blankfile
553get_tag_header blankfile-annotated-tag $commit commit $time >expect
554test_expect_success \
555 'creating a tag with blank -F messagefile with spaces should succeed' '
d592b315 556 git tag -F blankfile blankfile-annotated-tag &&
ef5a6fb5 557 get_tag_msg blankfile-annotated-tag >actual &&
3af82863 558 test_cmp expect actual
ef5a6fb5
CR
559'
560
561printf ' ' >blanknonlfile
562get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
563test_expect_success \
564 'creating a tag with -F file of spaces and no newline should succeed' '
d592b315 565 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
ef5a6fb5 566 get_tag_msg blanknonlfile-annotated-tag >actual &&
3af82863 567 test_cmp expect actual
ef5a6fb5
CR
568'
569
570# messages with commented lines:
571
572cat >commentsfile <<EOF
573# A comment
574
575############
576The message.
577############
578One line.
579
580
581# commented lines
582# commented lines
583
584Another line.
585# comments
586
587Last line.
588EOF
589get_tag_header comments-annotated-tag $commit commit $time >expect
590cat >>expect <<EOF
591The message.
592One line.
593
594Another line.
595
596Last line.
597EOF
598test_expect_success \
599 'creating a tag using a -F messagefile with #comments should succeed' '
d592b315 600 git tag -F commentsfile comments-annotated-tag &&
ef5a6fb5 601 get_tag_msg comments-annotated-tag >actual &&
3af82863 602 test_cmp expect actual
ef5a6fb5
CR
603'
604
605get_tag_header comment-annotated-tag $commit commit $time >expect
606test_expect_success \
607 'creating a tag with a #comment in the -m message should succeed' '
d592b315 608 git tag -m "#comment" comment-annotated-tag &&
ef5a6fb5 609 get_tag_msg comment-annotated-tag >actual &&
3af82863 610 test_cmp expect actual
ef5a6fb5
CR
611'
612
613echo '#comment' >commentfile
614echo '' >>commentfile
615echo '####' >>commentfile
616get_tag_header commentfile-annotated-tag $commit commit $time >expect
617test_expect_success \
618 'creating a tag with #comments in the -F messagefile should succeed' '
d592b315 619 git tag -F commentfile commentfile-annotated-tag &&
ef5a6fb5 620 get_tag_msg commentfile-annotated-tag >actual &&
3af82863 621 test_cmp expect actual
ef5a6fb5
CR
622'
623
624printf '#comment' >commentnonlfile
625get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
626test_expect_success \
627 'creating a tag with a file of #comment and no newline should succeed' '
d592b315 628 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
ef5a6fb5 629 get_tag_msg commentnonlfile-annotated-tag >actual &&
3af82863 630 test_cmp expect actual
ef5a6fb5
CR
631'
632
5206d130
CR
633# listing messages for annotated non-signed tags:
634
635test_expect_success \
636 'listing the one-line message of a non-signed tag should succeed' '
d592b315 637 git tag -m "A msg" tag-one-line &&
5206d130
CR
638
639 echo "tag-one-line" >expect &&
d592b315 640 git tag -l | grep "^tag-one-line" >actual &&
3af82863 641 test_cmp expect actual &&
d592b315 642 git tag -n0 -l | grep "^tag-one-line" >actual &&
3af82863 643 test_cmp expect actual &&
d592b315 644 git tag -n0 -l tag-one-line >actual &&
3af82863 645 test_cmp expect actual &&
5206d130 646
6a338149
ÆAB
647 git tag -n0 | grep "^tag-one-line" >actual &&
648 test_cmp expect actual &&
649 git tag -n0 tag-one-line >actual &&
650 test_cmp expect actual &&
651
5206d130 652 echo "tag-one-line A msg" >expect &&
d592b315 653 git tag -n1 -l | grep "^tag-one-line" >actual &&
3af82863 654 test_cmp expect actual &&
d592b315 655 git tag -n -l | grep "^tag-one-line" >actual &&
3af82863 656 test_cmp expect actual &&
d592b315 657 git tag -n1 -l tag-one-line >actual &&
3af82863 658 test_cmp expect actual &&
d592b315 659 git tag -n2 -l tag-one-line >actual &&
3af82863 660 test_cmp expect actual &&
d592b315 661 git tag -n999 -l tag-one-line >actual &&
3af82863 662 test_cmp expect actual
5206d130
CR
663'
664
6a338149
ÆAB
665test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
666 >expect &&
667 git tag -n 100 >actual &&
668 test_cmp expect actual &&
669
670 git tag -m "A msg" 100 &&
671 echo "100 A msg" >expect &&
672 git tag -n 100 >actual &&
673 test_cmp expect actual
674'
675
5206d130
CR
676test_expect_success \
677 'listing the zero-lines message of a non-signed tag should succeed' '
d592b315 678 git tag -m "" tag-zero-lines &&
5206d130
CR
679
680 echo "tag-zero-lines" >expect &&
d592b315 681 git tag -l | grep "^tag-zero-lines" >actual &&
3af82863 682 test_cmp expect actual &&
d592b315 683 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
3af82863 684 test_cmp expect actual &&
d592b315 685 git tag -n0 -l tag-zero-lines >actual &&
3af82863 686 test_cmp expect actual &&
5206d130
CR
687
688 echo "tag-zero-lines " >expect &&
d592b315 689 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
3af82863 690 test_cmp expect actual &&
d592b315 691 git tag -n -l | grep "^tag-zero-lines" >actual &&
3af82863 692 test_cmp expect actual &&
d592b315 693 git tag -n1 -l tag-zero-lines >actual &&
3af82863 694 test_cmp expect actual &&
d592b315 695 git tag -n2 -l tag-zero-lines >actual &&
3af82863 696 test_cmp expect actual &&
d592b315 697 git tag -n999 -l tag-zero-lines >actual &&
3af82863 698 test_cmp expect actual
5206d130
CR
699'
700
701echo 'tag line one' >annotagmsg
702echo 'tag line two' >>annotagmsg
703echo 'tag line three' >>annotagmsg
704test_expect_success \
705 'listing many message lines of a non-signed tag should succeed' '
d592b315 706 git tag -F annotagmsg tag-lines &&
5206d130
CR
707
708 echo "tag-lines" >expect &&
d592b315 709 git tag -l | grep "^tag-lines" >actual &&
3af82863 710 test_cmp expect actual &&
d592b315 711 git tag -n0 -l | grep "^tag-lines" >actual &&
3af82863 712 test_cmp expect actual &&
d592b315 713 git tag -n0 -l tag-lines >actual &&
3af82863 714 test_cmp expect actual &&
5206d130
CR
715
716 echo "tag-lines tag line one" >expect &&
d592b315 717 git tag -n1 -l | grep "^tag-lines" >actual &&
3af82863 718 test_cmp expect actual &&
d592b315 719 git tag -n -l | grep "^tag-lines" >actual &&
3af82863 720 test_cmp expect actual &&
d592b315 721 git tag -n1 -l tag-lines >actual &&
3af82863 722 test_cmp expect actual &&
5206d130
CR
723
724 echo " tag line two" >>expect &&
d592b315 725 git tag -n2 -l | grep "^ *tag.line" >actual &&
3af82863 726 test_cmp expect actual &&
d592b315 727 git tag -n2 -l tag-lines >actual &&
3af82863 728 test_cmp expect actual &&
5206d130
CR
729
730 echo " tag line three" >>expect &&
d592b315 731 git tag -n3 -l | grep "^ *tag.line" >actual &&
3af82863 732 test_cmp expect actual &&
d592b315 733 git tag -n3 -l tag-lines >actual &&
3af82863 734 test_cmp expect actual &&
d592b315 735 git tag -n4 -l | grep "^ *tag.line" >actual &&
3af82863 736 test_cmp expect actual &&
d592b315 737 git tag -n4 -l tag-lines >actual &&
3af82863 738 test_cmp expect actual &&
d592b315 739 git tag -n99 -l | grep "^ *tag.line" >actual &&
3af82863 740 test_cmp expect actual &&
d592b315 741 git tag -n99 -l tag-lines >actual &&
3af82863 742 test_cmp expect actual
5206d130
CR
743'
744
31fd8d72
JH
745test_expect_success 'annotations for blobs are empty' '
746 blob=$(git hash-object -w --stdin <<-\EOF
747 Blob paragraph 1.
748
749 Blob paragraph 2.
750 EOF
751 ) &&
752 git tag tag-blob $blob &&
753 echo "tag-blob " >expect &&
754 git tag -n1 -l tag-blob >actual &&
755 test_cmp expect actual
756'
757
ef5a6fb5
CR
758# trying to verify annotated non-signed tags:
759
a4df22ce 760test_expect_success GPG \
ef5a6fb5
CR
761 'trying to verify an annotated non-signed tag should fail' '
762 tag_exists annotated-tag &&
d592b315 763 test_must_fail git tag -v annotated-tag
ef5a6fb5
CR
764'
765
a4df22ce 766test_expect_success GPG \
ef5a6fb5
CR
767 'trying to verify a file-annotated non-signed tag should fail' '
768 tag_exists file-annotated-tag &&
d592b315 769 test_must_fail git tag -v file-annotated-tag
ef5a6fb5
CR
770'
771
a4df22ce 772test_expect_success GPG \
62e09ce9
CR
773 'trying to verify two annotated non-signed tags should fail' '
774 tag_exists annotated-tag file-annotated-tag &&
d592b315 775 test_must_fail git tag -v annotated-tag file-annotated-tag
62e09ce9
CR
776'
777
ef5a6fb5
CR
778# creating and verifying signed tags:
779
ef5a6fb5
CR
780get_tag_header signed-tag $commit commit $time >expect
781echo 'A signed tag message' >>expect
782echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 783test_expect_success GPG 'creating a signed tag with -m message should succeed' '
d592b315 784 git tag -s -m "A signed tag message" signed-tag &&
ef5a6fb5 785 get_tag_msg signed-tag >actual &&
3af82863 786 test_cmp expect actual
ef5a6fb5
CR
787'
788
be15f505
LT
789get_tag_header u-signed-tag $commit commit $time >expect
790echo 'Another message' >>expect
791echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 792test_expect_success GPG 'sign with a given key id' '
be15f505
LT
793
794 git tag -u committer@example.com -m "Another message" u-signed-tag &&
795 get_tag_msg u-signed-tag >actual &&
3af82863 796 test_cmp expect actual
be15f505
LT
797
798'
799
a4df22ce 800test_expect_success GPG 'sign with an unknown id (1)' '
be15f505 801
d492b31c
SB
802 test_must_fail git tag -u author@example.com \
803 -m "Another message" o-signed-tag
be15f505
LT
804
805'
806
a4df22ce 807test_expect_success GPG 'sign with an unknown id (2)' '
be15f505 808
d492b31c 809 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
be15f505
LT
810
811'
812
813cat >fakeeditor <<'EOF'
814#!/bin/sh
815test -n "$1" && exec >"$1"
816echo A signed tag message
817echo from a fake editor.
818EOF
819chmod +x fakeeditor
820
821get_tag_header implied-sign $commit commit $time >expect
822./fakeeditor >>expect
823echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 824test_expect_success GPG '-u implies signed tag' '
d592b315 825 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
be15f505 826 get_tag_msg implied-sign >actual &&
3af82863 827 test_cmp expect actual
be15f505
LT
828'
829
62e09ce9
CR
830cat >sigmsgfile <<EOF
831Another signed tag
832message in a file.
833EOF
834get_tag_header file-signed-tag $commit commit $time >expect
835cat sigmsgfile >>expect
836echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 837test_expect_success GPG \
62e09ce9 838 'creating a signed tag with -F messagefile should succeed' '
d592b315 839 git tag -s -F sigmsgfile file-signed-tag &&
62e09ce9 840 get_tag_msg file-signed-tag >actual &&
3af82863 841 test_cmp expect actual
62e09ce9
CR
842'
843
844cat >siginputmsg <<EOF
845A signed tag message from
846the standard input
847EOF
848get_tag_header stdin-signed-tag $commit commit $time >expect
849cat siginputmsg >>expect
850echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 851test_expect_success GPG 'creating a signed tag with -F - should succeed' '
d592b315 852 git tag -s -F - stdin-signed-tag <siginputmsg &&
62e09ce9 853 get_tag_msg stdin-signed-tag >actual &&
3af82863 854 test_cmp expect actual
62e09ce9
CR
855'
856
10507857
JK
857get_tag_header implied-annotate $commit commit $time >expect
858./fakeeditor >>expect
859echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 860test_expect_success GPG '-s implies annotated tag' '
d592b315 861 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
10507857 862 get_tag_msg implied-annotate >actual &&
3af82863 863 test_cmp expect actual
10507857
JK
864'
865
61c2fe0c
LA
866get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
867echo "A message" >>expect
868echo '-----BEGIN PGP SIGNATURE-----' >>expect
869test_expect_success GPG \
870 'git tag -s implied if configured with tag.forcesignannotated' \
871 'test_config tag.forcesignannotated true &&
872 git tag -m "A message" forcesignannotated-implied-sign &&
873 get_tag_msg forcesignannotated-implied-sign >actual &&
874 test_cmp expect actual
875'
876
877test_expect_success GPG \
878 'lightweight with no message when configured with tag.forcesignannotated' \
879 'test_config tag.forcesignannotated true &&
880 git tag forcesignannotated-lightweight &&
881 tag_exists forcesignannotated-lightweight &&
882 test_must_fail git tag -v forcesignannotated-no-message
883'
884
885get_tag_header forcesignannotated-annotate $commit commit $time >expect
886echo "A message" >>expect
887test_expect_success GPG \
888 'git tag -a disable configured tag.forcesignannotated' \
889 'test_config tag.forcesignannotated true &&
890 git tag -a -m "A message" forcesignannotated-annotate &&
891 get_tag_msg forcesignannotated-annotate >actual &&
892 test_cmp expect actual &&
893 test_must_fail git tag -v forcesignannotated-annotate
894'
895
896get_tag_header forcesignannotated-disabled $commit commit $time >expect
897echo "A message" >>expect
898echo '-----BEGIN PGP SIGNATURE-----' >>expect
899test_expect_success GPG \
900 'git tag --sign enable GPG sign' \
901 'test_config tag.forcesignannotated false &&
902 git tag --sign -m "A message" forcesignannotated-disabled &&
903 get_tag_msg forcesignannotated-disabled >actual &&
904 test_cmp expect actual
905'
906
a4df22ce 907test_expect_success GPG \
e317cfaf
CR
908 'trying to create a signed tag with non-existing -F file should fail' '
909 ! test -f nonexistingfile &&
910 ! tag_exists nosigtag &&
d592b315 911 test_must_fail git tag -s -F nonexistingfile nosigtag &&
e317cfaf
CR
912 ! tag_exists nosigtag
913'
914
a4df22ce 915test_expect_success GPG 'verifying a signed tag should succeed' \
d592b315 916 'git tag -v signed-tag'
ef5a6fb5 917
a4df22ce 918test_expect_success GPG 'verifying two signed tags in one command should succeed' \
d592b315 919 'git tag -v signed-tag file-signed-tag'
62e09ce9 920
a4df22ce 921test_expect_success GPG \
62e09ce9 922 'verifying many signed and non-signed tags should fail' '
d592b315
NS
923 test_must_fail git tag -v signed-tag annotated-tag &&
924 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
925 test_must_fail git tag -v annotated-tag \
d492b31c 926 file-signed-tag file-annotated-tag &&
d592b315 927 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
62e09ce9
CR
928'
929
a4df22ce 930test_expect_success GPG 'verifying a forged tag should fail' '
ef5a6fb5
CR
931 forged=$(git cat-file tag signed-tag |
932 sed -e "s/signed-tag/forged-tag/" |
933 git mktag) &&
934 git tag forged-tag $forged &&
d592b315 935 test_must_fail git tag -v forged-tag
ef5a6fb5
CR
936'
937
b42ca35e
ST
938test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
939 cat >expect <<-\EOF &&
4fea72f4 940 tagname : signed-tag
b42ca35e 941 EOF
4fea72f4
ST
942 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
943 test_cmp expect actual
944'
945
b42ca35e
ST
946test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
947 >expect &&
4fea72f4
ST
948 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
949 test_cmp expect actual
950'
951
ef5a6fb5
CR
952# blank and empty messages for signed tags:
953
954get_tag_header empty-signed-tag $commit commit $time >expect
955echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 956test_expect_success GPG \
ef5a6fb5 957 'creating a signed tag with an empty -m message should succeed' '
d592b315 958 git tag -s -m "" empty-signed-tag &&
ef5a6fb5 959 get_tag_msg empty-signed-tag >actual &&
3af82863 960 test_cmp expect actual &&
d592b315 961 git tag -v empty-signed-tag
ef5a6fb5
CR
962'
963
964>sigemptyfile
965get_tag_header emptyfile-signed-tag $commit commit $time >expect
966echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 967test_expect_success GPG \
ef5a6fb5 968 'creating a signed tag with an empty -F messagefile should succeed' '
d592b315 969 git tag -s -F sigemptyfile emptyfile-signed-tag &&
ef5a6fb5 970 get_tag_msg emptyfile-signed-tag >actual &&
3af82863 971 test_cmp expect actual &&
d592b315 972 git tag -v emptyfile-signed-tag
ef5a6fb5
CR
973'
974
975printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
976printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
977printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
978printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
979get_tag_header blanks-signed-tag $commit commit $time >expect
980cat >>expect <<EOF
981Leading blank lines
982
983Repeated blank lines
984
985Trailing spaces
986
987Trailing blank lines
988EOF
989echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 990test_expect_success GPG \
ef5a6fb5 991 'extra blanks in the message for a signed tag should be removed' '
d592b315 992 git tag -s -F sigblanksfile blanks-signed-tag &&
ef5a6fb5 993 get_tag_msg blanks-signed-tag >actual &&
3af82863 994 test_cmp expect actual &&
d592b315 995 git tag -v blanks-signed-tag
ef5a6fb5
CR
996'
997
998get_tag_header blank-signed-tag $commit commit $time >expect
999echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1000test_expect_success GPG \
ef5a6fb5 1001 'creating a signed tag with a blank -m message should succeed' '
d592b315 1002 git tag -s -m " " blank-signed-tag &&
ef5a6fb5 1003 get_tag_msg blank-signed-tag >actual &&
3af82863 1004 test_cmp expect actual &&
d592b315 1005 git tag -v blank-signed-tag
ef5a6fb5
CR
1006'
1007
1008echo ' ' >sigblankfile
1009echo '' >>sigblankfile
1010echo ' ' >>sigblankfile
1011get_tag_header blankfile-signed-tag $commit commit $time >expect
1012echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1013test_expect_success GPG \
ef5a6fb5 1014 'creating a signed tag with blank -F file with spaces should succeed' '
d592b315 1015 git tag -s -F sigblankfile blankfile-signed-tag &&
ef5a6fb5 1016 get_tag_msg blankfile-signed-tag >actual &&
3af82863 1017 test_cmp expect actual &&
d592b315 1018 git tag -v blankfile-signed-tag
ef5a6fb5
CR
1019'
1020
1021printf ' ' >sigblanknonlfile
1022get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1023echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1024test_expect_success GPG \
ef5a6fb5 1025 'creating a signed tag with spaces and no newline should succeed' '
d592b315 1026 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
ef5a6fb5 1027 get_tag_msg blanknonlfile-signed-tag >actual &&
3af82863 1028 test_cmp expect actual &&
d592b315 1029 git tag -v signed-tag
ef5a6fb5
CR
1030'
1031
1032# messages with commented lines for signed tags:
1033
1034cat >sigcommentsfile <<EOF
1035# A comment
1036
1037############
1038The message.
1039############
1040One line.
1041
1042
1043# commented lines
1044# commented lines
1045
1046Another line.
1047# comments
1048
1049Last line.
1050EOF
1051get_tag_header comments-signed-tag $commit commit $time >expect
1052cat >>expect <<EOF
1053The message.
1054One line.
1055
1056Another line.
1057
1058Last line.
1059EOF
1060echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1061test_expect_success GPG \
ef5a6fb5 1062 'creating a signed tag with a -F file with #comments should succeed' '
d592b315 1063 git tag -s -F sigcommentsfile comments-signed-tag &&
ef5a6fb5 1064 get_tag_msg comments-signed-tag >actual &&
3af82863 1065 test_cmp expect actual &&
d592b315 1066 git tag -v comments-signed-tag
ef5a6fb5
CR
1067'
1068
1069get_tag_header comment-signed-tag $commit commit $time >expect
1070echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1071test_expect_success GPG \
ef5a6fb5 1072 'creating a signed tag with #commented -m message should succeed' '
d592b315 1073 git tag -s -m "#comment" comment-signed-tag &&
ef5a6fb5 1074 get_tag_msg comment-signed-tag >actual &&
3af82863 1075 test_cmp expect actual &&
d592b315 1076 git tag -v comment-signed-tag
ef5a6fb5
CR
1077'
1078
1079echo '#comment' >sigcommentfile
1080echo '' >>sigcommentfile
1081echo '####' >>sigcommentfile
1082get_tag_header commentfile-signed-tag $commit commit $time >expect
1083echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1084test_expect_success GPG \
ef5a6fb5 1085 'creating a signed tag with #commented -F messagefile should succeed' '
d592b315 1086 git tag -s -F sigcommentfile commentfile-signed-tag &&
ef5a6fb5 1087 get_tag_msg commentfile-signed-tag >actual &&
3af82863 1088 test_cmp expect actual &&
d592b315 1089 git tag -v commentfile-signed-tag
ef5a6fb5
CR
1090'
1091
1092printf '#comment' >sigcommentnonlfile
1093get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1094echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1095test_expect_success GPG \
ef5a6fb5 1096 'creating a signed tag with a #comment and no newline should succeed' '
d592b315 1097 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
ef5a6fb5 1098 get_tag_msg commentnonlfile-signed-tag >actual &&
3af82863 1099 test_cmp expect actual &&
d592b315 1100 git tag -v commentnonlfile-signed-tag
ef5a6fb5
CR
1101'
1102
5206d130
CR
1103# listing messages for signed tags:
1104
a4df22ce 1105test_expect_success GPG \
5206d130 1106 'listing the one-line message of a signed tag should succeed' '
d592b315 1107 git tag -s -m "A message line signed" stag-one-line &&
5206d130
CR
1108
1109 echo "stag-one-line" >expect &&
d592b315 1110 git tag -l | grep "^stag-one-line" >actual &&
3af82863 1111 test_cmp expect actual &&
d592b315 1112 git tag -n0 -l | grep "^stag-one-line" >actual &&
3af82863 1113 test_cmp expect actual &&
d592b315 1114 git tag -n0 -l stag-one-line >actual &&
3af82863 1115 test_cmp expect actual &&
5206d130
CR
1116
1117 echo "stag-one-line A message line signed" >expect &&
d592b315 1118 git tag -n1 -l | grep "^stag-one-line" >actual &&
3af82863 1119 test_cmp expect actual &&
d592b315 1120 git tag -n -l | grep "^stag-one-line" >actual &&
3af82863 1121 test_cmp expect actual &&
d592b315 1122 git tag -n1 -l stag-one-line >actual &&
3af82863 1123 test_cmp expect actual &&
d592b315 1124 git tag -n2 -l stag-one-line >actual &&
3af82863 1125 test_cmp expect actual &&
d592b315 1126 git tag -n999 -l stag-one-line >actual &&
3af82863 1127 test_cmp expect actual
5206d130
CR
1128'
1129
a4df22ce 1130test_expect_success GPG \
5206d130 1131 'listing the zero-lines message of a signed tag should succeed' '
d592b315 1132 git tag -s -m "" stag-zero-lines &&
5206d130
CR
1133
1134 echo "stag-zero-lines" >expect &&
d592b315 1135 git tag -l | grep "^stag-zero-lines" >actual &&
3af82863 1136 test_cmp expect actual &&
d592b315 1137 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
3af82863 1138 test_cmp expect actual &&
d592b315 1139 git tag -n0 -l stag-zero-lines >actual &&
3af82863 1140 test_cmp expect actual &&
5206d130
CR
1141
1142 echo "stag-zero-lines " >expect &&
d592b315 1143 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
3af82863 1144 test_cmp expect actual &&
d592b315 1145 git tag -n -l | grep "^stag-zero-lines" >actual &&
3af82863 1146 test_cmp expect actual &&
d592b315 1147 git tag -n1 -l stag-zero-lines >actual &&
3af82863 1148 test_cmp expect actual &&
d592b315 1149 git tag -n2 -l stag-zero-lines >actual &&
3af82863 1150 test_cmp expect actual &&
d592b315 1151 git tag -n999 -l stag-zero-lines >actual &&
3af82863 1152 test_cmp expect actual
5206d130
CR
1153'
1154
1155echo 'stag line one' >sigtagmsg
1156echo 'stag line two' >>sigtagmsg
1157echo 'stag line three' >>sigtagmsg
a4df22ce 1158test_expect_success GPG \
5206d130 1159 'listing many message lines of a signed tag should succeed' '
d592b315 1160 git tag -s -F sigtagmsg stag-lines &&
5206d130
CR
1161
1162 echo "stag-lines" >expect &&
d592b315 1163 git tag -l | grep "^stag-lines" >actual &&
3af82863 1164 test_cmp expect actual &&
d592b315 1165 git tag -n0 -l | grep "^stag-lines" >actual &&
3af82863 1166 test_cmp expect actual &&
d592b315 1167 git tag -n0 -l stag-lines >actual &&
3af82863 1168 test_cmp expect actual &&
5206d130
CR
1169
1170 echo "stag-lines stag line one" >expect &&
d592b315 1171 git tag -n1 -l | grep "^stag-lines" >actual &&
3af82863 1172 test_cmp expect actual &&
d592b315 1173 git tag -n -l | grep "^stag-lines" >actual &&
3af82863 1174 test_cmp expect actual &&
d592b315 1175 git tag -n1 -l stag-lines >actual &&
3af82863 1176 test_cmp expect actual &&
5206d130
CR
1177
1178 echo " stag line two" >>expect &&
d592b315 1179 git tag -n2 -l | grep "^ *stag.line" >actual &&
3af82863 1180 test_cmp expect actual &&
d592b315 1181 git tag -n2 -l stag-lines >actual &&
3af82863 1182 test_cmp expect actual &&
5206d130
CR
1183
1184 echo " stag line three" >>expect &&
d592b315 1185 git tag -n3 -l | grep "^ *stag.line" >actual &&
3af82863 1186 test_cmp expect actual &&
d592b315 1187 git tag -n3 -l stag-lines >actual &&
3af82863 1188 test_cmp expect actual &&
d592b315 1189 git tag -n4 -l | grep "^ *stag.line" >actual &&
3af82863 1190 test_cmp expect actual &&
d592b315 1191 git tag -n4 -l stag-lines >actual &&
3af82863 1192 test_cmp expect actual &&
d592b315 1193 git tag -n99 -l | grep "^ *stag.line" >actual &&
3af82863 1194 test_cmp expect actual &&
d592b315 1195 git tag -n99 -l stag-lines >actual &&
3af82863 1196 test_cmp expect actual
5206d130
CR
1197'
1198
ef5a6fb5
CR
1199# tags pointing to objects different from commits:
1200
1201tree=$(git rev-parse HEAD^{tree})
1202blob=$(git rev-parse HEAD:foo)
a4df22ce 1203tag=$(git rev-parse signed-tag 2>/dev/null)
ef5a6fb5
CR
1204
1205get_tag_header tree-signed-tag $tree tree $time >expect
1206echo "A message for a tree" >>expect
1207echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1208test_expect_success GPG \
ef5a6fb5 1209 'creating a signed tag pointing to a tree should succeed' '
d592b315 1210 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
ef5a6fb5 1211 get_tag_msg tree-signed-tag >actual &&
3af82863 1212 test_cmp expect actual
ef5a6fb5
CR
1213'
1214
1215get_tag_header blob-signed-tag $blob blob $time >expect
1216echo "A message for a blob" >>expect
1217echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1218test_expect_success GPG \
ef5a6fb5 1219 'creating a signed tag pointing to a blob should succeed' '
d592b315 1220 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
ef5a6fb5 1221 get_tag_msg blob-signed-tag >actual &&
3af82863 1222 test_cmp expect actual
ef5a6fb5
CR
1223'
1224
1225get_tag_header tag-signed-tag $tag tag $time >expect
1226echo "A message for another tag" >>expect
1227echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1228test_expect_success GPG \
ef5a6fb5 1229 'creating a signed tag pointing to another tag should succeed' '
d592b315 1230 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
ef5a6fb5 1231 get_tag_msg tag-signed-tag >actual &&
3af82863 1232 test_cmp expect actual
ef5a6fb5
CR
1233'
1234
c8525c30 1235# usage with rfc1991 signatures
c8525c30
MG
1236get_tag_header rfc1991-signed-tag $commit commit $time >expect
1237echo "RFC1991 signed tag" >>expect
1238echo '-----BEGIN PGP MESSAGE-----' >>expect
c0e0ed6e 1239test_expect_success GPG,RFC1991 \
c8525c30 1240 'creating a signed tag with rfc1991' '
086cb911 1241 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1242 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1243 get_tag_msg rfc1991-signed-tag >actual &&
1244 test_cmp expect actual
1245'
1246
1247cat >fakeeditor <<'EOF'
1248#!/bin/sh
1249cp "$1" actual
1250EOF
1251chmod +x fakeeditor
1252
c0e0ed6e 1253test_expect_success GPG,RFC1991 \
c8525c30 1254 'reediting a signed tag body omits signature' '
086cb911 1255 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1256 echo "RFC1991 signed tag" >expect &&
1257 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1258 test_cmp expect actual
1259'
1260
c0e0ed6e 1261test_expect_success GPG,RFC1991 \
c8525c30 1262 'verifying rfc1991 signature' '
086cb911 1263 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1264 git tag -v rfc1991-signed-tag
1265'
1266
c0e0ed6e 1267test_expect_success GPG,RFC1991 \
c8525c30 1268 'list tag with rfc1991 signature' '
086cb911 1269 echo "rfc1991" >gpghome/gpg.conf &&
c8525c30
MG
1270 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1271 git tag -l -n1 rfc1991-signed-tag >actual &&
1272 test_cmp expect actual &&
1273 git tag -l -n2 rfc1991-signed-tag >actual &&
1274 test_cmp expect actual &&
1275 git tag -l -n999 rfc1991-signed-tag >actual &&
1276 test_cmp expect actual
1277'
1278
1279rm -f gpghome/gpg.conf
1280
c0e0ed6e 1281test_expect_success GPG,RFC1991 \
c8525c30
MG
1282 'verifying rfc1991 signature without --rfc1991' '
1283 git tag -v rfc1991-signed-tag
1284'
1285
c0e0ed6e 1286test_expect_success GPG,RFC1991 \
c8525c30
MG
1287 'list tag with rfc1991 signature without --rfc1991' '
1288 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1289 git tag -l -n1 rfc1991-signed-tag >actual &&
1290 test_cmp expect actual &&
1291 git tag -l -n2 rfc1991-signed-tag >actual &&
1292 test_cmp expect actual &&
1293 git tag -l -n999 rfc1991-signed-tag >actual &&
1294 test_cmp expect actual
1295'
1296
c0e0ed6e 1297test_expect_success GPG,RFC1991 \
c8525c30
MG
1298 'reediting a signed tag body omits signature' '
1299 echo "RFC1991 signed tag" >expect &&
1300 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1301 test_cmp expect actual
1302'
1303
aba91192 1304# try to sign with bad user.signingkey
a4df22ce 1305test_expect_success GPG \
efee9553 1306 'git tag -s fails if gpg is misconfigured (bad key)' \
9ffda48f
SG
1307 'test_config user.signingkey BobTheMouse &&
1308 test_must_fail git tag -s -m tail tag-gpg-failure'
aba91192 1309
efee9553
MG
1310# try to produce invalid signature
1311test_expect_success GPG \
1312 'git tag -s fails if gpg is misconfigured (bad signature format)' \
1313 'test_config gpg.program echo &&
1314 test_must_fail git tag -s -m tail tag-gpg-failure'
1315
1316
ef5a6fb5
CR
1317# try to verify without gpg:
1318
1319rm -rf gpghome
a4df22ce 1320test_expect_success GPG \
ef5a6fb5 1321 'verify signed tag fails when public key is not present' \
d592b315 1322 'test_must_fail git tag -v signed-tag'
ef5a6fb5 1323
41ac414e 1324test_expect_success \
d592b315 1325 'git tag -a fails if tag annotation is empty' '
41ac414e 1326 ! (GIT_EDITOR=cat git tag -a initial-comment)
eb9d2b91
MH
1327'
1328
4d8b1dc8
MH
1329test_expect_success \
1330 'message in editor has initial comment' '
5649bd9a
ÆAB
1331 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1332'
1333
b3e1900a 1334test_expect_success 'message in editor has initial comment: first line' '
eb9d2b91 1335 # check the first line --- should be empty
5649bd9a
ÆAB
1336 echo >first.expect &&
1337 sed -e 1q <actual >first.actual &&
b3e1900a 1338 test_i18ncmp first.expect first.actual
5649bd9a
ÆAB
1339'
1340
1341test_expect_success \
1342 'message in editor has initial comment: remainder' '
eb9d2b91 1343 # remove commented lines from the remainder -- should be empty
99094a7a 1344 >rest.expect &&
11f228b0 1345 sed -e 1d -e "/^#/d" <actual >rest.actual &&
5649bd9a 1346 test_cmp rest.expect rest.actual
4d8b1dc8
MH
1347'
1348
1349get_tag_header reuse $commit commit $time >expect
1350echo "An annotation to be reused" >> expect
1351test_expect_success \
1352 'overwriting an annoted tag should use its previous body' '
1353 git tag -a -m "An annotation to be reused" reuse &&
1354 GIT_EDITOR=true git tag -f -a reuse &&
1355 get_tag_msg reuse >actual &&
3af82863 1356 test_cmp expect actual
4d8b1dc8
MH
1357'
1358
dbd0f5c7
JH
1359test_expect_success 'filename for the message is relative to cwd' '
1360 mkdir subdir &&
1361 echo "Tag message in top directory" >msgfile-5 &&
1362 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1363 (
1364 cd subdir &&
1365 git tag -a -F msgfile-5 tag-from-subdir
1366 ) &&
1367 git cat-file tag tag-from-subdir | grep "in sub directory"
1368'
1369
1370test_expect_success 'filename for the message is relative to cwd' '
1371 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1372 (
1373 cd subdir &&
1374 git tag -a -F msgfile-6 tag-from-subdir-2
1375 ) &&
1376 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1377'
1378
32c35cfb
JG
1379# create a few more commits to test --contains
1380
1381hash1=$(git rev-parse HEAD)
1382
1383test_expect_success 'creating second commit and tag' '
1384 echo foo-2.0 >foo &&
1385 git add foo &&
2dec68cf 1386 git commit -m second &&
32c35cfb
JG
1387 git tag v2.0
1388'
1389
1390hash2=$(git rev-parse HEAD)
1391
1392test_expect_success 'creating third commit without tag' '
1393 echo foo-dev >foo &&
1394 git add foo &&
1395 git commit -m third
1396'
1397
1398hash3=$(git rev-parse HEAD)
1399
1400# simple linear checks of --continue
1401
1402cat > expected <<EOF
1403v0.2.1
1404v1.0
1405v1.0.1
1406v1.1.3
1407v2.0
1408EOF
1409
1410test_expect_success 'checking that first commit is in all tags (hash)' "
2dec68cf 1411 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1412 test_cmp expected actual
1413"
1414
1415# other ways of specifying the commit
1416test_expect_success 'checking that first commit is in all tags (tag)' "
2dec68cf 1417 git tag -l --contains v1.0 v* >actual &&
32c35cfb
JG
1418 test_cmp expected actual
1419"
1420
1421test_expect_success 'checking that first commit is in all tags (relative)' "
2dec68cf 1422 git tag -l --contains HEAD~2 v* >actual &&
32c35cfb
JG
1423 test_cmp expected actual
1424"
1425
ac3f5a34
ÆAB
1426# All the --contains tests above, but with --no-contains
1427test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' "
1428 >expected &&
1429 git tag -l --no-contains $hash1 v* >actual &&
1430 test_cmp expected actual
1431"
1432
1433test_expect_success 'checking that first commit is in all tags (tag)' "
1434 git tag -l --no-contains v1.0 v* >actual &&
1435 test_cmp expected actual
1436"
1437
1438test_expect_success 'checking that first commit is in all tags (relative)' "
1439 git tag -l --no-contains HEAD~2 v* >actual &&
1440 test_cmp expected actual
1441"
1442
32c35cfb
JG
1443cat > expected <<EOF
1444v2.0
1445EOF
1446
1447test_expect_success 'checking that second commit only has one tag' "
2dec68cf 1448 git tag -l --contains $hash2 v* >actual &&
32c35cfb
JG
1449 test_cmp expected actual
1450"
1451
ac3f5a34
ÆAB
1452cat > expected <<EOF
1453v0.2.1
1454v1.0
1455v1.0.1
1456v1.1.3
1457EOF
1458
1459test_expect_success 'inverse of the last test, with --no-contains' "
1460 git tag -l --no-contains $hash2 v* >actual &&
1461 test_cmp expected actual
1462"
32c35cfb
JG
1463
1464cat > expected <<EOF
1465EOF
1466
1467test_expect_success 'checking that third commit has no tags' "
2dec68cf 1468 git tag -l --contains $hash3 v* >actual &&
32c35cfb
JG
1469 test_cmp expected actual
1470"
1471
ac3f5a34
ÆAB
1472cat > expected <<EOF
1473v0.2.1
1474v1.0
1475v1.0.1
1476v1.1.3
1477v2.0
1478EOF
1479
1480test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1481 git tag -l --no-contains $hash3 v* >actual &&
1482 test_cmp expected actual
1483"
1484
32c35cfb
JG
1485# how about a simple merge?
1486
1487test_expect_success 'creating simple branch' '
1488 git branch stable v2.0 &&
1489 git checkout stable &&
1490 echo foo-3.0 > foo &&
2dec68cf 1491 git commit foo -m fourth &&
32c35cfb
JG
1492 git tag v3.0
1493'
1494
1495hash4=$(git rev-parse HEAD)
1496
1497cat > expected <<EOF
1498v3.0
1499EOF
1500
1501test_expect_success 'checking that branch head only has one tag' "
2dec68cf 1502 git tag -l --contains $hash4 v* >actual &&
32c35cfb
JG
1503 test_cmp expected actual
1504"
1505
ac3f5a34
ÆAB
1506cat > expected <<EOF
1507v0.2.1
1508v1.0
1509v1.0.1
1510v1.1.3
1511v2.0
1512EOF
1513
1514test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1515 git tag -l --no-contains $hash4 v* >actual &&
1516 test_cmp expected actual
1517"
1518
32c35cfb
JG
1519test_expect_success 'merging original branch into this branch' '
1520 git merge --strategy=ours master &&
1521 git tag v4.0
1522'
1523
1524cat > expected <<EOF
1525v4.0
1526EOF
1527
1528test_expect_success 'checking that original branch head has one tag now' "
2dec68cf 1529 git tag -l --contains $hash3 v* >actual &&
32c35cfb
JG
1530 test_cmp expected actual
1531"
1532
ac3f5a34
ÆAB
1533cat > expected <<EOF
1534v0.2.1
1535v1.0
1536v1.0.1
1537v1.1.3
1538v2.0
1539v3.0
1540EOF
1541
1542test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1543 git tag -l --no-contains $hash3 v* >actual &&
1544 test_cmp expected actual
1545"
1546
32c35cfb
JG
1547cat > expected <<EOF
1548v0.2.1
1549v1.0
1550v1.0.1
1551v1.1.3
1552v2.0
1553v3.0
1554v4.0
1555EOF
1556
1557test_expect_success 'checking that initial commit is in all tags' "
2dec68cf 1558 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1559 test_cmp expected actual
1560"
1561
6a338149
ÆAB
1562test_expect_success 'checking that --contains can be used in non-list mode' '
1563 git tag --contains $hash1 v* >actual &&
1564 test_cmp expected actual
1565'
1566
ac3f5a34
ÆAB
1567test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1568 >expected &&
1569 git tag -l --no-contains $hash1 v* >actual &&
1570 test_cmp expected actual
1571"
1572
e0e03a73
ST
1573# mixing modes and options:
1574
1575test_expect_success 'mixing incompatibles modes and options is forbidden' '
2dec68cf 1576 test_must_fail git tag -a &&
bf748049
ÆAB
1577 test_must_fail git tag -a -l &&
1578 test_must_fail git tag -s &&
1579 test_must_fail git tag -s -l &&
1580 test_must_fail git tag -m &&
1581 test_must_fail git tag -m -l &&
1582 test_must_fail git tag -m "hlagh" &&
1583 test_must_fail git tag -m "hlagh" -l &&
1584 test_must_fail git tag -F &&
1585 test_must_fail git tag -F -l &&
1586 test_must_fail git tag -f &&
1587 test_must_fail git tag -f -l &&
1588 test_must_fail git tag -a -s -m -F &&
1589 test_must_fail git tag -a -s -m -F -l &&
2dec68cf 1590 test_must_fail git tag -l -v &&
bf748049
ÆAB
1591 test_must_fail git tag -l -d &&
1592 test_must_fail git tag -l -v -d &&
bf748049 1593 test_must_fail git tag -n 100 -v &&
2dec68cf
JN
1594 test_must_fail git tag -l -m msg &&
1595 test_must_fail git tag -l -F some file &&
b643827b
ÆAB
1596 test_must_fail git tag -v -s &&
1597 test_must_fail git tag --contains tag-tree &&
ac3f5a34
ÆAB
1598 test_must_fail git tag --contains tag-blob &&
1599 test_must_fail git tag --no-contains tag-tree &&
1600 test_must_fail git tag --no-contains tag-blob &&
75057691
ÆAB
1601 test_must_fail git tag --contains --no-contains &&
1602 test_must_fail git tag --no-with HEAD &&
1603 test_must_fail git tag --no-without HEAD
e0e03a73
ST
1604'
1605
75057691 1606for option in --contains --with --no-contains --without --merged --no-merged --points-at
6a338149
ÆAB
1607do
1608 test_expect_success "mixing incompatible modes with $option is forbidden" "
1609 test_must_fail git tag -d $option HEAD &&
1610 test_must_fail git tag -d $option HEAD some-tag &&
1611 test_must_fail git tag -v $option HEAD
1612 "
1613 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1614 git tag -n $option HEAD HEAD &&
1e0c3b68
ÆAB
1615 git tag $option HEAD HEAD &&
1616 git tag $option
6a338149
ÆAB
1617 "
1618done
e0e03a73 1619
ae7706b9
TG
1620# check points-at
1621
6a338149
ÆAB
1622test_expect_success '--points-at can be used in non-list mode' '
1623 echo v4.0 >expect &&
1624 git tag --points-at=v4.0 "v*" >actual &&
1625 test_cmp expect actual
ae7706b9
TG
1626'
1627
1e0c3b68
ÆAB
1628test_expect_success '--points-at is a synonym for --points-at HEAD' '
1629 echo v4.0 >expect &&
1630 git tag --points-at >actual &&
1631 test_cmp expect actual
ae7706b9
TG
1632'
1633
1634test_expect_success '--points-at finds lightweight tags' '
1635 echo v4.0 >expect &&
1636 git tag --points-at v4.0 >actual &&
1637 test_cmp expect actual
1638'
1639
1640test_expect_success '--points-at finds annotated tags of commits' '
1641 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1642 echo annotated-v4.0 >expect &&
1643 git tag -l --points-at v4.0 "annotated*" >actual &&
1644 test_cmp expect actual
1645'
1646
1647test_expect_success '--points-at finds annotated tags of tags' '
1648 git tag -m "describing the v4.0 tag object" \
1649 annotated-again-v4.0 annotated-v4.0 &&
1650 cat >expect <<-\EOF &&
1651 annotated-again-v4.0
1652 annotated-v4.0
1653 EOF
1654 git tag --points-at=annotated-v4.0 >actual &&
1655 test_cmp expect actual
1656'
1657
1658test_expect_success 'multiple --points-at are OR-ed together' '
1659 cat >expect <<-\EOF &&
1660 v2.0
1661 v3.0
1662 EOF
1663 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1664 test_cmp expect actual
1665'
1666
9ef176b5
NTND
1667test_expect_success 'lexical sort' '
1668 git tag foo1.3 &&
1669 git tag foo1.6 &&
1670 git tag foo1.10 &&
1671 git tag -l --sort=refname "foo*" >actual &&
dc662d44
JK
1672 cat >expect <<-\EOF &&
1673 foo1.10
1674 foo1.3
1675 foo1.6
1676 EOF
9ef176b5
NTND
1677 test_cmp expect actual
1678'
1679
1680test_expect_success 'version sort' '
1681 git tag -l --sort=version:refname "foo*" >actual &&
dc662d44
JK
1682 cat >expect <<-\EOF &&
1683 foo1.3
1684 foo1.6
1685 foo1.10
1686 EOF
9ef176b5
NTND
1687 test_cmp expect actual
1688'
1689
1690test_expect_success 'reverse version sort' '
1691 git tag -l --sort=-version:refname "foo*" >actual &&
dc662d44
JK
1692 cat >expect <<-\EOF &&
1693 foo1.10
1694 foo1.6
1695 foo1.3
1696 EOF
9ef176b5
NTND
1697 test_cmp expect actual
1698'
1699
1700test_expect_success 'reverse lexical sort' '
1701 git tag -l --sort=-refname "foo*" >actual &&
dc662d44
JK
1702 cat >expect <<-\EOF &&
1703 foo1.6
1704 foo1.3
1705 foo1.10
1706 EOF
9ef176b5
NTND
1707 test_cmp expect actual
1708'
1709
b150794d 1710test_expect_success 'configured lexical sort' '
9ffda48f 1711 test_config tag.sort "v:refname" &&
b150794d
JK
1712 git tag -l "foo*" >actual &&
1713 cat >expect <<-\EOF &&
1714 foo1.3
1715 foo1.6
1716 foo1.10
1717 EOF
1718 test_cmp expect actual
1719'
1720
1721test_expect_success 'option override configured sort' '
9ffda48f 1722 test_config tag.sort "v:refname" &&
b150794d
JK
1723 git tag -l --sort=-refname "foo*" >actual &&
1724 cat >expect <<-\EOF &&
1725 foo1.6
1726 foo1.3
1727 foo1.10
1728 EOF
1729 test_cmp expect actual
1730'
1731
1732test_expect_success 'invalid sort parameter on command line' '
1733 test_must_fail git tag -l --sort=notvalid "foo*" >actual
1734'
1735
1736test_expect_success 'invalid sort parameter in configuratoin' '
9ffda48f 1737 test_config tag.sort "v:notvalid" &&
b7cc53e9 1738 test_must_fail git tag -l "foo*"
b150794d
JK
1739'
1740
d811c8e1 1741test_expect_success 'version sort with prerelease reordering' '
9ffda48f 1742 test_config versionsort.prereleaseSuffix -rc &&
d811c8e1
NTND
1743 git tag foo1.6-rc1 &&
1744 git tag foo1.6-rc2 &&
1745 git tag -l --sort=version:refname "foo*" >actual &&
1746 cat >expect <<-\EOF &&
1747 foo1.3
1748 foo1.6-rc1
1749 foo1.6-rc2
1750 foo1.6
1751 foo1.10
1752 EOF
1753 test_cmp expect actual
1754'
1755
1756test_expect_success 'reverse version sort with prerelease reordering' '
9ffda48f 1757 test_config versionsort.prereleaseSuffix -rc &&
d811c8e1
NTND
1758 git tag -l --sort=-version:refname "foo*" >actual &&
1759 cat >expect <<-\EOF &&
1760 foo1.10
1761 foo1.6
1762 foo1.6-rc2
1763 foo1.6-rc1
1764 foo1.3
1765 EOF
1766 test_cmp expect actual
1767'
1768
b8231660 1769test_expect_success 'version sort with prerelease reordering and common leading character' '
0c1b4878
SG
1770 test_config versionsort.prereleaseSuffix -before &&
1771 git tag foo1.7-before1 &&
1772 git tag foo1.7 &&
1773 git tag foo1.7-after1 &&
1774 git tag -l --sort=version:refname "foo1.7*" >actual &&
1775 cat >expect <<-\EOF &&
1776 foo1.7-before1
1777 foo1.7
1778 foo1.7-after1
1779 EOF
1780 test_cmp expect actual
1781'
1782
b8231660 1783test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
0c1b4878
SG
1784 test_config versionsort.prereleaseSuffix -before &&
1785 git config --add versionsort.prereleaseSuffix -after &&
1786 git tag -l --sort=version:refname "foo1.7*" >actual &&
1787 cat >expect <<-\EOF &&
1788 foo1.7-before1
1789 foo1.7-after1
1790 foo1.7
1791 EOF
1792 test_cmp expect actual
1793'
1794
51acfa9d
SG
1795test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1796 test_config versionsort.prereleaseSuffix -bar &&
1797 git config --add versionsort.prereleaseSuffix -foo-baz &&
1798 git config --add versionsort.prereleaseSuffix -foo-bar &&
1799 git tag foo1.8-foo-bar &&
1800 git tag foo1.8-foo-baz &&
1801 git tag foo1.8 &&
1802 git tag -l --sort=version:refname "foo1.8*" >actual &&
1803 cat >expect <<-\EOF &&
1804 foo1.8-foo-baz
1805 foo1.8-foo-bar
1806 foo1.8
1807 EOF
1808 test_cmp expect actual
1809'
1810
1811test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1812 test_config versionsort.prereleaseSuffix -pre &&
1813 git config --add versionsort.prereleaseSuffix -prerelease &&
1814 git tag foo1.9-pre1 &&
1815 git tag foo1.9-pre2 &&
1816 git tag foo1.9-prerelease1 &&
1817 git tag -l --sort=version:refname "foo1.9*" >actual &&
1818 cat >expect <<-\EOF &&
1819 foo1.9-pre1
1820 foo1.9-pre2
1821 foo1.9-prerelease1
1822 EOF
1823 test_cmp expect actual
1824'
1825
c026557a
SG
1826test_expect_success 'version sort with general suffix reordering' '
1827 test_config versionsort.suffix -alpha &&
1828 git config --add versionsort.suffix -beta &&
1829 git config --add versionsort.suffix "" &&
1830 git config --add versionsort.suffix -gamma &&
1831 git config --add versionsort.suffix -delta &&
1832 git tag foo1.10-alpha &&
1833 git tag foo1.10-beta &&
1834 git tag foo1.10-gamma &&
1835 git tag foo1.10-delta &&
1836 git tag foo1.10-unlisted-suffix &&
1837 git tag -l --sort=version:refname "foo1.10*" >actual &&
1838 cat >expect <<-\EOF &&
1839 foo1.10-alpha
1840 foo1.10-beta
1841 foo1.10
1842 foo1.10-unlisted-suffix
1843 foo1.10-gamma
1844 foo1.10-delta
1845 EOF
1846 test_cmp expect actual
1847'
1848
1849test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1850 test_config versionsort.suffix -before &&
1851 test_config versionsort.prereleaseSuffix -after &&
1852 git tag -l --sort=version:refname "foo1.7*" >actual &&
1853 cat >expect <<-\EOF &&
1854 foo1.7-before1
1855 foo1.7
1856 foo1.7-after1
1857 EOF
1858 test_cmp expect actual
1859'
1860
b8231660
SG
1861test_expect_success 'version sort with very long prerelease suffix' '
1862 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1863 git tag -l --sort=version:refname
1864'
1865
cbc60b67 1866run_with_limited_stack () {
b9a19078 1867 (ulimit -s 128 && "$@")
cbc60b67
JJL
1868}
1869
fc38a9bb 1870test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
cbc60b67
JJL
1871
1872# we require ulimit, this excludes Windows
ac3f5a34 1873test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
cbc60b67
JJL
1874 >expect &&
1875 i=1 &&
b9a19078 1876 while test $i -lt 8000
cbc60b67
JJL
1877 do
1878 echo "commit refs/heads/master
1879committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1880data <<EOF
1881commit #$i
1882EOF"
1883 test $i = 1 && echo "from refs/heads/master^0"
1884 i=$(($i + 1))
1885 done | git fast-import &&
1886 git checkout master &&
1887 git tag far-far-away HEAD^ &&
1888 run_with_limited_stack git tag --contains HEAD >actual &&
ac3f5a34
ÆAB
1889 test_cmp expect actual &&
1890 run_with_limited_stack git tag --no-contains HEAD >actual &&
1891 test_line_count ">" 10 actual
cbc60b67
JJL
1892'
1893
df094741
KN
1894test_expect_success '--format should list tags as per format given' '
1895 cat >expect <<-\EOF &&
0c1b4878
SG
1896 refname : refs/tags/v1.0
1897 refname : refs/tags/v1.0.1
1898 refname : refs/tags/v1.1.3
df094741 1899 EOF
0c1b4878 1900 git tag -l --format="refname : %(refname)" "v1*" >actual &&
df094741
KN
1901 test_cmp expect actual
1902'
1903
11b087ad
JK
1904test_expect_success "set up color tests" '
1905 echo "<RED>v1.0<RESET>" >expect.color &&
1906 echo "v1.0" >expect.bare &&
1907 color_args="--format=%(color:red)%(refname:short) --list v1.0"
1908'
1909
1910test_expect_success '%(color) omitted without tty' '
1911 TERM=vt100 git tag $color_args >actual.raw &&
1912 test_decode_color <actual.raw >actual &&
1913 test_cmp expect.bare actual
1914'
1915
1916test_expect_success TTY '%(color) present with tty' '
e433749d 1917 test_terminal git tag $color_args >actual.raw &&
11b087ad
JK
1918 test_decode_color <actual.raw >actual &&
1919 test_cmp expect.color actual
1920'
1921
1922test_expect_success 'color.ui=always overrides auto-color' '
1923 git -c color.ui=always tag $color_args >actual.raw &&
1924 test_decode_color <actual.raw >actual &&
1925 test_cmp expect.color actual
1926'
1927
5242860f
KN
1928test_expect_success 'setup --merged test tags' '
1929 git tag mergetest-1 HEAD~2 &&
1930 git tag mergetest-2 HEAD~1 &&
1931 git tag mergetest-3 HEAD
1932'
1933
6a338149
ÆAB
1934test_expect_success '--merged can be used in non-list mode' '
1935 cat >expect <<-\EOF &&
1936 mergetest-1
1937 mergetest-2
1938 EOF
1939 git tag --merged=mergetest-2 "mergetest*" >actual &&
1940 test_cmp expect actual
5242860f
KN
1941'
1942
17d6c744
ÆAB
1943test_expect_success '--merged is incompatible with --no-merged' '
1944 test_must_fail git tag --merged HEAD --no-merged HEAD
5242860f
KN
1945'
1946
1947test_expect_success '--merged shows merged tags' '
1948 cat >expect <<-\EOF &&
1949 mergetest-1
1950 mergetest-2
1951 EOF
1952 git tag -l --merged=mergetest-2 mergetest-* >actual &&
1953 test_cmp expect actual
1954'
1955
1956test_expect_success '--no-merged show unmerged tags' '
1957 cat >expect <<-\EOF &&
1958 mergetest-3
1959 EOF
1960 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
1961 test_cmp expect actual
1962'
1963
6a338149
ÆAB
1964test_expect_success '--no-merged can be used in non-list mode' '
1965 git tag --no-merged=mergetest-2 mergetest-* >actual &&
1966 test_cmp expect actual
1967'
1968
0571979b
JK
1969test_expect_success 'ambiguous branch/tags not marked' '
1970 git tag ambiguous &&
1971 git branch ambiguous &&
1972 echo ambiguous >expect &&
1973 git tag -l ambiguous >actual &&
1974 test_cmp expect actual
1975'
1976
ac3f5a34
ÆAB
1977test_expect_success '--contains combined with --no-contains' '
1978 (
1979 git init no-contains &&
1980 cd no-contains &&
1981 test_commit v0.1 &&
1982 test_commit v0.2 &&
1983 test_commit v0.3 &&
1984 test_commit v0.4 &&
1985 test_commit v0.5 &&
1986 cat >expected <<-\EOF &&
1987 v0.2
1988 v0.3
1989 v0.4
1990 EOF
1991 git tag --contains v0.2 --no-contains v0.5 >actual &&
1992 test_cmp expected actual
1993 )
1994'
1995
1996# As the docs say, list tags which contain a specified *commit*. We
1997# don't recurse down to tags for trees or blobs pointed to by *those*
1998# commits.
1999test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2000 cd no-contains &&
2001 blob=$(git rev-parse v0.3:v0.3.t) &&
2002 tree=$(git rev-parse v0.3^{tree}) &&
2003 git tag tag-blob $blob &&
2004 git tag tag-tree $tree &&
2005 git tag --contains v0.3 >actual &&
2006 cat >expected <<-\EOF &&
2007 v0.3
2008 v0.4
2009 v0.5
2010 EOF
2011 test_cmp expected actual &&
2012 git tag --no-contains v0.3 >actual &&
2013 cat >expected <<-\EOF &&
2014 v0.1
2015 v0.2
2016 EOF
2017 test_cmp expected actual
2018'
2019
ef5a6fb5 2020test_done