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