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