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