]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7004-tag.sh
git-svn: understand grafts when doing dcommit
[thirdparty/git.git] / t / t7004-tag.sh
CommitLineData
ef5a6fb5
CR
1#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
6test_description='git-tag
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
CR
24test_expect_success 'listing all tags in an empty tree should output nothing' '
25 test `git-tag -l | wc -l` -eq 0 &&
26 test `git-tag | wc -l` -eq 0
27'
ef5a6fb5
CR
28
29test_expect_failure 'looking for a tag in an empty tree should fail' \
30 'tag_exists mytag'
31
32test_expect_success 'creating a tag in an empty tree should fail' '
33 ! git-tag mynotag &&
34 ! tag_exists mynotag
35'
36
37test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
38 ! git-tag mytaghead HEAD &&
39 ! tag_exists mytaghead
40'
41
42test_expect_success 'creating a tag for an unknown revision should fail' '
43 ! git-tag mytagnorev aaaaaaaaaaa &&
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
CR
56test_expect_success 'listing all tags if one exists should succeed' '
57 git-tag -l &&
58 git-tag
59'
ef5a6fb5 60
62e09ce9
CR
61test_expect_success 'listing all tags if one exists should output that tag' '
62 test `git-tag -l` = mytag &&
63 test `git-tag` = mytag
64'
ef5a6fb5
CR
65
66# pattern matching:
67
68test_expect_success 'listing a tag using a matching pattern should succeed' \
69 'git-tag -l mytag'
70
71test_expect_success \
72 'listing a tag using a matching pattern should output that tag' \
73 'test `git-tag -l mytag` = mytag'
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' \
78 'git-tag -l xxx'
79
80test_expect_success \
81 'listing tags using a non-matching pattern should output nothing' \
82 'test `git-tag -l xxx | wc -l` -eq 0'
83
84# special cases for creating tags:
85
86test_expect_failure \
87 'trying to create a tag with the name of one existing should fail' \
88 'git tag mytag'
89
90test_expect_success \
91 'trying to create a tag with a non-valid name should fail' '
92 test `git-tag -l | wc -l` -eq 1 &&
93 ! git tag "" &&
94 ! git tag .othertag &&
95 ! git tag "other tag" &&
96 ! git tag "othertag^" &&
97 ! git tag "other~tag" &&
98 test `git-tag -l | wc -l` -eq 1
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 &&
110 ! git-tag -d unknown-tag
111'
112
113cat >expect <<EOF
114myhead
115mytag
116EOF
117test_expect_success \
118 'trying to delete tags without params should succeed and do nothing' '
119 git tag -l > actual && git diff expect actual &&
120 git-tag -d &&
121 git tag -l > actual && git diff expect actual
122'
123
124test_expect_success \
125 'deleting two existing tags in one command should succeed' '
126 tag_exists mytag &&
127 tag_exists myhead &&
128 git-tag -d mytag myhead &&
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 &&
136 git-tag mytag &&
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 &&
144 ! git-tag -d mytag anothertag &&
145 ! tag_exists mytag &&
146 ! tag_exists myhead
147'
148
149test_expect_failure 'trying to delete an already deleted tag should fail' \
150 'git-tag -d mytag'
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 &&
62e09ce9
CR
176 git diff expect actual &&
177 git tag > actual &&
ef5a6fb5
CR
178 git diff expect actual
179'
180
181cat >expect <<EOF
182a1
183aa1
184cba
185EOF
186test_expect_success \
187 'listing tags with substring as pattern must print those matching' '
18e32b5b 188 git-tag -l "*a*" > actual &&
5be60078 189 git diff expect actual
ef5a6fb5
CR
190'
191
192cat >expect <<EOF
193v0.2.1
194v1.0.1
ef5a6fb5
CR
195EOF
196test_expect_success \
18e32b5b
CR
197 'listing tags with a suffix as pattern must print those matching' '
198 git-tag -l "*.1" > actual &&
5be60078 199 git diff expect actual
ef5a6fb5
CR
200'
201
202cat >expect <<EOF
203t210
204t211
205EOF
206test_expect_success \
18e32b5b
CR
207 'listing tags with a prefix as pattern must print those matching' '
208 git-tag -l "t21*" > actual &&
5be60078 209 git diff 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' '
ef5a6fb5 217 git-tag -l a1 > actual &&
5be60078 218 git diff 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' '
ef5a6fb5 226 git-tag -l v1.0 > actual &&
5be60078 227 git diff 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' '
18e32b5b 236 git-tag -l "v1.?.?" > actual &&
5be60078 237 git diff expect actual
ef5a6fb5
CR
238'
239
240>expect
241test_expect_success \
242 'listing tags using v.* should print nothing because none have v.' '
243 git-tag -l "v.*" > actual &&
5be60078 244 git diff 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' '
255 git-tag -l "v*" > actual &&
5be60078 256 git diff 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' '
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
268test_expect_failure 'trying to verify an unknown tag should fail' \
269 'git-tag -v unknown-tag'
270
271test_expect_failure \
272 'trying to verify a non-annotated and non-signed tag should fail' \
273 'git-tag -v non-annotated-tag'
274
62e09ce9
CR
275test_expect_failure \
276 'trying to verify many non-annotated or unknown tags, should fail' \
277 'git-tag -v unknown-tag1 non-annotated-tag unknown-tag2'
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' '
303 git-tag -m "A message" annotated-tag &&
304 get_tag_msg annotated-tag >actual &&
305 git diff expect actual
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' '
316 git-tag -F msgfile file-annotated-tag &&
317 get_tag_msg file-annotated-tag >actual &&
318 git diff expect actual
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' '
328 git-tag -F - stdin-annotated-tag <inputmsg &&
329 get_tag_msg stdin-annotated-tag >actual &&
330 git diff expect actual
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 &&
337 ! git-tag -F nonexistingfile notag &&
338 ! tag_exists notag
339'
340
341test_expect_success \
342 'trying to create tags giving many -m or -F options should fail' '
343 echo "message file 1" >msgfile1 &&
344 echo "message file 2" >msgfile2 &&
345 ! tag_exists msgtag &&
346 ! git-tag -m "message 1" -m "message 2" msgtag &&
347 ! tag_exists msgtag &&
348 ! git-tag -F msgfile1 -F msgfile2 msgtag &&
349 ! tag_exists msgtag &&
350 ! git-tag -m "message 1" -F msgfile1 msgtag &&
351 ! tag_exists msgtag &&
352 ! git-tag -F msgfile1 -m "message 1" msgtag &&
353 ! tag_exists msgtag &&
354 ! git-tag -F msgfile1 -m "message 1" -F msgfile2 msgtag &&
355 ! tag_exists msgtag &&
356 ! git-tag -m "message 1" -F msgfile1 -m "message 2" msgtag &&
357 ! tag_exists msgtag
358'
359
ef5a6fb5
CR
360# blank and empty messages:
361
362get_tag_header empty-annotated-tag $commit commit $time >expect
363test_expect_success \
364 'creating a tag with an empty -m message should succeed' '
365 git-tag -m "" empty-annotated-tag &&
366 get_tag_msg empty-annotated-tag >actual &&
367 git diff expect actual
368'
369
370>emptyfile
371get_tag_header emptyfile-annotated-tag $commit commit $time >expect
372test_expect_success \
373 'creating a tag with an empty -F messagefile should succeed' '
374 git-tag -F emptyfile emptyfile-annotated-tag &&
375 get_tag_msg emptyfile-annotated-tag >actual &&
376 git diff expect actual
377'
378
379printf '\n\n \n\t\nLeading blank lines\n' >blanksfile
380printf '\n\t \t \nRepeated blank lines\n' >>blanksfile
381printf '\n\n\nTrailing spaces \t \n' >>blanksfile
382printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
383get_tag_header blanks-annotated-tag $commit commit $time >expect
384cat >>expect <<EOF
385Leading blank lines
386
387Repeated blank lines
388
389Trailing spaces
390
391Trailing blank lines
392EOF
393test_expect_success \
394 'extra blanks in the message for an annotated tag should be removed' '
395 git-tag -F blanksfile blanks-annotated-tag &&
396 get_tag_msg blanks-annotated-tag >actual &&
397 git diff expect actual
398'
399
400get_tag_header blank-annotated-tag $commit commit $time >expect
401test_expect_success \
402 'creating a tag with blank -m message with spaces should succeed' '
403 git-tag -m " " blank-annotated-tag &&
404 get_tag_msg blank-annotated-tag >actual &&
405 git diff expect actual
406'
407
408echo ' ' >blankfile
409echo '' >>blankfile
410echo ' ' >>blankfile
411get_tag_header blankfile-annotated-tag $commit commit $time >expect
412test_expect_success \
413 'creating a tag with blank -F messagefile with spaces should succeed' '
414 git-tag -F blankfile blankfile-annotated-tag &&
415 get_tag_msg blankfile-annotated-tag >actual &&
416 git diff expect actual
417'
418
419printf ' ' >blanknonlfile
420get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
421test_expect_success \
422 'creating a tag with -F file of spaces and no newline should succeed' '
423 git-tag -F blanknonlfile blanknonlfile-annotated-tag &&
424 get_tag_msg blanknonlfile-annotated-tag >actual &&
425 git diff expect actual
426'
427
428# messages with commented lines:
429
430cat >commentsfile <<EOF
431# A comment
432
433############
434The message.
435############
436One line.
437
438
439# commented lines
440# commented lines
441
442Another line.
443# comments
444
445Last line.
446EOF
447get_tag_header comments-annotated-tag $commit commit $time >expect
448cat >>expect <<EOF
449The message.
450One line.
451
452Another line.
453
454Last line.
455EOF
456test_expect_success \
457 'creating a tag using a -F messagefile with #comments should succeed' '
458 git-tag -F commentsfile comments-annotated-tag &&
459 get_tag_msg comments-annotated-tag >actual &&
460 git diff expect actual
461'
462
463get_tag_header comment-annotated-tag $commit commit $time >expect
464test_expect_success \
465 'creating a tag with a #comment in the -m message should succeed' '
466 git-tag -m "#comment" comment-annotated-tag &&
467 get_tag_msg comment-annotated-tag >actual &&
468 git diff expect actual
469'
470
471echo '#comment' >commentfile
472echo '' >>commentfile
473echo '####' >>commentfile
474get_tag_header commentfile-annotated-tag $commit commit $time >expect
475test_expect_success \
476 'creating a tag with #comments in the -F messagefile should succeed' '
477 git-tag -F commentfile commentfile-annotated-tag &&
478 get_tag_msg commentfile-annotated-tag >actual &&
479 git diff expect actual
480'
481
482printf '#comment' >commentnonlfile
483get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
484test_expect_success \
485 'creating a tag with a file of #comment and no newline should succeed' '
486 git-tag -F commentnonlfile commentnonlfile-annotated-tag &&
487 get_tag_msg commentnonlfile-annotated-tag >actual &&
488 git diff expect actual
489'
490
5206d130
CR
491# listing messages for annotated non-signed tags:
492
493test_expect_success \
494 'listing the one-line message of a non-signed tag should succeed' '
495 git-tag -m "A msg" tag-one-line &&
496
497 echo "tag-one-line" >expect &&
498 git-tag -l | grep "^tag-one-line" >actual &&
499 git diff expect actual &&
500 git-tag -n 0 -l | grep "^tag-one-line" >actual &&
501 git diff expect actual &&
502 git-tag -n 0 -l tag-one-line >actual &&
503 git diff expect actual &&
504
505 echo "tag-one-line A msg" >expect &&
506 git-tag -n xxx -l | grep "^tag-one-line" >actual &&
507 git diff expect actual &&
508 git-tag -n "" -l | grep "^tag-one-line" >actual &&
509 git diff expect actual &&
510 git-tag -n 1 -l | grep "^tag-one-line" >actual &&
511 git diff expect actual &&
512 git-tag -n -l | grep "^tag-one-line" >actual &&
513 git diff expect actual &&
514 git-tag -n 1 -l tag-one-line >actual &&
515 git diff expect actual &&
516 git-tag -n 2 -l tag-one-line >actual &&
517 git diff expect actual &&
518 git-tag -n 999 -l tag-one-line >actual &&
519 git diff expect actual
520'
521
522test_expect_success \
523 'listing the zero-lines message of a non-signed tag should succeed' '
524 git-tag -m "" tag-zero-lines &&
525
526 echo "tag-zero-lines" >expect &&
527 git-tag -l | grep "^tag-zero-lines" >actual &&
528 git diff expect actual &&
529 git-tag -n 0 -l | grep "^tag-zero-lines" >actual &&
530 git diff expect actual &&
531 git-tag -n 0 -l tag-zero-lines >actual &&
532 git diff expect actual &&
533
534 echo "tag-zero-lines " >expect &&
535 git-tag -n 1 -l | grep "^tag-zero-lines" >actual &&
536 git diff expect actual &&
537 git-tag -n -l | grep "^tag-zero-lines" >actual &&
538 git diff expect actual &&
539 git-tag -n 1 -l tag-zero-lines >actual &&
540 git diff expect actual &&
541 git-tag -n 2 -l tag-zero-lines >actual &&
542 git diff expect actual &&
543 git-tag -n 999 -l tag-zero-lines >actual &&
544 git diff expect actual
545'
546
547echo 'tag line one' >annotagmsg
548echo 'tag line two' >>annotagmsg
549echo 'tag line three' >>annotagmsg
550test_expect_success \
551 'listing many message lines of a non-signed tag should succeed' '
552 git-tag -F annotagmsg tag-lines &&
553
554 echo "tag-lines" >expect &&
555 git-tag -l | grep "^tag-lines" >actual &&
556 git diff expect actual &&
557 git-tag -n 0 -l | grep "^tag-lines" >actual &&
558 git diff expect actual &&
559 git-tag -n 0 -l tag-lines >actual &&
560 git diff expect actual &&
561
562 echo "tag-lines tag line one" >expect &&
563 git-tag -n 1 -l | grep "^tag-lines" >actual &&
564 git diff expect actual &&
565 git-tag -n -l | grep "^tag-lines" >actual &&
566 git diff expect actual &&
567 git-tag -n 1 -l tag-lines >actual &&
568 git diff expect actual &&
569
570 echo " tag line two" >>expect &&
571 git-tag -n 2 -l | grep "^ *tag.line" >actual &&
572 git diff expect actual &&
573 git-tag -n 2 -l tag-lines >actual &&
574 git diff expect actual &&
575
576 echo " tag line three" >>expect &&
577 git-tag -n 3 -l | grep "^ *tag.line" >actual &&
578 git diff expect actual &&
579 git-tag -n 3 -l tag-lines >actual &&
580 git diff expect actual &&
581 git-tag -n 4 -l | grep "^ *tag.line" >actual &&
582 git diff expect actual &&
583 git-tag -n 4 -l tag-lines >actual &&
584 git diff expect actual &&
585 git-tag -n 99 -l | grep "^ *tag.line" >actual &&
586 git diff expect actual &&
587 git-tag -n 99 -l tag-lines >actual &&
588 git diff expect actual
589'
590
ef5a6fb5
CR
591# trying to verify annotated non-signed tags:
592
593test_expect_success \
594 'trying to verify an annotated non-signed tag should fail' '
595 tag_exists annotated-tag &&
596 ! git-tag -v annotated-tag
597'
598
599test_expect_success \
600 'trying to verify a file-annotated non-signed tag should fail' '
601 tag_exists file-annotated-tag &&
602 ! git-tag -v file-annotated-tag
603'
604
62e09ce9
CR
605test_expect_success \
606 'trying to verify two annotated non-signed tags should fail' '
607 tag_exists annotated-tag file-annotated-tag &&
608 ! git-tag -v annotated-tag file-annotated-tag
609'
610
ef5a6fb5
CR
611# creating and verifying signed tags:
612
613gpg --version >/dev/null
614if [ $? -eq 127 ]; then
615 echo "Skipping signed tags tests, because gpg was not found"
616 test_done
617 exit
618fi
619
797e99a2
CR
620# As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
621# the gpg version 1.0.6 didn't parse trust packets correctly, so for
622# that version, creation of signed tags using the generated key fails.
623case "$(gpg --version)" in
624'gpg (GnuPG) 1.0.6'*)
625 echo "Skipping signed tag tests, because a bug in 1.0.6 version"
626 test_done
627 exit
628 ;;
629esac
630
ef5a6fb5
CR
631# key generation info: gpg --homedir t/t7004 --gen-key
632# Type DSA and Elgamal, size 2048 bits, no expiration date.
633# Name and email: C O Mitter <committer@example.com>
634# No password given, to enable non-interactive operation.
635
636cp -R ../t7004 ./gpghome
637chmod 0700 gpghome
638export GNUPGHOME="$(pwd)/gpghome"
639
640get_tag_header signed-tag $commit commit $time >expect
641echo 'A signed tag message' >>expect
642echo '-----BEGIN PGP SIGNATURE-----' >>expect
643test_expect_success 'creating a signed tag with -m message should succeed' '
644 git-tag -s -m "A signed tag message" signed-tag &&
645 get_tag_msg signed-tag >actual &&
5be60078 646 git diff expect actual
ef5a6fb5
CR
647'
648
62e09ce9
CR
649cat >sigmsgfile <<EOF
650Another signed tag
651message in a file.
652EOF
653get_tag_header file-signed-tag $commit commit $time >expect
654cat sigmsgfile >>expect
655echo '-----BEGIN PGP SIGNATURE-----' >>expect
656test_expect_success \
657 'creating a signed tag with -F messagefile should succeed' '
658 git-tag -s -F sigmsgfile file-signed-tag &&
659 get_tag_msg file-signed-tag >actual &&
660 git diff expect actual
661'
662
663cat >siginputmsg <<EOF
664A signed tag message from
665the standard input
666EOF
667get_tag_header stdin-signed-tag $commit commit $time >expect
668cat siginputmsg >>expect
669echo '-----BEGIN PGP SIGNATURE-----' >>expect
670test_expect_success 'creating a signed tag with -F - should succeed' '
671 git-tag -s -F - stdin-signed-tag <siginputmsg &&
672 get_tag_msg stdin-signed-tag >actual &&
673 git diff expect actual
674'
675
e317cfaf
CR
676test_expect_success \
677 'trying to create a signed tag with non-existing -F file should fail' '
678 ! test -f nonexistingfile &&
679 ! tag_exists nosigtag &&
680 ! git-tag -s -F nonexistingfile nosigtag &&
681 ! tag_exists nosigtag
682'
683
ef5a6fb5
CR
684test_expect_success 'verifying a signed tag should succeed' \
685 'git-tag -v signed-tag'
686
62e09ce9
CR
687test_expect_success 'verifying two signed tags in one command should succeed' \
688 'git-tag -v signed-tag file-signed-tag'
689
690test_expect_success \
691 'verifying many signed and non-signed tags should fail' '
692 ! git-tag -v signed-tag annotated-tag &&
693 ! git-tag -v file-annotated-tag file-signed-tag &&
694 ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
695 ! git-tag -v signed-tag annotated-tag file-signed-tag
696'
697
ef5a6fb5
CR
698test_expect_success 'verifying a forged tag should fail' '
699 forged=$(git cat-file tag signed-tag |
700 sed -e "s/signed-tag/forged-tag/" |
701 git mktag) &&
702 git tag forged-tag $forged &&
703 ! git-tag -v forged-tag
704'
705
706# blank and empty messages for signed tags:
707
708get_tag_header empty-signed-tag $commit commit $time >expect
709echo '-----BEGIN PGP SIGNATURE-----' >>expect
710test_expect_success \
711 'creating a signed tag with an empty -m message should succeed' '
712 git-tag -s -m "" empty-signed-tag &&
713 get_tag_msg empty-signed-tag >actual &&
714 git diff expect actual &&
715 git-tag -v empty-signed-tag
716'
717
718>sigemptyfile
719get_tag_header emptyfile-signed-tag $commit commit $time >expect
720echo '-----BEGIN PGP SIGNATURE-----' >>expect
721test_expect_success \
722 'creating a signed tag with an empty -F messagefile should succeed' '
723 git-tag -s -F sigemptyfile emptyfile-signed-tag &&
724 get_tag_msg emptyfile-signed-tag >actual &&
725 git diff expect actual &&
726 git-tag -v emptyfile-signed-tag
727'
728
729printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile
730printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile
731printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile
732printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
733get_tag_header blanks-signed-tag $commit commit $time >expect
734cat >>expect <<EOF
735Leading blank lines
736
737Repeated blank lines
738
739Trailing spaces
740
741Trailing blank lines
742EOF
743echo '-----BEGIN PGP SIGNATURE-----' >>expect
744test_expect_success \
745 'extra blanks in the message for a signed tag should be removed' '
746 git-tag -s -F sigblanksfile blanks-signed-tag &&
747 get_tag_msg blanks-signed-tag >actual &&
748 git diff expect actual &&
749 git-tag -v blanks-signed-tag
750'
751
752get_tag_header blank-signed-tag $commit commit $time >expect
753echo '-----BEGIN PGP SIGNATURE-----' >>expect
754test_expect_success \
755 'creating a signed tag with a blank -m message should succeed' '
756 git-tag -s -m " " blank-signed-tag &&
757 get_tag_msg blank-signed-tag >actual &&
758 git diff expect actual &&
759 git-tag -v blank-signed-tag
760'
761
762echo ' ' >sigblankfile
763echo '' >>sigblankfile
764echo ' ' >>sigblankfile
765get_tag_header blankfile-signed-tag $commit commit $time >expect
766echo '-----BEGIN PGP SIGNATURE-----' >>expect
767test_expect_success \
768 'creating a signed tag with blank -F file with spaces should succeed' '
769 git-tag -s -F sigblankfile blankfile-signed-tag &&
770 get_tag_msg blankfile-signed-tag >actual &&
771 git diff expect actual &&
772 git-tag -v blankfile-signed-tag
773'
774
775printf ' ' >sigblanknonlfile
776get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
777echo '-----BEGIN PGP SIGNATURE-----' >>expect
778test_expect_success \
779 'creating a signed tag with spaces and no newline should succeed' '
780 git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
781 get_tag_msg blanknonlfile-signed-tag >actual &&
782 git diff expect actual &&
783 git-tag -v signed-tag
784'
785
786# messages with commented lines for signed tags:
787
788cat >sigcommentsfile <<EOF
789# A comment
790
791############
792The message.
793############
794One line.
795
796
797# commented lines
798# commented lines
799
800Another line.
801# comments
802
803Last line.
804EOF
805get_tag_header comments-signed-tag $commit commit $time >expect
806cat >>expect <<EOF
807The message.
808One line.
809
810Another line.
811
812Last line.
813EOF
814echo '-----BEGIN PGP SIGNATURE-----' >>expect
815test_expect_success \
816 'creating a signed tag with a -F file with #comments should succeed' '
817 git-tag -s -F sigcommentsfile comments-signed-tag &&
818 get_tag_msg comments-signed-tag >actual &&
819 git diff expect actual &&
820 git-tag -v comments-signed-tag
821'
822
823get_tag_header comment-signed-tag $commit commit $time >expect
824echo '-----BEGIN PGP SIGNATURE-----' >>expect
825test_expect_success \
826 'creating a signed tag with #commented -m message should succeed' '
827 git-tag -s -m "#comment" comment-signed-tag &&
828 get_tag_msg comment-signed-tag >actual &&
829 git diff expect actual &&
830 git-tag -v comment-signed-tag
831'
832
833echo '#comment' >sigcommentfile
834echo '' >>sigcommentfile
835echo '####' >>sigcommentfile
836get_tag_header commentfile-signed-tag $commit commit $time >expect
837echo '-----BEGIN PGP SIGNATURE-----' >>expect
838test_expect_success \
839 'creating a signed tag with #commented -F messagefile should succeed' '
840 git-tag -s -F sigcommentfile commentfile-signed-tag &&
841 get_tag_msg commentfile-signed-tag >actual &&
842 git diff expect actual &&
843 git-tag -v commentfile-signed-tag
844'
845
846printf '#comment' >sigcommentnonlfile
847get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
848echo '-----BEGIN PGP SIGNATURE-----' >>expect
849test_expect_success \
850 'creating a signed tag with a #comment and no newline should succeed' '
851 git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
852 get_tag_msg commentnonlfile-signed-tag >actual &&
853 git diff expect actual &&
854 git-tag -v commentnonlfile-signed-tag
855'
856
5206d130
CR
857# listing messages for signed tags:
858
859test_expect_success \
860 'listing the one-line message of a signed tag should succeed' '
861 git-tag -s -m "A message line signed" stag-one-line &&
862
863 echo "stag-one-line" >expect &&
864 git-tag -l | grep "^stag-one-line" >actual &&
865 git diff expect actual &&
866 git-tag -n 0 -l | grep "^stag-one-line" >actual &&
867 git diff expect actual &&
868 git-tag -n 0 -l stag-one-line >actual &&
869 git diff expect actual &&
870
871 echo "stag-one-line A message line signed" >expect &&
872 git-tag -n xxx -l | grep "^stag-one-line" >actual &&
873 git diff expect actual &&
874 git-tag -n "" -l | grep "^stag-one-line" >actual &&
875 git diff expect actual &&
876 git-tag -n 1 -l | grep "^stag-one-line" >actual &&
877 git diff expect actual &&
878 git-tag -n -l | grep "^stag-one-line" >actual &&
879 git diff expect actual &&
880 git-tag -n 1 -l stag-one-line >actual &&
881 git diff expect actual &&
882 git-tag -n 2 -l stag-one-line >actual &&
883 git diff expect actual &&
884 git-tag -n 999 -l stag-one-line >actual &&
885 git diff expect actual
886'
887
888test_expect_success \
889 'listing the zero-lines message of a signed tag should succeed' '
890 git-tag -s -m "" stag-zero-lines &&
891
892 echo "stag-zero-lines" >expect &&
893 git-tag -l | grep "^stag-zero-lines" >actual &&
894 git diff expect actual &&
895 git-tag -n 0 -l | grep "^stag-zero-lines" >actual &&
896 git diff expect actual &&
897 git-tag -n 0 -l stag-zero-lines >actual &&
898 git diff expect actual &&
899
900 echo "stag-zero-lines " >expect &&
901 git-tag -n 1 -l | grep "^stag-zero-lines" >actual &&
902 git diff expect actual &&
903 git-tag -n -l | grep "^stag-zero-lines" >actual &&
904 git diff expect actual &&
905 git-tag -n 1 -l stag-zero-lines >actual &&
906 git diff expect actual &&
907 git-tag -n 2 -l stag-zero-lines >actual &&
908 git diff expect actual &&
909 git-tag -n 999 -l stag-zero-lines >actual &&
910 git diff expect actual
911'
912
913echo 'stag line one' >sigtagmsg
914echo 'stag line two' >>sigtagmsg
915echo 'stag line three' >>sigtagmsg
916test_expect_success \
917 'listing many message lines of a signed tag should succeed' '
918 git-tag -s -F sigtagmsg stag-lines &&
919
920 echo "stag-lines" >expect &&
921 git-tag -l | grep "^stag-lines" >actual &&
922 git diff expect actual &&
923 git-tag -n 0 -l | grep "^stag-lines" >actual &&
924 git diff expect actual &&
925 git-tag -n 0 -l stag-lines >actual &&
926 git diff expect actual &&
927
928 echo "stag-lines stag line one" >expect &&
929 git-tag -n 1 -l | grep "^stag-lines" >actual &&
930 git diff expect actual &&
931 git-tag -n -l | grep "^stag-lines" >actual &&
932 git diff expect actual &&
933 git-tag -n 1 -l stag-lines >actual &&
934 git diff expect actual &&
935
936 echo " stag line two" >>expect &&
937 git-tag -n 2 -l | grep "^ *stag.line" >actual &&
938 git diff expect actual &&
939 git-tag -n 2 -l stag-lines >actual &&
940 git diff expect actual &&
941
942 echo " stag line three" >>expect &&
943 git-tag -n 3 -l | grep "^ *stag.line" >actual &&
944 git diff expect actual &&
945 git-tag -n 3 -l stag-lines >actual &&
946 git diff expect actual &&
947 git-tag -n 4 -l | grep "^ *stag.line" >actual &&
948 git diff expect actual &&
949 git-tag -n 4 -l stag-lines >actual &&
950 git diff expect actual &&
951 git-tag -n 99 -l | grep "^ *stag.line" >actual &&
952 git diff expect actual &&
953 git-tag -n 99 -l stag-lines >actual &&
954 git diff expect actual
955'
956
ef5a6fb5
CR
957# tags pointing to objects different from commits:
958
959tree=$(git rev-parse HEAD^{tree})
960blob=$(git rev-parse HEAD:foo)
961tag=$(git rev-parse signed-tag)
962
963get_tag_header tree-signed-tag $tree tree $time >expect
964echo "A message for a tree" >>expect
965echo '-----BEGIN PGP SIGNATURE-----' >>expect
966test_expect_success \
967 'creating a signed tag pointing to a tree should succeed' '
968 git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
969 get_tag_msg tree-signed-tag >actual &&
970 git diff expect actual
971'
972
973get_tag_header blob-signed-tag $blob blob $time >expect
974echo "A message for a blob" >>expect
975echo '-----BEGIN PGP SIGNATURE-----' >>expect
976test_expect_success \
977 'creating a signed tag pointing to a blob should succeed' '
978 git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
979 get_tag_msg blob-signed-tag >actual &&
980 git diff expect actual
981'
982
983get_tag_header tag-signed-tag $tag tag $time >expect
984echo "A message for another tag" >>expect
985echo '-----BEGIN PGP SIGNATURE-----' >>expect
986test_expect_success \
987 'creating a signed tag pointing to another tag should succeed' '
988 git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
989 get_tag_msg tag-signed-tag >actual &&
990 git diff expect actual
991'
992
993# try to verify without gpg:
994
995rm -rf gpghome
996test_expect_failure \
997 'verify signed tag fails when public key is not present' \
998 'git-tag -v signed-tag'
999
1000test_done