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