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