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