]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7004-tag.sh
Merge branch 'jk/pickaxe-textconv' into maint
[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' '
d592b315
NS
26 test `git tag -l | wc -l` -eq 0 &&
27 test `git tag | wc -l` -eq 0
62e09ce9 28'
ef5a6fb5 29
41ac414e
JH
30test_expect_success 'looking for a tag in an empty tree should fail' \
31 '! (tag_exists mytag)'
ef5a6fb5
CR
32
33test_expect_success 'creating a tag in an empty tree should fail' '
d592b315 34 test_must_fail git tag mynotag &&
ef5a6fb5
CR
35 ! tag_exists mynotag
36'
37
38test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
d592b315 39 test_must_fail git tag mytaghead HEAD &&
ef5a6fb5
CR
40 ! tag_exists mytaghead
41'
42
43test_expect_success 'creating a tag for an unknown revision should fail' '
d592b315 44 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
ef5a6fb5
CR
45 ! tag_exists mytagnorev
46'
47
48# commit used in the tests, test_tick is also called here to freeze the date:
49test_expect_success 'creating a tag using default HEAD should succeed' '
50 test_tick &&
51 echo foo >foo &&
52 git add foo &&
53 git commit -m Foo &&
54 git tag mytag
55'
56
62e09ce9 57test_expect_success 'listing all tags if one exists should succeed' '
d592b315
NS
58 git tag -l &&
59 git tag
62e09ce9 60'
ef5a6fb5 61
62e09ce9 62test_expect_success 'listing all tags if one exists should output that tag' '
d592b315
NS
63 test `git tag -l` = mytag &&
64 test `git tag` = mytag
62e09ce9 65'
ef5a6fb5
CR
66
67# pattern matching:
68
69test_expect_success 'listing a tag using a matching pattern should succeed' \
d592b315 70 'git tag -l mytag'
ef5a6fb5
CR
71
72test_expect_success \
73 'listing a tag using a matching pattern should output that tag' \
d592b315 74 'test `git tag -l mytag` = mytag'
ef5a6fb5
CR
75
76# todo: git tag -l now returns always zero, when fixed, change this test
77test_expect_success \
78 'listing tags using a non-matching pattern should suceed' \
d592b315 79 'git tag -l xxx'
ef5a6fb5
CR
80
81test_expect_success \
82 'listing tags using a non-matching pattern should output nothing' \
d592b315 83 'test `git tag -l xxx | wc -l` -eq 0'
ef5a6fb5
CR
84
85# special cases for creating tags:
86
41ac414e 87test_expect_success \
ef5a6fb5 88 'trying to create a tag with the name of one existing should fail' \
d492b31c 89 'test_must_fail git tag mytag'
ef5a6fb5
CR
90
91test_expect_success \
92 'trying to create a tag with a non-valid name should fail' '
d592b315 93 test `git tag -l | wc -l` -eq 1 &&
d492b31c
SB
94 test_must_fail git tag "" &&
95 test_must_fail git tag .othertag &&
96 test_must_fail git tag "other tag" &&
97 test_must_fail git tag "othertag^" &&
98 test_must_fail git tag "other~tag" &&
d592b315 99 test `git tag -l | wc -l` -eq 1
ef5a6fb5
CR
100'
101
102test_expect_success 'creating a tag using HEAD directly should succeed' '
103 git tag myhead HEAD &&
104 tag_exists myhead
105'
106
107# deleting tags:
108
109test_expect_success 'trying to delete an unknown tag should fail' '
110 ! tag_exists unknown-tag &&
d592b315 111 test_must_fail git tag -d unknown-tag
ef5a6fb5
CR
112'
113
114cat >expect <<EOF
115myhead
116mytag
117EOF
118test_expect_success \
119 'trying to delete tags without params should succeed and do nothing' '
3af82863 120 git tag -l > actual && test_cmp expect actual &&
d592b315 121 git tag -d &&
3af82863 122 git tag -l > actual && test_cmp expect actual
ef5a6fb5
CR
123'
124
125test_expect_success \
126 'deleting two existing tags in one command should succeed' '
127 tag_exists mytag &&
128 tag_exists myhead &&
d592b315 129 git tag -d mytag myhead &&
ef5a6fb5
CR
130 ! tag_exists mytag &&
131 ! tag_exists myhead
132'
133
134test_expect_success \
135 'creating a tag with the name of another deleted one should succeed' '
136 ! tag_exists mytag &&
d592b315 137 git tag mytag &&
ef5a6fb5
CR
138 tag_exists mytag
139'
140
141test_expect_success \
142 'trying to delete two tags, existing and not, should fail in the 2nd' '
143 tag_exists mytag &&
144 ! tag_exists myhead &&
d592b315 145 test_must_fail git tag -d mytag anothertag &&
ef5a6fb5
CR
146 ! tag_exists mytag &&
147 ! tag_exists myhead
148'
149
41ac414e 150test_expect_success 'trying to delete an already deleted tag should fail' \
d592b315 151 'test_must_fail git tag -d mytag'
ef5a6fb5
CR
152
153# listing various tags with pattern matching:
154
155cat >expect <<EOF
156a1
157aa1
158cba
159t210
160t211
161v0.2.1
162v1.0
163v1.0.1
164v1.1.3
165EOF
166test_expect_success 'listing all tags should print them ordered' '
167 git tag v1.0.1 &&
168 git tag t211 &&
169 git tag aa1 &&
170 git tag v0.2.1 &&
171 git tag v1.1.3 &&
172 git tag cba &&
173 git tag a1 &&
174 git tag v1.0 &&
175 git tag t210 &&
5206d130 176 git tag -l > actual &&
3af82863 177 test_cmp expect actual &&
62e09ce9 178 git tag > actual &&
3af82863 179 test_cmp expect actual
ef5a6fb5
CR
180'
181
182cat >expect <<EOF
183a1
184aa1
185cba
186EOF
187test_expect_success \
188 'listing tags with substring as pattern must print those matching' '
0aaaef7b
JS
189 rm *a* &&
190 git tag -l "*a*" > current &&
191 test_cmp expect current
ef5a6fb5
CR
192'
193
194cat >expect <<EOF
195v0.2.1
196v1.0.1
ef5a6fb5
CR
197EOF
198test_expect_success \
18e32b5b 199 'listing tags with a suffix as pattern must print those matching' '
d592b315 200 git tag -l "*.1" > actual &&
3af82863 201 test_cmp expect actual
ef5a6fb5
CR
202'
203
204cat >expect <<EOF
205t210
206t211
207EOF
208test_expect_success \
18e32b5b 209 'listing tags with a prefix as pattern must print those matching' '
d592b315 210 git tag -l "t21*" > actual &&
3af82863 211 test_cmp expect actual
ef5a6fb5
CR
212'
213
214cat >expect <<EOF
215a1
ef5a6fb5
CR
216EOF
217test_expect_success \
18e32b5b 218 'listing tags using a name as pattern must print that one matching' '
d592b315 219 git tag -l a1 > actual &&
3af82863 220 test_cmp expect actual
ef5a6fb5
CR
221'
222
223cat >expect <<EOF
224v1.0
ef5a6fb5
CR
225EOF
226test_expect_success \
18e32b5b 227 'listing tags using a name as pattern must print that one matching' '
d592b315 228 git tag -l v1.0 > actual &&
3af82863 229 test_cmp expect actual
ef5a6fb5
CR
230'
231
232cat >expect <<EOF
18e32b5b 233v1.0.1
ef5a6fb5
CR
234v1.1.3
235EOF
236test_expect_success \
237 'listing tags with ? in the pattern should print those matching' '
d592b315 238 git tag -l "v1.?.?" > actual &&
3af82863 239 test_cmp expect actual
ef5a6fb5
CR
240'
241
242>expect
243test_expect_success \
244 'listing tags using v.* should print nothing because none have v.' '
d592b315 245 git tag -l "v.*" > actual &&
3af82863 246 test_cmp expect actual
ef5a6fb5
CR
247'
248
249cat >expect <<EOF
250v0.2.1
251v1.0
252v1.0.1
253v1.1.3
254EOF
255test_expect_success \
256 'listing tags using v* should print only those having v' '
d592b315 257 git tag -l "v*" > actual &&
3af82863 258 test_cmp expect actual
ef5a6fb5
CR
259'
260
588d0e83
JK
261test_expect_success 'tag -l can accept multiple patterns' '
262 git tag -l "v1*" "v0*" >actual &&
263 test_cmp expect actual
264'
265
d96e3c15
NTND
266test_expect_success 'listing tags in column' '
267 COLUMNS=40 git tag -l --column=row >actual &&
268 cat >expected <<\EOF &&
269a1 aa1 cba t210 t211
270v0.2.1 v1.0 v1.0.1 v1.1.3
271EOF
272 test_cmp expected actual
273'
274
275test_expect_success 'listing tags in column with column.*' '
276 git config column.tag row &&
277 git config column.ui dense &&
278 COLUMNS=40 git tag -l >actual &&
279 git config --unset column.ui &&
280 git config --unset column.tag &&
281 cat >expected <<\EOF &&
282a1 aa1 cba t210 t211
283v0.2.1 v1.0 v1.0.1 v1.1.3
284EOF
285 test_cmp expected actual
286'
287
288test_expect_success 'listing tag with -n --column should fail' '
289 test_must_fail git tag --column -n
290'
291
292test_expect_success 'listing tags -n in column with column.ui ignored' '
293 git config column.ui "row dense" &&
294 COLUMNS=40 git tag -l -n >actual &&
295 git config --unset column.ui &&
296 cat >expected <<\EOF &&
297a1 Foo
298aa1 Foo
299cba Foo
300t210 Foo
301t211 Foo
302v0.2.1 Foo
303v1.0 Foo
304v1.0.1 Foo
305v1.1.3 Foo
306EOF
307 test_cmp expected actual
308'
309
ef5a6fb5
CR
310# creating and verifying lightweight tags:
311
312test_expect_success \
313 'a non-annotated tag created without parameters should point to HEAD' '
d592b315 314 git tag non-annotated-tag &&
5be60078
JH
315 test $(git cat-file -t non-annotated-tag) = commit &&
316 test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
ef5a6fb5
CR
317'
318
41ac414e 319test_expect_success 'trying to verify an unknown tag should fail' \
d592b315 320 'test_must_fail git tag -v unknown-tag'
ef5a6fb5 321
41ac414e 322test_expect_success \
ef5a6fb5 323 'trying to verify a non-annotated and non-signed tag should fail' \
d592b315 324 'test_must_fail git tag -v non-annotated-tag'
ef5a6fb5 325
41ac414e 326test_expect_success \
62e09ce9 327 'trying to verify many non-annotated or unknown tags, should fail' \
d592b315 328 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
62e09ce9 329
ef5a6fb5
CR
330# creating annotated tags:
331
332get_tag_msg () {
333 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
334}
335
336# run test_tick before committing always gives the time in that timezone
337get_tag_header () {
338cat <<EOF
339object $2
340type $3
341tag $1
342tagger C O Mitter <committer@example.com> $4 -0700
343
344EOF
345}
346
347commit=$(git rev-parse HEAD)
348time=$test_tick
349
350get_tag_header annotated-tag $commit commit $time >expect
351echo "A message" >>expect
352test_expect_success \
353 'creating an annotated tag with -m message should succeed' '
d592b315 354 git tag -m "A message" annotated-tag &&
ef5a6fb5 355 get_tag_msg annotated-tag >actual &&
3af82863 356 test_cmp expect actual
ef5a6fb5
CR
357'
358
359cat >msgfile <<EOF
360Another message
361in a file.
362EOF
363get_tag_header file-annotated-tag $commit commit $time >expect
364cat msgfile >>expect
365test_expect_success \
366 'creating an annotated tag with -F messagefile should succeed' '
d592b315 367 git tag -F msgfile file-annotated-tag &&
ef5a6fb5 368 get_tag_msg file-annotated-tag >actual &&
3af82863 369 test_cmp expect actual
ef5a6fb5
CR
370'
371
62e09ce9
CR
372cat >inputmsg <<EOF
373A message from the
374standard input
375EOF
376get_tag_header stdin-annotated-tag $commit commit $time >expect
377cat inputmsg >>expect
378test_expect_success 'creating an annotated tag with -F - should succeed' '
d592b315 379 git tag -F - stdin-annotated-tag <inputmsg &&
62e09ce9 380 get_tag_msg stdin-annotated-tag >actual &&
3af82863 381 test_cmp expect actual
62e09ce9
CR
382'
383
e317cfaf
CR
384test_expect_success \
385 'trying to create a tag with a non-existing -F file should fail' '
386 ! test -f nonexistingfile &&
387 ! tag_exists notag &&
d592b315 388 test_must_fail git tag -F nonexistingfile notag &&
e317cfaf
CR
389 ! tag_exists notag
390'
391
392test_expect_success \
39686585 393 'trying to create tags giving both -m or -F options should fail' '
e317cfaf
CR
394 echo "message file 1" >msgfile1 &&
395 echo "message file 2" >msgfile2 &&
396 ! tag_exists msgtag &&
d592b315 397 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
e317cfaf 398 ! tag_exists msgtag &&
d592b315 399 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
e317cfaf 400 ! tag_exists msgtag &&
d592b315 401 test_must_fail git tag -m "message 1" -F msgfile1 \
d492b31c 402 -m "message 2" msgtag &&
e317cfaf
CR
403 ! tag_exists msgtag
404'
405
ef5a6fb5
CR
406# blank and empty messages:
407
408get_tag_header empty-annotated-tag $commit commit $time >expect
409test_expect_success \
410 'creating a tag with an empty -m message should succeed' '
d592b315 411 git tag -m "" empty-annotated-tag &&
ef5a6fb5 412 get_tag_msg empty-annotated-tag >actual &&
3af82863 413 test_cmp expect actual
ef5a6fb5
CR
414'
415
416>emptyfile
417get_tag_header emptyfile-annotated-tag $commit commit $time >expect
418test_expect_success \
419 'creating a tag with an empty -F messagefile should succeed' '
d592b315 420 git tag -F emptyfile emptyfile-annotated-tag &&
ef5a6fb5 421 get_tag_msg emptyfile-annotated-tag >actual &&
3af82863 422 test_cmp expect actual
ef5a6fb5
CR
423'
424
425printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
426printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
427printf '\n\n\nTrailing spaces \t \n' >>blanksfile
428printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
429get_tag_header blanks-annotated-tag $commit commit $time >expect
430cat >>expect <<EOF
431Leading blank lines
432
433Repeated blank lines
434
435Trailing spaces
436
437Trailing blank lines
438EOF
439test_expect_success \
440 'extra blanks in the message for an annotated tag should be removed' '
d592b315 441 git tag -F blanksfile blanks-annotated-tag &&
ef5a6fb5 442 get_tag_msg blanks-annotated-tag >actual &&
3af82863 443 test_cmp expect actual
ef5a6fb5
CR
444'
445
446get_tag_header blank-annotated-tag $commit commit $time >expect
447test_expect_success \
448 'creating a tag with blank -m message with spaces should succeed' '
d592b315 449 git tag -m " " blank-annotated-tag &&
ef5a6fb5 450 get_tag_msg blank-annotated-tag >actual &&
3af82863 451 test_cmp expect actual
ef5a6fb5
CR
452'
453
454echo ' ' >blankfile
455echo '' >>blankfile
456echo ' ' >>blankfile
457get_tag_header blankfile-annotated-tag $commit commit $time >expect
458test_expect_success \
459 'creating a tag with blank -F messagefile with spaces should succeed' '
d592b315 460 git tag -F blankfile blankfile-annotated-tag &&
ef5a6fb5 461 get_tag_msg blankfile-annotated-tag >actual &&
3af82863 462 test_cmp expect actual
ef5a6fb5
CR
463'
464
465printf ' ' >blanknonlfile
466get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
467test_expect_success \
468 'creating a tag with -F file of spaces and no newline should succeed' '
d592b315 469 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
ef5a6fb5 470 get_tag_msg blanknonlfile-annotated-tag >actual &&
3af82863 471 test_cmp expect actual
ef5a6fb5
CR
472'
473
474# messages with commented lines:
475
476cat >commentsfile <<EOF
477# A comment
478
479############
480The message.
481############
482One line.
483
484
485# commented lines
486# commented lines
487
488Another line.
489# comments
490
491Last line.
492EOF
493get_tag_header comments-annotated-tag $commit commit $time >expect
494cat >>expect <<EOF
495The message.
496One line.
497
498Another line.
499
500Last line.
501EOF
502test_expect_success \
503 'creating a tag using a -F messagefile with #comments should succeed' '
d592b315 504 git tag -F commentsfile comments-annotated-tag &&
ef5a6fb5 505 get_tag_msg comments-annotated-tag >actual &&
3af82863 506 test_cmp expect actual
ef5a6fb5
CR
507'
508
509get_tag_header comment-annotated-tag $commit commit $time >expect
510test_expect_success \
511 'creating a tag with a #comment in the -m message should succeed' '
d592b315 512 git tag -m "#comment" comment-annotated-tag &&
ef5a6fb5 513 get_tag_msg comment-annotated-tag >actual &&
3af82863 514 test_cmp expect actual
ef5a6fb5
CR
515'
516
517echo '#comment' >commentfile
518echo '' >>commentfile
519echo '####' >>commentfile
520get_tag_header commentfile-annotated-tag $commit commit $time >expect
521test_expect_success \
522 'creating a tag with #comments in the -F messagefile should succeed' '
d592b315 523 git tag -F commentfile commentfile-annotated-tag &&
ef5a6fb5 524 get_tag_msg commentfile-annotated-tag >actual &&
3af82863 525 test_cmp expect actual
ef5a6fb5
CR
526'
527
528printf '#comment' >commentnonlfile
529get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
530test_expect_success \
531 'creating a tag with a file of #comment and no newline should succeed' '
d592b315 532 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
ef5a6fb5 533 get_tag_msg commentnonlfile-annotated-tag >actual &&
3af82863 534 test_cmp expect actual
ef5a6fb5
CR
535'
536
5206d130
CR
537# listing messages for annotated non-signed tags:
538
539test_expect_success \
540 'listing the one-line message of a non-signed tag should succeed' '
d592b315 541 git tag -m "A msg" tag-one-line &&
5206d130
CR
542
543 echo "tag-one-line" >expect &&
d592b315 544 git tag -l | grep "^tag-one-line" >actual &&
3af82863 545 test_cmp expect actual &&
d592b315 546 git tag -n0 -l | grep "^tag-one-line" >actual &&
3af82863 547 test_cmp expect actual &&
d592b315 548 git tag -n0 -l tag-one-line >actual &&
3af82863 549 test_cmp expect actual &&
5206d130
CR
550
551 echo "tag-one-line A msg" >expect &&
d592b315 552 git tag -n1 -l | grep "^tag-one-line" >actual &&
3af82863 553 test_cmp expect actual &&
d592b315 554 git tag -n -l | grep "^tag-one-line" >actual &&
3af82863 555 test_cmp expect actual &&
d592b315 556 git tag -n1 -l tag-one-line >actual &&
3af82863 557 test_cmp expect actual &&
d592b315 558 git tag -n2 -l tag-one-line >actual &&
3af82863 559 test_cmp expect actual &&
d592b315 560 git tag -n999 -l tag-one-line >actual &&
3af82863 561 test_cmp expect actual
5206d130
CR
562'
563
564test_expect_success \
565 'listing the zero-lines message of a non-signed tag should succeed' '
d592b315 566 git tag -m "" tag-zero-lines &&
5206d130
CR
567
568 echo "tag-zero-lines" >expect &&
d592b315 569 git tag -l | grep "^tag-zero-lines" >actual &&
3af82863 570 test_cmp expect actual &&
d592b315 571 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
3af82863 572 test_cmp expect actual &&
d592b315 573 git tag -n0 -l tag-zero-lines >actual &&
3af82863 574 test_cmp expect actual &&
5206d130
CR
575
576 echo "tag-zero-lines " >expect &&
d592b315 577 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
3af82863 578 test_cmp expect actual &&
d592b315 579 git tag -n -l | grep "^tag-zero-lines" >actual &&
3af82863 580 test_cmp expect actual &&
d592b315 581 git tag -n1 -l tag-zero-lines >actual &&
3af82863 582 test_cmp expect actual &&
d592b315 583 git tag -n2 -l tag-zero-lines >actual &&
3af82863 584 test_cmp expect actual &&
d592b315 585 git tag -n999 -l tag-zero-lines >actual &&
3af82863 586 test_cmp expect actual
5206d130
CR
587'
588
589echo 'tag line one' >annotagmsg
590echo 'tag line two' >>annotagmsg
591echo 'tag line three' >>annotagmsg
592test_expect_success \
593 'listing many message lines of a non-signed tag should succeed' '
d592b315 594 git tag -F annotagmsg tag-lines &&
5206d130
CR
595
596 echo "tag-lines" >expect &&
d592b315 597 git tag -l | grep "^tag-lines" >actual &&
3af82863 598 test_cmp expect actual &&
d592b315 599 git tag -n0 -l | grep "^tag-lines" >actual &&
3af82863 600 test_cmp expect actual &&
d592b315 601 git tag -n0 -l tag-lines >actual &&
3af82863 602 test_cmp expect actual &&
5206d130
CR
603
604 echo "tag-lines tag line one" >expect &&
d592b315 605 git tag -n1 -l | grep "^tag-lines" >actual &&
3af82863 606 test_cmp expect actual &&
d592b315 607 git tag -n -l | grep "^tag-lines" >actual &&
3af82863 608 test_cmp expect actual &&
d592b315 609 git tag -n1 -l tag-lines >actual &&
3af82863 610 test_cmp expect actual &&
5206d130
CR
611
612 echo " tag line two" >>expect &&
d592b315 613 git tag -n2 -l | grep "^ *tag.line" >actual &&
3af82863 614 test_cmp expect actual &&
d592b315 615 git tag -n2 -l tag-lines >actual &&
3af82863 616 test_cmp expect actual &&
5206d130
CR
617
618 echo " tag line three" >>expect &&
d592b315 619 git tag -n3 -l | grep "^ *tag.line" >actual &&
3af82863 620 test_cmp expect actual &&
d592b315 621 git tag -n3 -l tag-lines >actual &&
3af82863 622 test_cmp expect actual &&
d592b315 623 git tag -n4 -l | grep "^ *tag.line" >actual &&
3af82863 624 test_cmp expect actual &&
d592b315 625 git tag -n4 -l tag-lines >actual &&
3af82863 626 test_cmp expect actual &&
d592b315 627 git tag -n99 -l | grep "^ *tag.line" >actual &&
3af82863 628 test_cmp expect actual &&
d592b315 629 git tag -n99 -l tag-lines >actual &&
3af82863 630 test_cmp expect actual
5206d130
CR
631'
632
31fd8d72
JH
633test_expect_success 'annotations for blobs are empty' '
634 blob=$(git hash-object -w --stdin <<-\EOF
635 Blob paragraph 1.
636
637 Blob paragraph 2.
638 EOF
639 ) &&
640 git tag tag-blob $blob &&
641 echo "tag-blob " >expect &&
642 git tag -n1 -l tag-blob >actual &&
643 test_cmp expect actual
644'
645
ef5a6fb5
CR
646# trying to verify annotated non-signed tags:
647
a4df22ce 648test_expect_success GPG \
ef5a6fb5
CR
649 'trying to verify an annotated non-signed tag should fail' '
650 tag_exists annotated-tag &&
d592b315 651 test_must_fail git tag -v annotated-tag
ef5a6fb5
CR
652'
653
a4df22ce 654test_expect_success GPG \
ef5a6fb5
CR
655 'trying to verify a file-annotated non-signed tag should fail' '
656 tag_exists file-annotated-tag &&
d592b315 657 test_must_fail git tag -v file-annotated-tag
ef5a6fb5
CR
658'
659
a4df22ce 660test_expect_success GPG \
62e09ce9
CR
661 'trying to verify two annotated non-signed tags should fail' '
662 tag_exists annotated-tag file-annotated-tag &&
d592b315 663 test_must_fail git tag -v annotated-tag file-annotated-tag
62e09ce9
CR
664'
665
ef5a6fb5
CR
666# creating and verifying signed tags:
667
ef5a6fb5
CR
668get_tag_header signed-tag $commit commit $time >expect
669echo 'A signed tag message' >>expect
670echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 671test_expect_success GPG 'creating a signed tag with -m message should succeed' '
d592b315 672 git tag -s -m "A signed tag message" signed-tag &&
ef5a6fb5 673 get_tag_msg signed-tag >actual &&
3af82863 674 test_cmp expect actual
ef5a6fb5
CR
675'
676
be15f505
LT
677get_tag_header u-signed-tag $commit commit $time >expect
678echo 'Another message' >>expect
679echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 680test_expect_success GPG 'sign with a given key id' '
be15f505
LT
681
682 git tag -u committer@example.com -m "Another message" u-signed-tag &&
683 get_tag_msg u-signed-tag >actual &&
3af82863 684 test_cmp expect actual
be15f505
LT
685
686'
687
a4df22ce 688test_expect_success GPG 'sign with an unknown id (1)' '
be15f505 689
d492b31c
SB
690 test_must_fail git tag -u author@example.com \
691 -m "Another message" o-signed-tag
be15f505
LT
692
693'
694
a4df22ce 695test_expect_success GPG 'sign with an unknown id (2)' '
be15f505 696
d492b31c 697 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
be15f505
LT
698
699'
700
701cat >fakeeditor <<'EOF'
702#!/bin/sh
703test -n "$1" && exec >"$1"
704echo A signed tag message
705echo from a fake editor.
706EOF
707chmod +x fakeeditor
708
709get_tag_header implied-sign $commit commit $time >expect
710./fakeeditor >>expect
711echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 712test_expect_success GPG '-u implies signed tag' '
d592b315 713 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
be15f505 714 get_tag_msg implied-sign >actual &&
3af82863 715 test_cmp expect actual
be15f505
LT
716'
717
62e09ce9
CR
718cat >sigmsgfile <<EOF
719Another signed tag
720message in a file.
721EOF
722get_tag_header file-signed-tag $commit commit $time >expect
723cat sigmsgfile >>expect
724echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 725test_expect_success GPG \
62e09ce9 726 'creating a signed tag with -F messagefile should succeed' '
d592b315 727 git tag -s -F sigmsgfile file-signed-tag &&
62e09ce9 728 get_tag_msg file-signed-tag >actual &&
3af82863 729 test_cmp expect actual
62e09ce9
CR
730'
731
732cat >siginputmsg <<EOF
733A signed tag message from
734the standard input
735EOF
736get_tag_header stdin-signed-tag $commit commit $time >expect
737cat siginputmsg >>expect
738echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 739test_expect_success GPG 'creating a signed tag with -F - should succeed' '
d592b315 740 git tag -s -F - stdin-signed-tag <siginputmsg &&
62e09ce9 741 get_tag_msg stdin-signed-tag >actual &&
3af82863 742 test_cmp expect actual
62e09ce9
CR
743'
744
10507857
JK
745get_tag_header implied-annotate $commit commit $time >expect
746./fakeeditor >>expect
747echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 748test_expect_success GPG '-s implies annotated tag' '
d592b315 749 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
10507857 750 get_tag_msg implied-annotate >actual &&
3af82863 751 test_cmp expect actual
10507857
JK
752'
753
a4df22ce 754test_expect_success GPG \
e317cfaf
CR
755 'trying to create a signed tag with non-existing -F file should fail' '
756 ! test -f nonexistingfile &&
757 ! tag_exists nosigtag &&
d592b315 758 test_must_fail git tag -s -F nonexistingfile nosigtag &&
e317cfaf
CR
759 ! tag_exists nosigtag
760'
761
a4df22ce 762test_expect_success GPG 'verifying a signed tag should succeed' \
d592b315 763 'git tag -v signed-tag'
ef5a6fb5 764
a4df22ce 765test_expect_success GPG 'verifying two signed tags in one command should succeed' \
d592b315 766 'git tag -v signed-tag file-signed-tag'
62e09ce9 767
a4df22ce 768test_expect_success GPG \
62e09ce9 769 'verifying many signed and non-signed tags should fail' '
d592b315
NS
770 test_must_fail git tag -v signed-tag annotated-tag &&
771 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
772 test_must_fail git tag -v annotated-tag \
d492b31c 773 file-signed-tag file-annotated-tag &&
d592b315 774 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
62e09ce9
CR
775'
776
a4df22ce 777test_expect_success GPG 'verifying a forged tag should fail' '
ef5a6fb5
CR
778 forged=$(git cat-file tag signed-tag |
779 sed -e "s/signed-tag/forged-tag/" |
780 git mktag) &&
781 git tag forged-tag $forged &&
d592b315 782 test_must_fail git tag -v forged-tag
ef5a6fb5
CR
783'
784
785# blank and empty messages for signed tags:
786
787get_tag_header empty-signed-tag $commit commit $time >expect
788echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 789test_expect_success GPG \
ef5a6fb5 790 'creating a signed tag with an empty -m message should succeed' '
d592b315 791 git tag -s -m "" empty-signed-tag &&
ef5a6fb5 792 get_tag_msg empty-signed-tag >actual &&
3af82863 793 test_cmp expect actual &&
d592b315 794 git tag -v empty-signed-tag
ef5a6fb5
CR
795'
796
797>sigemptyfile
798get_tag_header emptyfile-signed-tag $commit commit $time >expect
799echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 800test_expect_success GPG \
ef5a6fb5 801 'creating a signed tag with an empty -F messagefile should succeed' '
d592b315 802 git tag -s -F sigemptyfile emptyfile-signed-tag &&
ef5a6fb5 803 get_tag_msg emptyfile-signed-tag >actual &&
3af82863 804 test_cmp expect actual &&
d592b315 805 git tag -v emptyfile-signed-tag
ef5a6fb5
CR
806'
807
808printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
809printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
810printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
811printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
812get_tag_header blanks-signed-tag $commit commit $time >expect
813cat >>expect <<EOF
814Leading blank lines
815
816Repeated blank lines
817
818Trailing spaces
819
820Trailing blank lines
821EOF
822echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 823test_expect_success GPG \
ef5a6fb5 824 'extra blanks in the message for a signed tag should be removed' '
d592b315 825 git tag -s -F sigblanksfile blanks-signed-tag &&
ef5a6fb5 826 get_tag_msg blanks-signed-tag >actual &&
3af82863 827 test_cmp expect actual &&
d592b315 828 git tag -v blanks-signed-tag
ef5a6fb5
CR
829'
830
831get_tag_header blank-signed-tag $commit commit $time >expect
832echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 833test_expect_success GPG \
ef5a6fb5 834 'creating a signed tag with a blank -m message should succeed' '
d592b315 835 git tag -s -m " " blank-signed-tag &&
ef5a6fb5 836 get_tag_msg blank-signed-tag >actual &&
3af82863 837 test_cmp expect actual &&
d592b315 838 git tag -v blank-signed-tag
ef5a6fb5
CR
839'
840
841echo ' ' >sigblankfile
842echo '' >>sigblankfile
843echo ' ' >>sigblankfile
844get_tag_header blankfile-signed-tag $commit commit $time >expect
845echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 846test_expect_success GPG \
ef5a6fb5 847 'creating a signed tag with blank -F file with spaces should succeed' '
d592b315 848 git tag -s -F sigblankfile blankfile-signed-tag &&
ef5a6fb5 849 get_tag_msg blankfile-signed-tag >actual &&
3af82863 850 test_cmp expect actual &&
d592b315 851 git tag -v blankfile-signed-tag
ef5a6fb5
CR
852'
853
854printf ' ' >sigblanknonlfile
855get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
856echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 857test_expect_success GPG \
ef5a6fb5 858 'creating a signed tag with spaces and no newline should succeed' '
d592b315 859 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
ef5a6fb5 860 get_tag_msg blanknonlfile-signed-tag >actual &&
3af82863 861 test_cmp expect actual &&
d592b315 862 git tag -v signed-tag
ef5a6fb5
CR
863'
864
865# messages with commented lines for signed tags:
866
867cat >sigcommentsfile <<EOF
868# A comment
869
870############
871The message.
872############
873One line.
874
875
876# commented lines
877# commented lines
878
879Another line.
880# comments
881
882Last line.
883EOF
884get_tag_header comments-signed-tag $commit commit $time >expect
885cat >>expect <<EOF
886The message.
887One line.
888
889Another line.
890
891Last line.
892EOF
893echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 894test_expect_success GPG \
ef5a6fb5 895 'creating a signed tag with a -F file with #comments should succeed' '
d592b315 896 git tag -s -F sigcommentsfile comments-signed-tag &&
ef5a6fb5 897 get_tag_msg comments-signed-tag >actual &&
3af82863 898 test_cmp expect actual &&
d592b315 899 git tag -v comments-signed-tag
ef5a6fb5
CR
900'
901
902get_tag_header comment-signed-tag $commit commit $time >expect
903echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 904test_expect_success GPG \
ef5a6fb5 905 'creating a signed tag with #commented -m message should succeed' '
d592b315 906 git tag -s -m "#comment" comment-signed-tag &&
ef5a6fb5 907 get_tag_msg comment-signed-tag >actual &&
3af82863 908 test_cmp expect actual &&
d592b315 909 git tag -v comment-signed-tag
ef5a6fb5
CR
910'
911
912echo '#comment' >sigcommentfile
913echo '' >>sigcommentfile
914echo '####' >>sigcommentfile
915get_tag_header commentfile-signed-tag $commit commit $time >expect
916echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 917test_expect_success GPG \
ef5a6fb5 918 'creating a signed tag with #commented -F messagefile should succeed' '
d592b315 919 git tag -s -F sigcommentfile commentfile-signed-tag &&
ef5a6fb5 920 get_tag_msg commentfile-signed-tag >actual &&
3af82863 921 test_cmp expect actual &&
d592b315 922 git tag -v commentfile-signed-tag
ef5a6fb5
CR
923'
924
925printf '#comment' >sigcommentnonlfile
926get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
927echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 928test_expect_success GPG \
ef5a6fb5 929 'creating a signed tag with a #comment and no newline should succeed' '
d592b315 930 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
ef5a6fb5 931 get_tag_msg commentnonlfile-signed-tag >actual &&
3af82863 932 test_cmp expect actual &&
d592b315 933 git tag -v commentnonlfile-signed-tag
ef5a6fb5
CR
934'
935
5206d130
CR
936# listing messages for signed tags:
937
a4df22ce 938test_expect_success GPG \
5206d130 939 'listing the one-line message of a signed tag should succeed' '
d592b315 940 git tag -s -m "A message line signed" stag-one-line &&
5206d130
CR
941
942 echo "stag-one-line" >expect &&
d592b315 943 git tag -l | grep "^stag-one-line" >actual &&
3af82863 944 test_cmp expect actual &&
d592b315 945 git tag -n0 -l | grep "^stag-one-line" >actual &&
3af82863 946 test_cmp expect actual &&
d592b315 947 git tag -n0 -l stag-one-line >actual &&
3af82863 948 test_cmp expect actual &&
5206d130
CR
949
950 echo "stag-one-line A message line signed" >expect &&
d592b315 951 git tag -n1 -l | grep "^stag-one-line" >actual &&
3af82863 952 test_cmp expect actual &&
d592b315 953 git tag -n -l | grep "^stag-one-line" >actual &&
3af82863 954 test_cmp expect actual &&
d592b315 955 git tag -n1 -l stag-one-line >actual &&
3af82863 956 test_cmp expect actual &&
d592b315 957 git tag -n2 -l stag-one-line >actual &&
3af82863 958 test_cmp expect actual &&
d592b315 959 git tag -n999 -l stag-one-line >actual &&
3af82863 960 test_cmp expect actual
5206d130
CR
961'
962
a4df22ce 963test_expect_success GPG \
5206d130 964 'listing the zero-lines message of a signed tag should succeed' '
d592b315 965 git tag -s -m "" stag-zero-lines &&
5206d130
CR
966
967 echo "stag-zero-lines" >expect &&
d592b315 968 git tag -l | grep "^stag-zero-lines" >actual &&
3af82863 969 test_cmp expect actual &&
d592b315 970 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
3af82863 971 test_cmp expect actual &&
d592b315 972 git tag -n0 -l stag-zero-lines >actual &&
3af82863 973 test_cmp expect actual &&
5206d130
CR
974
975 echo "stag-zero-lines " >expect &&
d592b315 976 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
3af82863 977 test_cmp expect actual &&
d592b315 978 git tag -n -l | grep "^stag-zero-lines" >actual &&
3af82863 979 test_cmp expect actual &&
d592b315 980 git tag -n1 -l stag-zero-lines >actual &&
3af82863 981 test_cmp expect actual &&
d592b315 982 git tag -n2 -l stag-zero-lines >actual &&
3af82863 983 test_cmp expect actual &&
d592b315 984 git tag -n999 -l stag-zero-lines >actual &&
3af82863 985 test_cmp expect actual
5206d130
CR
986'
987
988echo 'stag line one' >sigtagmsg
989echo 'stag line two' >>sigtagmsg
990echo 'stag line three' >>sigtagmsg
a4df22ce 991test_expect_success GPG \
5206d130 992 'listing many message lines of a signed tag should succeed' '
d592b315 993 git tag -s -F sigtagmsg stag-lines &&
5206d130
CR
994
995 echo "stag-lines" >expect &&
d592b315 996 git tag -l | grep "^stag-lines" >actual &&
3af82863 997 test_cmp expect actual &&
d592b315 998 git tag -n0 -l | grep "^stag-lines" >actual &&
3af82863 999 test_cmp expect actual &&
d592b315 1000 git tag -n0 -l stag-lines >actual &&
3af82863 1001 test_cmp expect actual &&
5206d130
CR
1002
1003 echo "stag-lines stag line one" >expect &&
d592b315 1004 git tag -n1 -l | grep "^stag-lines" >actual &&
3af82863 1005 test_cmp expect actual &&
d592b315 1006 git tag -n -l | grep "^stag-lines" >actual &&
3af82863 1007 test_cmp expect actual &&
d592b315 1008 git tag -n1 -l stag-lines >actual &&
3af82863 1009 test_cmp expect actual &&
5206d130
CR
1010
1011 echo " stag line two" >>expect &&
d592b315 1012 git tag -n2 -l | grep "^ *stag.line" >actual &&
3af82863 1013 test_cmp expect actual &&
d592b315 1014 git tag -n2 -l stag-lines >actual &&
3af82863 1015 test_cmp expect actual &&
5206d130
CR
1016
1017 echo " stag line three" >>expect &&
d592b315 1018 git tag -n3 -l | grep "^ *stag.line" >actual &&
3af82863 1019 test_cmp expect actual &&
d592b315 1020 git tag -n3 -l stag-lines >actual &&
3af82863 1021 test_cmp expect actual &&
d592b315 1022 git tag -n4 -l | grep "^ *stag.line" >actual &&
3af82863 1023 test_cmp expect actual &&
d592b315 1024 git tag -n4 -l stag-lines >actual &&
3af82863 1025 test_cmp expect actual &&
d592b315 1026 git tag -n99 -l | grep "^ *stag.line" >actual &&
3af82863 1027 test_cmp expect actual &&
d592b315 1028 git tag -n99 -l stag-lines >actual &&
3af82863 1029 test_cmp expect actual
5206d130
CR
1030'
1031
ef5a6fb5
CR
1032# tags pointing to objects different from commits:
1033
1034tree=$(git rev-parse HEAD^{tree})
1035blob=$(git rev-parse HEAD:foo)
a4df22ce 1036tag=$(git rev-parse signed-tag 2>/dev/null)
ef5a6fb5
CR
1037
1038get_tag_header tree-signed-tag $tree tree $time >expect
1039echo "A message for a tree" >>expect
1040echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1041test_expect_success GPG \
ef5a6fb5 1042 'creating a signed tag pointing to a tree should succeed' '
d592b315 1043 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
ef5a6fb5 1044 get_tag_msg tree-signed-tag >actual &&
3af82863 1045 test_cmp expect actual
ef5a6fb5
CR
1046'
1047
1048get_tag_header blob-signed-tag $blob blob $time >expect
1049echo "A message for a blob" >>expect
1050echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1051test_expect_success GPG \
ef5a6fb5 1052 'creating a signed tag pointing to a blob should succeed' '
d592b315 1053 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
ef5a6fb5 1054 get_tag_msg blob-signed-tag >actual &&
3af82863 1055 test_cmp expect actual
ef5a6fb5
CR
1056'
1057
1058get_tag_header tag-signed-tag $tag tag $time >expect
1059echo "A message for another tag" >>expect
1060echo '-----BEGIN PGP SIGNATURE-----' >>expect
a4df22ce 1061test_expect_success GPG \
ef5a6fb5 1062 'creating a signed tag pointing to another tag should succeed' '
d592b315 1063 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
ef5a6fb5 1064 get_tag_msg tag-signed-tag >actual &&
3af82863 1065 test_cmp expect actual
ef5a6fb5
CR
1066'
1067
c8525c30
MG
1068# usage with rfc1991 signatures
1069echo "rfc1991" > gpghome/gpg.conf
1070get_tag_header rfc1991-signed-tag $commit commit $time >expect
1071echo "RFC1991 signed tag" >>expect
1072echo '-----BEGIN PGP MESSAGE-----' >>expect
1073test_expect_success GPG \
1074 'creating a signed tag with rfc1991' '
1075 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1076 get_tag_msg rfc1991-signed-tag >actual &&
1077 test_cmp expect actual
1078'
1079
1080cat >fakeeditor <<'EOF'
1081#!/bin/sh
1082cp "$1" actual
1083EOF
1084chmod +x fakeeditor
1085
3d5854e7 1086test_expect_success GPG \
c8525c30
MG
1087 'reediting a signed tag body omits signature' '
1088 echo "RFC1991 signed tag" >expect &&
1089 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1090 test_cmp expect actual
1091'
1092
3d5854e7 1093test_expect_success GPG \
c8525c30
MG
1094 'verifying rfc1991 signature' '
1095 git tag -v rfc1991-signed-tag
1096'
1097
3d5854e7 1098test_expect_success GPG \
c8525c30
MG
1099 'list tag with rfc1991 signature' '
1100 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1101 git tag -l -n1 rfc1991-signed-tag >actual &&
1102 test_cmp expect actual &&
1103 git tag -l -n2 rfc1991-signed-tag >actual &&
1104 test_cmp expect actual &&
1105 git tag -l -n999 rfc1991-signed-tag >actual &&
1106 test_cmp expect actual
1107'
1108
1109rm -f gpghome/gpg.conf
1110
3d5854e7 1111test_expect_success GPG \
c8525c30
MG
1112 'verifying rfc1991 signature without --rfc1991' '
1113 git tag -v rfc1991-signed-tag
1114'
1115
3d5854e7 1116test_expect_success GPG \
c8525c30
MG
1117 'list tag with rfc1991 signature without --rfc1991' '
1118 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1119 git tag -l -n1 rfc1991-signed-tag >actual &&
1120 test_cmp expect actual &&
1121 git tag -l -n2 rfc1991-signed-tag >actual &&
1122 test_cmp expect actual &&
1123 git tag -l -n999 rfc1991-signed-tag >actual &&
1124 test_cmp expect actual
1125'
1126
3d5854e7 1127test_expect_success GPG \
c8525c30
MG
1128 'reediting a signed tag body omits signature' '
1129 echo "RFC1991 signed tag" >expect &&
1130 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1131 test_cmp expect actual
1132'
1133
aba91192
CR
1134# try to sign with bad user.signingkey
1135git config user.signingkey BobTheMouse
a4df22ce 1136test_expect_success GPG \
d592b315 1137 'git tag -s fails if gpg is misconfigured' \
d492b31c 1138 'test_must_fail git tag -s -m tail tag-gpg-failure'
aba91192
CR
1139git config --unset user.signingkey
1140
ef5a6fb5
CR
1141# try to verify without gpg:
1142
1143rm -rf gpghome
a4df22ce 1144test_expect_success GPG \
ef5a6fb5 1145 'verify signed tag fails when public key is not present' \
d592b315 1146 'test_must_fail git tag -v signed-tag'
ef5a6fb5 1147
41ac414e 1148test_expect_success \
d592b315 1149 'git tag -a fails if tag annotation is empty' '
41ac414e 1150 ! (GIT_EDITOR=cat git tag -a initial-comment)
eb9d2b91
MH
1151'
1152
4d8b1dc8
MH
1153test_expect_success \
1154 'message in editor has initial comment' '
5649bd9a
ÆAB
1155 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1156'
1157
b3e1900a 1158test_expect_success 'message in editor has initial comment: first line' '
eb9d2b91 1159 # check the first line --- should be empty
5649bd9a
ÆAB
1160 echo >first.expect &&
1161 sed -e 1q <actual >first.actual &&
b3e1900a 1162 test_i18ncmp first.expect first.actual
5649bd9a
ÆAB
1163'
1164
1165test_expect_success \
1166 'message in editor has initial comment: remainder' '
eb9d2b91 1167 # remove commented lines from the remainder -- should be empty
5649bd9a
ÆAB
1168 >rest.expect
1169 sed -e 1d -e '/^#/d' <actual >rest.actual &&
1170 test_cmp rest.expect rest.actual
4d8b1dc8
MH
1171'
1172
1173get_tag_header reuse $commit commit $time >expect
1174echo "An annotation to be reused" >> expect
1175test_expect_success \
1176 'overwriting an annoted tag should use its previous body' '
1177 git tag -a -m "An annotation to be reused" reuse &&
1178 GIT_EDITOR=true git tag -f -a reuse &&
1179 get_tag_msg reuse >actual &&
3af82863 1180 test_cmp expect actual
4d8b1dc8
MH
1181'
1182
dbd0f5c7
JH
1183test_expect_success 'filename for the message is relative to cwd' '
1184 mkdir subdir &&
1185 echo "Tag message in top directory" >msgfile-5 &&
1186 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1187 (
1188 cd subdir &&
1189 git tag -a -F msgfile-5 tag-from-subdir
1190 ) &&
1191 git cat-file tag tag-from-subdir | grep "in sub directory"
1192'
1193
1194test_expect_success 'filename for the message is relative to cwd' '
1195 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1196 (
1197 cd subdir &&
1198 git tag -a -F msgfile-6 tag-from-subdir-2
1199 ) &&
1200 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1201'
1202
32c35cfb
JG
1203# create a few more commits to test --contains
1204
1205hash1=$(git rev-parse HEAD)
1206
1207test_expect_success 'creating second commit and tag' '
1208 echo foo-2.0 >foo &&
1209 git add foo &&
2dec68cf 1210 git commit -m second &&
32c35cfb
JG
1211 git tag v2.0
1212'
1213
1214hash2=$(git rev-parse HEAD)
1215
1216test_expect_success 'creating third commit without tag' '
1217 echo foo-dev >foo &&
1218 git add foo &&
1219 git commit -m third
1220'
1221
1222hash3=$(git rev-parse HEAD)
1223
1224# simple linear checks of --continue
1225
1226cat > expected <<EOF
1227v0.2.1
1228v1.0
1229v1.0.1
1230v1.1.3
1231v2.0
1232EOF
1233
1234test_expect_success 'checking that first commit is in all tags (hash)' "
2dec68cf 1235 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1236 test_cmp expected actual
1237"
1238
1239# other ways of specifying the commit
1240test_expect_success 'checking that first commit is in all tags (tag)' "
2dec68cf 1241 git tag -l --contains v1.0 v* >actual &&
32c35cfb
JG
1242 test_cmp expected actual
1243"
1244
1245test_expect_success 'checking that first commit is in all tags (relative)' "
2dec68cf 1246 git tag -l --contains HEAD~2 v* >actual &&
32c35cfb
JG
1247 test_cmp expected actual
1248"
1249
1250cat > expected <<EOF
1251v2.0
1252EOF
1253
1254test_expect_success 'checking that second commit only has one tag' "
2dec68cf 1255 git tag -l --contains $hash2 v* >actual &&
32c35cfb
JG
1256 test_cmp expected actual
1257"
1258
1259
1260cat > expected <<EOF
1261EOF
1262
1263test_expect_success 'checking that third commit has no tags' "
2dec68cf 1264 git tag -l --contains $hash3 v* >actual &&
32c35cfb
JG
1265 test_cmp expected actual
1266"
1267
1268# how about a simple merge?
1269
1270test_expect_success 'creating simple branch' '
1271 git branch stable v2.0 &&
1272 git checkout stable &&
1273 echo foo-3.0 > foo &&
2dec68cf 1274 git commit foo -m fourth &&
32c35cfb
JG
1275 git tag v3.0
1276'
1277
1278hash4=$(git rev-parse HEAD)
1279
1280cat > expected <<EOF
1281v3.0
1282EOF
1283
1284test_expect_success 'checking that branch head only has one tag' "
2dec68cf 1285 git tag -l --contains $hash4 v* >actual &&
32c35cfb
JG
1286 test_cmp expected actual
1287"
1288
1289test_expect_success 'merging original branch into this branch' '
1290 git merge --strategy=ours master &&
1291 git tag v4.0
1292'
1293
1294cat > expected <<EOF
1295v4.0
1296EOF
1297
1298test_expect_success 'checking that original branch head has one tag now' "
2dec68cf 1299 git tag -l --contains $hash3 v* >actual &&
32c35cfb
JG
1300 test_cmp expected actual
1301"
1302
1303cat > expected <<EOF
1304v0.2.1
1305v1.0
1306v1.0.1
1307v1.1.3
1308v2.0
1309v3.0
1310v4.0
1311EOF
1312
1313test_expect_success 'checking that initial commit is in all tags' "
2dec68cf 1314 git tag -l --contains $hash1 v* >actual &&
32c35cfb
JG
1315 test_cmp expected actual
1316"
1317
e0e03a73
ST
1318# mixing modes and options:
1319
1320test_expect_success 'mixing incompatibles modes and options is forbidden' '
2dec68cf
JN
1321 test_must_fail git tag -a &&
1322 test_must_fail git tag -l -v &&
1323 test_must_fail git tag -n 100 &&
1324 test_must_fail git tag -l -m msg &&
1325 test_must_fail git tag -l -F some file &&
e0e03a73
ST
1326 test_must_fail git tag -v -s
1327'
1328
ae7706b9
TG
1329# check points-at
1330
1331test_expect_success '--points-at cannot be used in non-list mode' '
1332 test_must_fail git tag --points-at=v4.0 foo
1333'
1334
1335test_expect_success '--points-at finds lightweight tags' '
1336 echo v4.0 >expect &&
1337 git tag --points-at v4.0 >actual &&
1338 test_cmp expect actual
1339'
1340
1341test_expect_success '--points-at finds annotated tags of commits' '
1342 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1343 echo annotated-v4.0 >expect &&
1344 git tag -l --points-at v4.0 "annotated*" >actual &&
1345 test_cmp expect actual
1346'
1347
1348test_expect_success '--points-at finds annotated tags of tags' '
1349 git tag -m "describing the v4.0 tag object" \
1350 annotated-again-v4.0 annotated-v4.0 &&
1351 cat >expect <<-\EOF &&
1352 annotated-again-v4.0
1353 annotated-v4.0
1354 EOF
1355 git tag --points-at=annotated-v4.0 >actual &&
1356 test_cmp expect actual
1357'
1358
1359test_expect_success 'multiple --points-at are OR-ed together' '
1360 cat >expect <<-\EOF &&
1361 v2.0
1362 v3.0
1363 EOF
1364 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1365 test_cmp expect actual
1366'
1367
ef5a6fb5 1368test_done