interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t7004-tag.sh

2382 lines · 68388 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2007 Carlos Rica
4#
5
6test_description='git tag
7
8Tests for operations with tags.'
9
10GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
13. ./test-lib.sh
14GNUPGHOME_NOT_USED=$GNUPGHOME
15. "$TEST_DIRECTORY"/lib-gpg.sh
16. "$TEST_DIRECTORY"/lib-terminal.sh
17
18# creating and listing lightweight tags:
19
20tag_exists () {
21 git show-ref --quiet --verify refs/tags/"$1"
22}
23
24test_expect_success 'setup' '
25 test_oid_cache <<-EOM
26 othersigheader sha1:gpgsig-sha256
27 othersigheader sha256:gpgsig
28 EOM
29'
30
31test_expect_success 'listing all tags in an empty tree should succeed' '
32 git tag -l &&
33 git tag
34'
35
36test_expect_success 'listing all tags in an empty tree should output nothing' '
37 git tag -l >actual &&
38 test_must_be_empty actual &&
39 git tag >actual &&
40 test_must_be_empty actual
41'
42
43test_expect_success 'sort tags, ignore case' '
44 (
45 git init sort &&
46 cd sort &&
47 test_commit initial &&
48 git tag tag-one &&
49 git tag TAG-two &&
50 git tag -l >actual &&
51 cat >expected <<-\EOF &&
52 TAG-two
53 initial
54 tag-one
55 EOF
56 test_cmp expected actual &&
57 git tag -l -i >actual &&
58 cat >expected <<-\EOF &&
59 initial
60 tag-one
61 TAG-two
62 EOF
63 test_cmp expected actual
64 )
65'
66
67test_expect_success 'looking for a tag in an empty tree should fail' '
68 ! (tag_exists mytag)
69'
70
71test_expect_success 'creating a tag in an empty tree should fail' '
72 test_must_fail git tag mynotag &&
73 ! tag_exists mynotag
74'
75
76test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
77 test_must_fail git tag mytaghead HEAD &&
78 ! tag_exists mytaghead
79'
80
81test_expect_success 'creating a tag for an unknown revision should fail' '
82 test_must_fail git tag mytagnorev aaaaaaaaaaa &&
83 ! tag_exists mytagnorev
84'
85
86# commit used in the tests, test_tick is also called here to freeze the date:
87test_expect_success 'creating a tag using default HEAD should succeed' '
88 test_config core.logAllRefUpdates true &&
89 test_tick &&
90 echo foo >foo &&
91 git add foo &&
92 git commit -m Foo &&
93 git tag mytag &&
94 test_must_fail git reflog exists refs/tags/mytag
95'
96
97test_expect_success 'HEAD is forbidden as a tagname' '
98 test_when_finished "git update-ref --no-deref -d refs/tags/HEAD || :" &&
99 test_must_fail git tag HEAD &&
100 test_must_fail git tag -a -m "useless" HEAD
101'
102
103test_expect_success '"git tag" can remove a tag named HEAD' '
104 test_when_finished "git update-ref --no-deref -d refs/tags/HEAD || :" &&
105 git update-ref refs/tags/HEAD HEAD &&
106 git tag -d HEAD
107'
108
109test_expect_success 'creating a tag with --create-reflog should create reflog' '
110 git log -1 \
111 --format="format:tag: tagging %h (%s, %cd)%n" \
112 --date=format:%Y-%m-%d >expected &&
113 test_when_finished "git tag -d tag_with_reflog1" &&
114 git tag --create-reflog tag_with_reflog1 &&
115 git reflog exists refs/tags/tag_with_reflog1 &&
116 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual &&
117 test_cmp expected actual
118'
119
120test_expect_success 'annotated tag with --create-reflog has correct message' '
121 git log -1 \
122 --format="format:tag: tagging %h (%s, %cd)%n" \
123 --date=format:%Y-%m-%d >expected &&
124 test_when_finished "git tag -d tag_with_reflog2" &&
125 git tag -m "annotated tag" --create-reflog tag_with_reflog2 &&
126 git reflog exists refs/tags/tag_with_reflog2 &&
127 test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 | sed -e "s/^.* //" >actual &&
128 test_cmp expected actual
129'
130
131test_expect_success '--create-reflog does not create reflog on failure' '
132 test_must_fail git tag --create-reflog mytag &&
133 test_must_fail git reflog exists refs/tags/mytag
134'
135
136test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
137 test_when_finished "git tag -d tag_with_reflog3" &&
138 test_config core.logAllRefUpdates always &&
139 git tag tag_with_reflog3 &&
140 git reflog exists refs/tags/tag_with_reflog3
141'
142
143test_expect_success 'listing all tags if one exists should succeed' '
144 git tag -l &&
145 git tag
146'
147
148test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
149 git tag -l >expect &&
150 git tag -l -l >actual &&
151 test_cmp expect actual &&
152 git tag --list --list >actual &&
153 test_cmp expect actual &&
154 git tag --list -l --list >actual &&
155 test_cmp expect actual
156'
157
158test_expect_success 'listing all tags if one exists should output that tag' '
159 git tag -l >actual &&
160 test_grep "^mytag$" actual &&
161 git tag >actual &&
162 test_grep "^mytag$" actual
163'
164
165# pattern matching:
166
167test_expect_success 'listing a tag using a matching pattern should succeed' '
168 git tag -l mytag
169'
170
171test_expect_success 'listing a tag with --ignore-case' '
172 echo mytag >expect &&
173 git tag -l --ignore-case MYTAG >actual &&
174 test_cmp expect actual
175'
176
177test_expect_success 'listing a tag using a matching pattern should output that tag' '
178 echo mytag >expect &&
179 git tag -l mytag >actual &&
180 test_cmp expect actual
181'
182
183test_expect_success 'listing tags using a non-matching pattern should succeed' '
184 git tag -l xxx
185'
186
187test_expect_success 'listing tags using a non-matching pattern should output nothing' '
188 git tag -l xxx >actual &&
189 test_must_be_empty actual
190'
191
192# special cases for creating tags:
193
194test_expect_success 'trying to create a tag with the name of one existing should fail' '
195 test_must_fail git tag mytag
196'
197
198test_expect_success 'trying to create a tag with a non-valid name should fail' '
199 git tag -l >tags-before &&
200 test_must_fail git tag "" &&
201 test_must_fail git tag .othertag &&
202 test_must_fail git tag "other tag" &&
203 test_must_fail git tag "othertag^" &&
204 test_must_fail git tag "other~tag" &&
205 git tag -l >tags-after &&
206 test_cmp tags-before tags-after
207'
208
209test_expect_success 'creating a tag using HEAD directly should succeed' '
210 git tag myhead HEAD &&
211 tag_exists myhead
212'
213
214test_expect_success '--force can create a tag with the name of one existing' '
215 tag_exists mytag &&
216 git tag --force mytag &&
217 tag_exists mytag'
218
219test_expect_success '--force is moot with a non-existing tag name' '
220 test_when_finished git tag -d newtag forcetag &&
221 git tag newtag >expect &&
222 git tag --force forcetag >actual &&
223 test_cmp expect actual
224'
225
226# deleting tags:
227
228test_expect_success 'trying to delete an unknown tag should fail' '
229 ! tag_exists unknown-tag &&
230 test_must_fail git tag -d unknown-tag
231'
232
233test_expect_success 'trying to delete tags without params should succeed and do nothing' '
234 git tag -l >expect &&
235 git tag -d &&
236 git tag -l >actual &&
237 test_cmp expect actual
238'
239
240test_expect_success 'deleting two existing tags in one command should succeed' '
241 tag_exists mytag &&
242 tag_exists myhead &&
243 git tag -d mytag myhead &&
244 ! tag_exists mytag &&
245 ! tag_exists myhead
246'
247
248test_expect_success 'creating a tag with the name of another deleted one should succeed' '
249 ! tag_exists mytag &&
250 git tag mytag &&
251 tag_exists mytag
252'
253
254test_expect_success 'trying to delete two tags, existing and not, should fail in the 2nd' '
255 tag_exists mytag &&
256 ! tag_exists nonexistingtag &&
257 test_must_fail git tag -d mytag nonexistingtag &&
258 ! tag_exists mytag &&
259 ! tag_exists nonexistingtag
260'
261
262test_expect_success 'trying to delete an already deleted tag should fail' '
263 test_must_fail git tag -d mytag
264'
265
266# listing various tags with pattern matching:
267
268test_expect_success 'listing all tags should print them ordered' '
269 cat >expect <<-\EOF &&
270 a1
271 aa1
272 cba
273 t210
274 t211
275 v0.2.1
276 v1.0
277 v1.0.1
278 v1.1.3
279 EOF
280 git tag v1.0.1 &&
281 git tag t211 &&
282 git tag aa1 &&
283 git tag v0.2.1 &&
284 git tag v1.1.3 &&
285 git tag cba &&
286 git tag a1 &&
287 git tag v1.0 &&
288 git tag t210 &&
289 git tag -l >actual &&
290 test_cmp expect actual &&
291 git tag >actual &&
292 test_cmp expect actual
293'
294
295test_expect_success 'listing tags with substring as pattern must print those matching' '
296 cat >expect <<-\EOF &&
297 a1
298 aa1
299 cba
300 EOF
301 rm *a* &&
302 git tag -l "*a*" >current &&
303 test_cmp expect current
304'
305
306test_expect_success 'listing tags with a suffix as pattern must print those matching' '
307 cat >expect <<-\EOF &&
308 v0.2.1
309 v1.0.1
310 EOF
311 git tag -l "*.1" >actual &&
312 test_cmp expect actual
313'
314
315test_expect_success 'listing tags with a prefix as pattern must print those matching' '
316 cat >expect <<-\EOF &&
317 t210
318 t211
319 EOF
320 git tag -l "t21*" >actual &&
321 test_cmp expect actual
322'
323
324test_expect_success 'listing tags using a name as pattern must print that one matching' '
325 cat >expect <<-\EOF &&
326 a1
327 EOF
328 git tag -l a1 >actual &&
329 test_cmp expect actual
330'
331
332test_expect_success 'listing tags using a name as pattern must print that one matching' '
333 cat >expect <<-\EOF &&
334 v1.0
335 EOF
336 git tag -l v1.0 >actual &&
337 test_cmp expect actual
338'
339
340test_expect_success 'listing tags with ? in the pattern should print those matching' '
341 cat >expect <<-\EOF &&
342 v1.0.1
343 v1.1.3
344 EOF
345 git tag -l "v1.?.?" >actual &&
346 test_cmp expect actual
347'
348
349test_expect_success 'listing tags using v.* should print nothing because none have v.' '
350 git tag -l "v.*" >actual &&
351 test_must_be_empty actual
352'
353
354test_expect_success 'listing tags using v* should print only those having v' '
355 cat >expect <<-\EOF &&
356 v0.2.1
357 v1.0
358 v1.0.1
359 v1.1.3
360 EOF
361 git tag -l "v*" >actual &&
362 test_cmp expect actual
363'
364
365test_expect_success 'tag -l can accept multiple patterns' '
366 cat >expect <<-\EOF &&
367 v0.2.1
368 v1.0
369 v1.0.1
370 v1.1.3
371 EOF
372 git tag -l "v1*" "v0*" >actual &&
373 test_cmp expect actual
374'
375
376# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
377# could leave you with the impression that "-l <pattern> -l <pattern>"
378# was how we wanted to accept multiple patterns.
379#
380# This test should not imply that this is a sane thing to support. but
381# since the documentation was worded like it was let's at least find
382# out if we're going to break this long-documented form of taking
383# multiple patterns.
384test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
385 cat >expect <<-\EOF &&
386 v0.2.1
387 v1.0
388 v1.0.1
389 v1.1.3
390 EOF
391 git tag -l "v1*" -l "v0*" >actual &&
392 test_cmp expect actual
393'
394
395test_expect_success 'listing tags in column' '
396 COLUMNS=41 git tag -l --column=row >actual &&
397 cat >expected <<-\EOF &&
398 a1 aa1 cba t210 t211
399 v0.2.1 v1.0 v1.0.1 v1.1.3
400 EOF
401 test_cmp expected actual
402'
403
404test_expect_success 'listing tags in column with column.*' '
405 test_config column.tag row &&
406 test_config column.ui dense &&
407 COLUMNS=40 git tag -l >actual &&
408 cat >expected <<-\EOF &&
409 a1 aa1 cba t210 t211
410 v0.2.1 v1.0 v1.0.1 v1.1.3
411 EOF
412 test_cmp expected actual
413'
414
415test_expect_success 'listing tag with -n --column should fail' '
416 test_must_fail git tag --column -n
417'
418
419test_expect_success 'listing tags -n in column with column.ui ignored' '
420 test_config column.ui "row dense" &&
421 COLUMNS=40 git tag -l -n >actual &&
422 cat >expected <<-\EOF &&
423 a1 Foo
424 aa1 Foo
425 cba Foo
426 t210 Foo
427 t211 Foo
428 v0.2.1 Foo
429 v1.0 Foo
430 v1.0.1 Foo
431 v1.1.3 Foo
432 EOF
433 test_cmp expected actual
434'
435
436# creating and verifying lightweight tags:
437
438test_expect_success 'a non-annotated tag created without parameters should point to HEAD' '
439 git tag non-annotated-tag &&
440 echo commit >expect &&
441 git cat-file -t non-annotated-tag >actual &&
442 test_cmp expect actual &&
443 git rev-parse HEAD >expect &&
444 git rev-parse non-annotated-tag >actual &&
445 test_cmp expect actual
446'
447
448test_expect_success 'trying to verify an unknown tag should fail' '
449 test_must_fail git tag -v unknown-tag
450'
451
452test_expect_success 'trying to verify a non-annotated and non-signed tag should fail' '
453 test_must_fail git tag -v non-annotated-tag
454'
455
456test_expect_success 'trying to verify many non-annotated or unknown tags, should fail' '
457 test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2
458'
459
460# creating annotated tags:
461
462get_tag_msg () {
463 git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
464}
465
466# run test_tick before committing always gives the time in that timezone
467get_tag_header () {
468cat <<EOF
469object $2
470type $3
471tag $1
472tagger C O Mitter <committer@example.com> $4 -0700
473
474EOF
475}
476
477test_expect_success 'creating an annotated tag with -m message should succeed' '
478 commit=$(git rev-parse HEAD) &&
479 time=$test_tick &&
480 get_tag_header annotated-tag $commit commit $time >expect &&
481 echo "A message" >>expect &&
482 git tag -m "A message" annotated-tag &&
483 get_tag_msg annotated-tag >actual &&
484 test_cmp expect actual
485'
486
487test_expect_success 'set up editor' '
488 write_script fakeeditor <<-\EOF
489 sed -e "s/A message/An edited message/g" <"$1" >"$1-"
490 mv "$1-" "$1"
491 EOF
492'
493
494test_expect_success 'creating an annotated tag with -m message --edit should succeed' '
495 get_tag_header annotated-tag-edit $commit commit $time >expect &&
496 echo "An edited message" >>expect &&
497 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
498 get_tag_msg annotated-tag-edit >actual &&
499 test_cmp expect actual
500'
501
502test_expect_success 'creating an annotated tag with -F messagefile should succeed' '
503 cat >msgfile <<-\EOF &&
504 Another message
505 in a file.
506 EOF
507 get_tag_header file-annotated-tag $commit commit $time >expect &&
508 cat msgfile >>expect &&
509 git tag -F msgfile file-annotated-tag &&
510 get_tag_msg file-annotated-tag >actual &&
511 test_cmp expect actual
512'
513
514test_expect_success 'set up editor' '
515 write_script fakeeditor <<-\EOF
516 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
517 mv "$1-" "$1"
518 EOF
519'
520
521test_expect_success 'creating an annotated tag with -F messagefile --edit should succeed' '
522 get_tag_header file-annotated-tag-edit $commit commit $time >expect &&
523 sed -e "s/Another message/Another edited message/g" msgfile >>expect &&
524 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
525 get_tag_msg file-annotated-tag-edit >actual &&
526 test_cmp expect actual
527'
528
529test_expect_success 'creating an annotated tag with -F - should succeed' '
530 cat >inputmsg <<-\EOF &&
531 A message from the
532 standard input
533 EOF
534 get_tag_header stdin-annotated-tag $commit commit $time >expect &&
535 cat inputmsg >>expect &&
536 git tag -F - stdin-annotated-tag <inputmsg &&
537 get_tag_msg stdin-annotated-tag >actual &&
538 test_cmp expect actual
539'
540
541test_expect_success 'trying to create a tag with a non-existing -F file should fail' '
542 ! test -f nonexistingfile &&
543 ! tag_exists notag &&
544 test_must_fail git tag -F nonexistingfile notag &&
545 ! tag_exists notag
546'
547
548test_expect_success 'trying to create tags giving both -m or -F options should fail' '
549 echo "message file 1" >msgfile1 &&
550 ! tag_exists msgtag &&
551 test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
552 ! tag_exists msgtag &&
553 test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
554 ! tag_exists msgtag &&
555 test_must_fail git tag -m "message 1" -F msgfile1 \
556 -m "message 2" msgtag &&
557 ! tag_exists msgtag
558'
559
560# blank and empty messages:
561
562test_expect_success 'creating a tag with an empty -m message should succeed' '
563 get_tag_header empty-annotated-tag $commit commit $time >expect &&
564 git tag -m "" empty-annotated-tag &&
565 get_tag_msg empty-annotated-tag >actual &&
566 test_cmp expect actual
567'
568
569test_expect_success 'creating a tag with an empty -F messagefile should succeed' '
570 >emptyfile &&
571 get_tag_header emptyfile-annotated-tag $commit commit $time >expect &&
572 git tag -F emptyfile emptyfile-annotated-tag &&
573 get_tag_msg emptyfile-annotated-tag >actual &&
574 test_cmp expect actual
575'
576
577test_expect_success 'extra blanks in the message for an annotated tag should be removed' '
578 printf "\n\n \n\t\nLeading blank lines\n" >blanksfile &&
579 printf "\n\t \t \nRepeated blank lines\n" >>blanksfile &&
580 printf "\n\n\nTrailing spaces \t \n" >>blanksfile &&
581 printf "\nTrailing blank lines\n\n\t \n\n" >>blanksfile &&
582 get_tag_header blanks-annotated-tag $commit commit $time >expect &&
583 cat >>expect <<-\EOF &&
584 Leading blank lines
585
586 Repeated blank lines
587
588 Trailing spaces
589
590 Trailing blank lines
591 EOF
592 git tag -F blanksfile blanks-annotated-tag &&
593 get_tag_msg blanks-annotated-tag >actual &&
594 test_cmp expect actual
595'
596
597test_expect_success 'creating a tag with blank -m message with spaces should succeed' '
598 get_tag_header blank-annotated-tag $commit commit $time >expect &&
599 git tag -m " " blank-annotated-tag &&
600 get_tag_msg blank-annotated-tag >actual &&
601 test_cmp expect actual
602'
603
604test_expect_success 'creating a tag with blank -F messagefile with spaces should succeed' '
605 echo " " >blankfile &&
606 echo "" >>blankfile &&
607 echo " " >>blankfile &&
608 get_tag_header blankfile-annotated-tag $commit commit $time >expect &&
609 git tag -F blankfile blankfile-annotated-tag &&
610 get_tag_msg blankfile-annotated-tag >actual &&
611 test_cmp expect actual
612'
613
614test_expect_success 'creating a tag with -F file of spaces and no newline should succeed' '
615 printf " " >blanknonlfile &&
616 get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect &&
617 git tag -F blanknonlfile blanknonlfile-annotated-tag &&
618 get_tag_msg blanknonlfile-annotated-tag >actual &&
619 test_cmp expect actual
620'
621
622# messages with commented lines:
623
624test_expect_success 'creating a tag using a -F messagefile with #comments should succeed' '
625 cat >commentsfile <<-\EOF &&
626 # A comment
627
628 ############
629 The message.
630 ############
631 One line.
632
633
634 # commented lines
635 # commented lines
636
637 Another line.
638 # comments
639
640 Last line.
641 EOF
642 get_tag_header comments-annotated-tag $commit commit $time >expect &&
643 cat >>expect <<-\EOF &&
644 The message.
645 One line.
646
647 Another line.
648
649 Last line.
650 EOF
651 git tag -F commentsfile comments-annotated-tag &&
652 get_tag_msg comments-annotated-tag >actual &&
653 test_cmp expect actual
654'
655
656test_expect_success 'creating a tag with a #comment in the -m message should succeed' '
657 get_tag_header comment-annotated-tag $commit commit $time >expect &&
658 git tag -m "#comment" comment-annotated-tag &&
659 get_tag_msg comment-annotated-tag >actual &&
660 test_cmp expect actual
661'
662
663test_expect_success 'creating a tag with #comments in the -F messagefile should succeed' '
664 echo "#comment" >commentfile &&
665 echo "" >>commentfile &&
666 echo "####" >>commentfile &&
667 get_tag_header commentfile-annotated-tag $commit commit $time >expect &&
668 git tag -F commentfile commentfile-annotated-tag &&
669 get_tag_msg commentfile-annotated-tag >actual &&
670 test_cmp expect actual
671'
672
673test_expect_success 'creating a tag with a file of #comment and no newline should succeed' '
674 printf "#comment" >commentnonlfile &&
675 get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect &&
676 git tag -F commentnonlfile commentnonlfile-annotated-tag &&
677 get_tag_msg commentnonlfile-annotated-tag >actual &&
678 test_cmp expect actual
679'
680
681# trailers
682
683test_expect_success 'create tag with -m and --trailer' '
684 get_tag_header tag-with-inline-message-and-trailers $commit commit $time >expect &&
685 cat >>expect <<-\EOF &&
686 create tag with trailers
687
688 my-trailer: here
689 alt-trailer: there
690 EOF
691 git tag -m "create tag with trailers" \
692 --trailer my-trailer=here \
693 --trailer alt-trailer=there \
694 tag-with-inline-message-and-trailers &&
695 get_tag_msg tag-with-inline-message-and-trailers >actual &&
696 test_cmp expect actual
697'
698
699test_expect_success 'list tag extracting trailers' '
700 cat >expect <<-\EOF &&
701 my-trailer: here
702 alt-trailer: there
703
704 EOF
705 git tag --list --format="%(trailers)" tag-with-inline-message-and-trailers >actual &&
706 test_cmp expect actual
707'
708
709test_expect_success 'create tag with -F and --trailer' '
710 echo "create tag from message file using --trailer" >messagefilewithnotrailers &&
711 get_tag_header tag-with-file-message-and-trailers $commit commit $time >expect &&
712 cat >>expect <<-\EOF &&
713 create tag from message file using --trailer
714
715 my-trailer: here
716 alt-trailer: there
717 EOF
718 git tag -F messagefilewithnotrailers \
719 --trailer my-trailer=here \
720 --trailer alt-trailer=there \
721 tag-with-file-message-and-trailers &&
722 get_tag_msg tag-with-file-message-and-trailers >actual &&
723 test_cmp expect actual
724'
725
726test_expect_success 'create tag with -m and --trailer and --edit' '
727 write_script fakeeditor <<-\EOF &&
728 sed -e "1s/^/EDITED: /g" <"$1" >"$1-"
729 mv "$1-" "$1"
730 EOF
731 get_tag_header tag-with-edited-inline-message-and-trailers $commit commit $time >expect &&
732 cat >>expect <<-\EOF &&
733 EDITED: create tag with trailers
734
735 my-trailer: here
736 alt-trailer: there
737 EOF
738 GIT_EDITOR=./fakeeditor git tag --edit \
739 -m "create tag with trailers" \
740 --trailer my-trailer=here \
741 --trailer alt-trailer=there \
742 tag-with-edited-inline-message-and-trailers &&
743 get_tag_msg tag-with-edited-inline-message-and-trailers >actual &&
744 test_cmp expect actual
745'
746
747test_expect_success 'create tag with -F and --trailer and --edit' '
748 echo "create tag from message file using --trailer" >messagefilewithnotrailers &&
749 get_tag_header tag-with-edited-file-message-and-trailers $commit commit $time >expect &&
750 cat >>expect <<-\EOF &&
751 EDITED: create tag from message file using --trailer
752
753 my-trailer: here
754 alt-trailer: there
755 EOF
756 GIT_EDITOR=./fakeeditor git tag --edit \
757 -F messagefilewithnotrailers \
758 --trailer my-trailer=here \
759 --trailer alt-trailer=there \
760 tag-with-edited-file-message-and-trailers &&
761 get_tag_msg tag-with-edited-file-message-and-trailers >actual &&
762 test_cmp expect actual
763'
764
765test_expect_success 'create annotated tag and force editor when only --trailer is given' '
766 write_script fakeeditor <<-\EOF &&
767 echo "add a line" >"$1-"
768 cat <"$1" >>"$1-"
769 mv "$1-" "$1"
770 EOF
771 get_tag_header tag-with-trailers-and-no-message $commit commit $time >expect &&
772 cat >>expect <<-\EOF &&
773 add a line
774
775 my-trailer: here
776 alt-trailer: there
777 EOF
778 GIT_EDITOR=./fakeeditor git tag \
779 --trailer my-trailer=here \
780 --trailer alt-trailer=there \
781 tag-with-trailers-and-no-message &&
782 get_tag_msg tag-with-trailers-and-no-message >actual &&
783 test_cmp expect actual
784'
785
786test_expect_success 'bad editor causes panic when only --trailer is given' '
787 test_must_fail env GIT_EDITOR=false git tag --trailer my-trailer=here tag-will-not-exist
788'
789
790# listing messages for annotated non-signed tags:
791
792test_expect_success 'listing the one-line message of a non-signed tag should succeed' '
793 git tag -m "A msg" tag-one-line &&
794
795 echo "tag-one-line" >expect &&
796 git tag -l | grep "^tag-one-line" >actual &&
797 test_cmp expect actual &&
798 git tag -n0 -l | grep "^tag-one-line" >actual &&
799 test_cmp expect actual &&
800 git tag -n0 -l tag-one-line >actual &&
801 test_cmp expect actual &&
802
803 git tag -n0 | grep "^tag-one-line" >actual &&
804 test_cmp expect actual &&
805 git tag -n0 tag-one-line >actual &&
806 test_cmp expect actual &&
807
808 echo "tag-one-line A msg" >expect &&
809 git tag -n1 -l | grep "^tag-one-line" >actual &&
810 test_cmp expect actual &&
811 git tag -n -l | grep "^tag-one-line" >actual &&
812 test_cmp expect actual &&
813 git tag -n1 -l tag-one-line >actual &&
814 test_cmp expect actual &&
815 git tag -n2 -l tag-one-line >actual &&
816 test_cmp expect actual &&
817 git tag -n999 -l tag-one-line >actual &&
818 test_cmp expect actual
819'
820
821test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
822 git tag -n 100 >actual &&
823 test_must_be_empty actual &&
824
825 git tag -m "A msg" 100 &&
826 echo "100 A msg" >expect &&
827 git tag -n 100 >actual &&
828 test_cmp expect actual
829'
830
831test_expect_success 'listing the zero-lines message of a non-signed tag should succeed' '
832 git tag -m "" tag-zero-lines &&
833
834 echo "tag-zero-lines" >expect &&
835 git tag -l | grep "^tag-zero-lines" >actual &&
836 test_cmp expect actual &&
837 git tag -n0 -l | grep "^tag-zero-lines" >actual &&
838 test_cmp expect actual &&
839 git tag -n0 -l tag-zero-lines >actual &&
840 test_cmp expect actual &&
841
842 echo "tag-zero-lines " >expect &&
843 git tag -n1 -l | grep "^tag-zero-lines" >actual &&
844 test_cmp expect actual &&
845 git tag -n -l | grep "^tag-zero-lines" >actual &&
846 test_cmp expect actual &&
847 git tag -n1 -l tag-zero-lines >actual &&
848 test_cmp expect actual &&
849 git tag -n2 -l tag-zero-lines >actual &&
850 test_cmp expect actual &&
851 git tag -n999 -l tag-zero-lines >actual &&
852 test_cmp expect actual
853'
854
855test_expect_success 'listing many message lines of a non-signed tag should succeed' '
856 echo "tag line one" >annotagmsg &&
857 echo "tag line two" >>annotagmsg &&
858 echo "tag line three" >>annotagmsg &&
859 git tag -F annotagmsg tag-lines &&
860
861 echo "tag-lines" >expect &&
862 git tag -l | grep "^tag-lines" >actual &&
863 test_cmp expect actual &&
864 git tag -n0 -l | grep "^tag-lines" >actual &&
865 test_cmp expect actual &&
866 git tag -n0 -l tag-lines >actual &&
867 test_cmp expect actual &&
868
869 echo "tag-lines tag line one" >expect &&
870 git tag -n1 -l | grep "^tag-lines" >actual &&
871 test_cmp expect actual &&
872 git tag -n -l | grep "^tag-lines" >actual &&
873 test_cmp expect actual &&
874 git tag -n1 -l tag-lines >actual &&
875 test_cmp expect actual &&
876
877 echo " tag line two" >>expect &&
878 git tag -n2 -l | grep "^ *tag.line" >actual &&
879 test_cmp expect actual &&
880 git tag -n2 -l tag-lines >actual &&
881 test_cmp expect actual &&
882
883 echo " tag line three" >>expect &&
884 git tag -n3 -l | grep "^ *tag.line" >actual &&
885 test_cmp expect actual &&
886 git tag -n3 -l tag-lines >actual &&
887 test_cmp expect actual &&
888 git tag -n4 -l | grep "^ *tag.line" >actual &&
889 test_cmp expect actual &&
890 git tag -n4 -l tag-lines >actual &&
891 test_cmp expect actual &&
892 git tag -n99 -l | grep "^ *tag.line" >actual &&
893 test_cmp expect actual &&
894 git tag -n99 -l tag-lines >actual &&
895 test_cmp expect actual
896'
897
898test_expect_success 'annotations for blobs are empty' '
899 blob=$(git hash-object -w --stdin <<-\EOF
900 Blob paragraph 1.
901
902 Blob paragraph 2.
903 EOF
904 ) &&
905 git tag tag-blob $blob &&
906 echo "tag-blob " >expect &&
907 git tag -n1 -l tag-blob >actual &&
908 test_cmp expect actual
909'
910
911# Run this before doing any signing, so the test has the same results
912# regardless of the GPG prereq.
913test_expect_success 'git tag --format with ahead-behind' '
914 test_when_finished git reset --hard tag-one-line &&
915 git commit --allow-empty -m "left" &&
916 git tag -a -m left tag-left &&
917 git reset --hard HEAD~1 &&
918 git commit --allow-empty -m "right" &&
919 git tag -a -m left tag-right &&
920
921 # Use " !" at the end to demonstrate whitespace
922 # around empty ahead-behind token for tag-blob.
923 cat >expect <<-EOF &&
924 refs/tags/tag-blob !
925 refs/tags/tag-left 1 1 !
926 refs/tags/tag-lines 0 1 !
927 refs/tags/tag-one-line 0 1 !
928 refs/tags/tag-right 0 0 !
929 refs/tags/tag-with-edited-file-message-and-trailers 0 1 !
930 refs/tags/tag-with-edited-inline-message-and-trailers 0 1 !
931 refs/tags/tag-with-file-message-and-trailers 0 1 !
932 refs/tags/tag-with-inline-message-and-trailers 0 1 !
933 refs/tags/tag-with-trailers-and-no-message 0 1 !
934 refs/tags/tag-zero-lines 0 1 !
935 EOF
936 git tag -l --format="%(refname) %(ahead-behind:HEAD) !" >actual 2>err &&
937 grep "refs/tags/tag" actual >actual.focus &&
938 test_cmp expect actual.focus &&
939
940 # Error reported for tags that point to non-commits.
941 test_grep "error: object [0-9a-f]* is a blob, not a commit" err
942'
943
944# trying to verify annotated non-signed tags:
945
946test_expect_success GPG 'trying to verify an annotated non-signed tag should fail' '
947 tag_exists annotated-tag &&
948 test_must_fail git tag -v annotated-tag
949'
950
951test_expect_success GPG 'trying to verify a file-annotated non-signed tag should fail' '
952 tag_exists file-annotated-tag &&
953 test_must_fail git tag -v file-annotated-tag
954'
955
956test_expect_success GPG 'trying to verify two annotated non-signed tags should fail' '
957 tag_exists annotated-tag file-annotated-tag &&
958 test_must_fail git tag -v annotated-tag file-annotated-tag
959'
960
961# creating and verifying signed tags:
962
963test_expect_success GPG 'creating a signed tag with -m message should succeed' '
964 get_tag_header signed-tag $commit commit $time >expect &&
965 echo "A signed tag message" >>expect &&
966 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
967 git tag -s -m "A signed tag message" signed-tag &&
968 get_tag_msg signed-tag >actual &&
969 test_cmp expect actual
970'
971
972test_expect_success GPG 'sign with a given key id' '
973
974 get_tag_header u-signed-tag $commit commit $time >expect &&
975 echo "Another message" >>expect &&
976 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
977 git tag -u committer@example.com -m "Another message" u-signed-tag &&
978 get_tag_msg u-signed-tag >actual &&
979 test_cmp expect actual
980
981'
982
983test_expect_success GPG 'sign with an unknown id (1)' '
984
985 test_must_fail git tag -u author@example.com \
986 -m "Another message" o-signed-tag
987
988'
989
990test_expect_success GPG 'sign with an unknown id (2)' '
991
992 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
993
994'
995
996test_expect_success GPG '-u implies signed tag' '
997 write_script fakeeditor <<-\EOF &&
998 test -n "$1" && exec >"$1"
999 echo A signed tag message
1000 echo from a fake editor.
1001 EOF
1002
1003 get_tag_header implied-sign $commit commit $time >expect &&
1004 ./fakeeditor >>expect &&
1005 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1006 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
1007 get_tag_msg implied-sign >actual &&
1008 test_cmp expect actual
1009'
1010
1011test_expect_success GPG 'creating a signed tag with -F messagefile should succeed' '
1012 cat >sigmsgfile <<-\EOF &&
1013 Another signed tag
1014 message in a file.
1015 EOF
1016 get_tag_header file-signed-tag $commit commit $time >expect &&
1017 cat sigmsgfile >>expect &&
1018 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1019 git tag -s -F sigmsgfile file-signed-tag &&
1020 get_tag_msg file-signed-tag >actual &&
1021 test_cmp expect actual
1022'
1023
1024test_expect_success GPG 'creating a signed tag with -F - should succeed' '
1025 cat >siginputmsg <<-\EOF &&
1026 A signed tag message from
1027 the standard input
1028 EOF
1029 get_tag_header stdin-signed-tag $commit commit $time >expect &&
1030 cat siginputmsg >>expect &&
1031 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1032 git tag -s -F - stdin-signed-tag <siginputmsg &&
1033 get_tag_msg stdin-signed-tag >actual &&
1034 test_cmp expect actual
1035'
1036
1037test_expect_success GPG '-s implies annotated tag' '
1038 get_tag_header implied-annotate $commit commit $time >expect &&
1039 ./fakeeditor >>expect &&
1040 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1041 GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
1042 get_tag_msg implied-annotate >actual &&
1043 test_cmp expect actual
1044'
1045
1046test_expect_success GPG 'git tag -s implied if configured with tag.forcesignannotated' '
1047 get_tag_header forcesignannotated-implied-sign $commit commit $time >expect &&
1048 echo "A message" >>expect &&
1049 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1050 test_config tag.forcesignannotated true &&
1051 git tag -m "A message" forcesignannotated-implied-sign &&
1052 get_tag_msg forcesignannotated-implied-sign >actual &&
1053 test_cmp expect actual
1054'
1055
1056test_expect_success GPG 'lightweight with no message when configured with tag.forcesignannotated' '
1057 test_config tag.forcesignannotated true &&
1058 git tag forcesignannotated-lightweight &&
1059 tag_exists forcesignannotated-lightweight &&
1060 test_must_fail git tag -v forcesignannotated-no-message
1061'
1062
1063test_expect_success GPG 'git tag -a disable configured tag.forcesignannotated' '
1064 get_tag_header forcesignannotated-annotate $commit commit $time >expect &&
1065 echo "A message" >>expect &&
1066 test_config tag.forcesignannotated true &&
1067 git tag -a -m "A message" forcesignannotated-annotate &&
1068 get_tag_msg forcesignannotated-annotate >actual &&
1069 test_cmp expect actual &&
1070 test_must_fail git tag -v forcesignannotated-annotate
1071'
1072
1073test_expect_success GPG 'git tag --sign enable GPG sign' '
1074 get_tag_header forcesignannotated-disabled $commit commit $time >expect &&
1075 echo "A message" >>expect &&
1076 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1077 test_config tag.forcesignannotated false &&
1078 git tag --sign -m "A message" forcesignannotated-disabled &&
1079 get_tag_msg forcesignannotated-disabled >actual &&
1080 test_cmp expect actual
1081'
1082
1083test_expect_success GPG 'git tag configured tag.gpgsign enables GPG sign' '
1084 get_tag_header gpgsign-enabled $commit commit $time >expect &&
1085 echo "A message" >>expect &&
1086 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1087 test_config tag.gpgsign true &&
1088 git tag -m "A message" gpgsign-enabled &&
1089 get_tag_msg gpgsign-enabled>actual &&
1090 test_cmp expect actual
1091'
1092
1093test_expect_success GPG 'git tag --no-sign configured tag.gpgsign skip GPG sign' '
1094 get_tag_header no-sign $commit commit $time >expect &&
1095 echo "A message" >>expect &&
1096 test_config tag.gpgsign true &&
1097 git tag -a --no-sign -m "A message" no-sign &&
1098 get_tag_msg no-sign>actual &&
1099 test_cmp expect actual
1100'
1101
1102test_expect_success GPG 'trying to create a signed tag with non-existing -F file should fail' '
1103 ! test -f nonexistingfile &&
1104 ! tag_exists nosigtag &&
1105 test_must_fail git tag -s -F nonexistingfile nosigtag &&
1106 ! tag_exists nosigtag
1107'
1108
1109test_expect_success GPG 'verifying a signed tag should succeed' '
1110 git tag -v signed-tag
1111'
1112
1113test_expect_success GPG 'verifying two signed tags in one command should succeed' '
1114 git tag -v signed-tag file-signed-tag
1115'
1116
1117test_expect_success GPG 'verifying many signed and non-signed tags should fail' '
1118 test_must_fail git tag -v signed-tag annotated-tag &&
1119 test_must_fail git tag -v file-annotated-tag file-signed-tag &&
1120 test_must_fail git tag -v annotated-tag \
1121 file-signed-tag file-annotated-tag &&
1122 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
1123'
1124
1125test_expect_success GPG 'verifying a forged tag should fail' '
1126 forged=$(git cat-file tag signed-tag |
1127 sed -e "s/signed-tag/forged-tag/" |
1128 git mktag) &&
1129 git tag forged-tag $forged &&
1130 test_must_fail git tag -v forged-tag
1131'
1132
1133test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
1134 cat >expect <<-\EOF &&
1135 tagname : signed-tag
1136 EOF
1137 git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
1138 test_cmp expect actual
1139'
1140
1141test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
1142 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
1143 test_must_be_empty actual
1144'
1145
1146# blank and empty messages for signed tags:
1147
1148test_expect_success GPG 'creating a signed tag with an empty -m message should succeed' '
1149 get_tag_header empty-signed-tag $commit commit $time >expect &&
1150 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1151 git tag -s -m "" empty-signed-tag &&
1152 get_tag_msg empty-signed-tag >actual &&
1153 test_cmp expect actual &&
1154 git tag -v empty-signed-tag
1155'
1156
1157test_expect_success GPG 'creating a signed tag with an empty -F messagefile should succeed' '
1158 >sigemptyfile &&
1159 get_tag_header emptyfile-signed-tag $commit commit $time >expect &&
1160 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1161 git tag -s -F sigemptyfile emptyfile-signed-tag &&
1162 get_tag_msg emptyfile-signed-tag >actual &&
1163 test_cmp expect actual &&
1164 git tag -v emptyfile-signed-tag
1165'
1166
1167test_expect_success GPG 'extra blanks in the message for a signed tag should be removed' '
1168 printf "\n\n \n\t\nLeading blank lines\n" >sigblanksfile &&
1169 printf "\n\t \t \nRepeated blank lines\n" >>sigblanksfile &&
1170 printf "\n\n\nTrailing spaces \t \n" >>sigblanksfile &&
1171 printf "\nTrailing blank lines\n\n\t \n\n" >>sigblanksfile &&
1172 get_tag_header blanks-signed-tag $commit commit $time >expect &&
1173 cat >>expect <<-\EOF &&
1174 Leading blank lines
1175
1176 Repeated blank lines
1177
1178 Trailing spaces
1179
1180 Trailing blank lines
1181 EOF
1182 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1183 git tag -s -F sigblanksfile blanks-signed-tag &&
1184 get_tag_msg blanks-signed-tag >actual &&
1185 test_cmp expect actual &&
1186 git tag -v blanks-signed-tag
1187'
1188
1189test_expect_success GPG 'creating a signed tag with a blank -m message should succeed' '
1190 get_tag_header blank-signed-tag $commit commit $time >expect &&
1191 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1192 git tag -s -m " " blank-signed-tag &&
1193 get_tag_msg blank-signed-tag >actual &&
1194 test_cmp expect actual &&
1195 git tag -v blank-signed-tag
1196'
1197
1198test_expect_success GPG 'creating a signed tag with blank -F file with spaces should succeed' '
1199 echo " " >sigblankfile &&
1200 echo "" >>sigblankfile &&
1201 echo " " >>sigblankfile &&
1202 get_tag_header blankfile-signed-tag $commit commit $time >expect &&
1203 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1204 git tag -s -F sigblankfile blankfile-signed-tag &&
1205 get_tag_msg blankfile-signed-tag >actual &&
1206 test_cmp expect actual &&
1207 git tag -v blankfile-signed-tag
1208'
1209
1210test_expect_success GPG 'creating a signed tag with spaces and no newline should succeed' '
1211 printf " " >sigblanknonlfile &&
1212 get_tag_header blanknonlfile-signed-tag $commit commit $time >expect &&
1213 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1214 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1215 get_tag_msg blanknonlfile-signed-tag >actual &&
1216 test_cmp expect actual &&
1217 git tag -v blanknonlfile-signed-tag
1218'
1219
1220test_expect_success GPG 'signed tag with embedded PGP message' '
1221 cat >msg <<-\EOF &&
1222 -----BEGIN PGP MESSAGE-----
1223
1224 this is not a real PGP message
1225 -----END PGP MESSAGE-----
1226 EOF
1227 git tag -s -F msg confusing-pgp-message &&
1228 git tag -v confusing-pgp-message
1229'
1230
1231# messages with commented lines for signed tags:
1232
1233test_expect_success GPG 'creating a signed tag with a -F file with #comments should succeed' '
1234 cat >sigcommentsfile <<-\EOF &&
1235 # A comment
1236
1237 ############
1238 The message.
1239 ############
1240 One line.
1241
1242
1243 # commented lines
1244 # commented lines
1245
1246 Another line.
1247 # comments
1248
1249 Last line.
1250 EOF
1251 get_tag_header comments-signed-tag $commit commit $time >expect &&
1252 cat >>expect <<-\EOF &&
1253 The message.
1254 One line.
1255
1256 Another line.
1257
1258 Last line.
1259 EOF
1260 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1261 git tag -s -F sigcommentsfile comments-signed-tag &&
1262 get_tag_msg comments-signed-tag >actual &&
1263 test_cmp expect actual &&
1264 git tag -v comments-signed-tag
1265'
1266
1267test_expect_success GPG 'creating a signed tag with #commented -m message should succeed' '
1268 get_tag_header comment-signed-tag $commit commit $time >expect &&
1269 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1270 git tag -s -m "#comment" comment-signed-tag &&
1271 get_tag_msg comment-signed-tag >actual &&
1272 test_cmp expect actual &&
1273 git tag -v comment-signed-tag
1274'
1275
1276test_expect_success GPG 'creating a signed tag with #commented -F messagefile should succeed' '
1277 echo "#comment" >sigcommentfile &&
1278 echo "" >>sigcommentfile &&
1279 echo "####" >>sigcommentfile &&
1280 get_tag_header commentfile-signed-tag $commit commit $time >expect &&
1281 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1282 git tag -s -F sigcommentfile commentfile-signed-tag &&
1283 get_tag_msg commentfile-signed-tag >actual &&
1284 test_cmp expect actual &&
1285 git tag -v commentfile-signed-tag
1286'
1287
1288test_expect_success GPG 'creating a signed tag with a #comment and no newline should succeed' '
1289 printf "#comment" >sigcommentnonlfile &&
1290 get_tag_header commentnonlfile-signed-tag $commit commit $time >expect &&
1291 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1292 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1293 get_tag_msg commentnonlfile-signed-tag >actual &&
1294 test_cmp expect actual &&
1295 git tag -v commentnonlfile-signed-tag
1296'
1297
1298# listing messages for signed tags:
1299
1300test_expect_success GPG 'listing the one-line message of a signed tag should succeed' '
1301 git tag -s -m "A message line signed" stag-one-line &&
1302
1303 echo "stag-one-line" >expect &&
1304 git tag -l | grep "^stag-one-line" >actual &&
1305 test_cmp expect actual &&
1306 git tag -n0 -l | grep "^stag-one-line" >actual &&
1307 test_cmp expect actual &&
1308 git tag -n0 -l stag-one-line >actual &&
1309 test_cmp expect actual &&
1310
1311 echo "stag-one-line A message line signed" >expect &&
1312 git tag -n1 -l | grep "^stag-one-line" >actual &&
1313 test_cmp expect actual &&
1314 git tag -n -l | grep "^stag-one-line" >actual &&
1315 test_cmp expect actual &&
1316 git tag -n1 -l stag-one-line >actual &&
1317 test_cmp expect actual &&
1318 git tag -n2 -l stag-one-line >actual &&
1319 test_cmp expect actual &&
1320 git tag -n999 -l stag-one-line >actual &&
1321 test_cmp expect actual
1322'
1323
1324test_expect_success GPG 'listing the zero-lines message of a signed tag should succeed' '
1325 git tag -s -m "" stag-zero-lines &&
1326
1327 echo "stag-zero-lines" >expect &&
1328 git tag -l | grep "^stag-zero-lines" >actual &&
1329 test_cmp expect actual &&
1330 git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1331 test_cmp expect actual &&
1332 git tag -n0 -l stag-zero-lines >actual &&
1333 test_cmp expect actual &&
1334
1335 echo "stag-zero-lines " >expect &&
1336 git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1337 test_cmp expect actual &&
1338 git tag -n -l | grep "^stag-zero-lines" >actual &&
1339 test_cmp expect actual &&
1340 git tag -n1 -l stag-zero-lines >actual &&
1341 test_cmp expect actual &&
1342 git tag -n2 -l stag-zero-lines >actual &&
1343 test_cmp expect actual &&
1344 git tag -n999 -l stag-zero-lines >actual &&
1345 test_cmp expect actual
1346'
1347
1348test_expect_success GPG 'listing many message lines of a signed tag should succeed' '
1349 echo "stag line one" >sigtagmsg &&
1350 echo "stag line two" >>sigtagmsg &&
1351 echo "stag line three" >>sigtagmsg &&
1352 git tag -s -F sigtagmsg stag-lines &&
1353
1354 echo "stag-lines" >expect &&
1355 git tag -l | grep "^stag-lines" >actual &&
1356 test_cmp expect actual &&
1357 git tag -n0 -l | grep "^stag-lines" >actual &&
1358 test_cmp expect actual &&
1359 git tag -n0 -l stag-lines >actual &&
1360 test_cmp expect actual &&
1361
1362 echo "stag-lines stag line one" >expect &&
1363 git tag -n1 -l | grep "^stag-lines" >actual &&
1364 test_cmp expect actual &&
1365 git tag -n -l | grep "^stag-lines" >actual &&
1366 test_cmp expect actual &&
1367 git tag -n1 -l stag-lines >actual &&
1368 test_cmp expect actual &&
1369
1370 echo " stag line two" >>expect &&
1371 git tag -n2 -l | grep "^ *stag.line" >actual &&
1372 test_cmp expect actual &&
1373 git tag -n2 -l stag-lines >actual &&
1374 test_cmp expect actual &&
1375
1376 echo " stag line three" >>expect &&
1377 git tag -n3 -l | grep "^ *stag.line" >actual &&
1378 test_cmp expect actual &&
1379 git tag -n3 -l stag-lines >actual &&
1380 test_cmp expect actual &&
1381 git tag -n4 -l | grep "^ *stag.line" >actual &&
1382 test_cmp expect actual &&
1383 git tag -n4 -l stag-lines >actual &&
1384 test_cmp expect actual &&
1385 git tag -n99 -l | grep "^ *stag.line" >actual &&
1386 test_cmp expect actual &&
1387 git tag -n99 -l stag-lines >actual &&
1388 test_cmp expect actual
1389'
1390
1391# tags pointing to objects different from commits:
1392
1393test_expect_success GPG 'creating a signed tag pointing to a tree should succeed' '
1394 tree=$(git rev-parse HEAD^{tree}) &&
1395 get_tag_header tree-signed-tag $tree tree $time >expect &&
1396 echo "A message for a tree" >>expect &&
1397 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1398 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1399 get_tag_msg tree-signed-tag >actual &&
1400 test_cmp expect actual
1401'
1402
1403test_expect_success GPG 'creating a signed tag pointing to a blob should succeed' '
1404 blob=$(git rev-parse HEAD:foo) &&
1405 get_tag_header blob-signed-tag $blob blob $time >expect &&
1406 echo "A message for a blob" >>expect &&
1407 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1408 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1409 get_tag_msg blob-signed-tag >actual &&
1410 test_cmp expect actual
1411'
1412
1413test_expect_success GPG 'creating a signed tag pointing to another tag should succeed' '
1414 tag=$(git rev-parse signed-tag 2>/dev/null) &&
1415 get_tag_header tag-signed-tag $tag tag $time >expect &&
1416 echo "A message for another tag" >>expect &&
1417 echo "-----BEGIN PGP SIGNATURE-----" >>expect &&
1418 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1419 get_tag_msg tag-signed-tag >actual &&
1420 test_cmp expect actual
1421'
1422
1423# usage with rfc1991 signatures
1424
1425test_expect_success GPG,RFC1991 'creating a signed tag with rfc1991' '
1426 get_tag_header rfc1991-signed-tag $commit commit $time >expect &&
1427 echo "RFC1991 signed tag" >>expect &&
1428 echo "-----BEGIN PGP MESSAGE-----" >>expect &&
1429 echo "rfc1991" >gpghome/gpg.conf &&
1430 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1431 get_tag_msg rfc1991-signed-tag >actual &&
1432 test_cmp expect actual
1433'
1434
1435test_expect_success GPG,RFC1991 'reediting a signed tag body omits signature' '
1436 write_script fakeeditor <<-\EOF &&
1437 cp "$1" actual
1438 EOF
1439 echo "rfc1991" >gpghome/gpg.conf &&
1440 echo "RFC1991 signed tag" >expect &&
1441 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1442 test_cmp expect actual
1443'
1444
1445test_expect_success GPG,RFC1991 'verifying rfc1991 signature' '
1446 echo "rfc1991" >gpghome/gpg.conf &&
1447 git tag -v rfc1991-signed-tag
1448'
1449
1450test_expect_success GPG,RFC1991 'list tag with rfc1991 signature' '
1451 echo "rfc1991" >gpghome/gpg.conf &&
1452 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1453 git tag -l -n1 rfc1991-signed-tag >actual &&
1454 test_cmp expect actual &&
1455 git tag -l -n2 rfc1991-signed-tag >actual &&
1456 test_cmp expect actual &&
1457 git tag -l -n999 rfc1991-signed-tag >actual &&
1458 test_cmp expect actual
1459'
1460
1461test_expect_success GPG,RFC1991 'verifying rfc1991 signature without --rfc1991' '
1462 rm -f gpghome/gpg.conf &&
1463 git tag -v rfc1991-signed-tag
1464'
1465
1466test_expect_success GPG,RFC1991 'list tag with rfc1991 signature without --rfc1991' '
1467 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1468 git tag -l -n1 rfc1991-signed-tag >actual &&
1469 test_cmp expect actual &&
1470 git tag -l -n2 rfc1991-signed-tag >actual &&
1471 test_cmp expect actual &&
1472 git tag -l -n999 rfc1991-signed-tag >actual &&
1473 test_cmp expect actual
1474'
1475
1476test_expect_success GPG,RFC1991 'reediting a signed tag body omits signature' '
1477 echo "RFC1991 signed tag" >expect &&
1478 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1479 test_cmp expect actual
1480'
1481
1482# try to sign with bad user.signingkey
1483test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad key)' '
1484 test_config user.signingkey BobTheMouse &&
1485 test_must_fail git tag -s -m tail tag-gpg-failure
1486'
1487
1488# try to produce invalid signature
1489test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad signature format)' '
1490 test_config gpg.program echo &&
1491 test_must_fail git tag -s -m tail tag-gpg-failure
1492'
1493
1494# try to produce invalid signature
1495test_expect_success GPG 'git verifies tag is valid with double signature' '
1496 git tag -s -m tail tag-gpg-double-sig &&
1497 git cat-file tag tag-gpg-double-sig >tag &&
1498 othersigheader=$(test_oid othersigheader) &&
1499 sed -ne "/^\$/q;p" tag >new-tag &&
1500 cat <<-EOM >>new-tag &&
1501 $othersigheader -----BEGIN PGP SIGNATURE-----
1502 someinvaliddata
1503 -----END PGP SIGNATURE-----
1504 EOM
1505 sed -e "1,/^tagger/d" tag >>new-tag &&
1506 new_tag=$(git hash-object -t tag -w new-tag) &&
1507 git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1508 git verify-tag tag-gpg-double-sig &&
1509 git fsck
1510'
1511
1512# try to sign with bad user.signingkey
1513test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad key)' '
1514 test_config user.signingkey BobTheMouse &&
1515 test_config gpg.format x509 &&
1516 test_must_fail git tag -s -m tail tag-gpg-failure
1517'
1518
1519# try to produce invalid signature
1520test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad signature format)' '
1521 test_config gpg.x509.program echo &&
1522 test_config gpg.format x509 &&
1523 test_must_fail git tag -s -m tail tag-gpg-failure
1524'
1525
1526# try to verify without gpg:
1527
1528test_expect_success GPG 'verify signed tag fails when public key is not present' '
1529 test_must_fail env GNUPGHOME="$GNUPGHOME_NOT_USED" git tag -v signed-tag
1530'
1531
1532test_expect_success 'git tag -a fails if tag annotation is empty' '
1533 test_must_fail env GIT_EDITOR=cat git tag -a initial-comment
1534'
1535
1536test_expect_success 'message in editor has initial comment' '
1537 test_must_fail env GIT_EDITOR=cat git tag -a initial-comment >actual
1538'
1539
1540test_expect_success 'message in editor has initial comment: first line' '
1541 # check the first line --- should be empty
1542 echo >first.expect &&
1543 sed -e 1q <actual >first.actual &&
1544 test_cmp first.expect first.actual
1545'
1546
1547test_expect_success 'message in editor has initial comment: remainder' '
1548 # remove commented lines from the remainder -- should be empty
1549 sed -e 1d -e "/^#/d" <actual >rest.actual &&
1550 test_must_be_empty rest.actual
1551'
1552
1553test_expect_success 'overwriting an annotated tag should use its previous body' '
1554 get_tag_header reuse $commit commit $time >expect &&
1555 echo "An annotation to be reused" >>expect &&
1556 git tag -a -m "An annotation to be reused" reuse &&
1557 GIT_EDITOR=true git tag -f -a reuse &&
1558 get_tag_msg reuse >actual &&
1559 test_cmp expect actual
1560'
1561
1562test_expect_success 'filename for the message is relative to cwd' '
1563 mkdir subdir &&
1564 echo "Tag message in top directory" >msgfile-5 &&
1565 echo "Tag message in sub directory" >subdir/msgfile-5 &&
1566 (
1567 cd subdir &&
1568 git tag -a -F msgfile-5 tag-from-subdir
1569 ) &&
1570 git cat-file tag tag-from-subdir | grep "in sub directory"
1571'
1572
1573test_expect_success 'filename for the message is relative to cwd' '
1574 echo "Tag message in sub directory" >subdir/msgfile-6 &&
1575 (
1576 cd subdir &&
1577 git tag -a -F msgfile-6 tag-from-subdir-2
1578 ) &&
1579 git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1580'
1581
1582# create a few more commits to test --contains
1583
1584test_expect_success 'creating second commit and tag' '
1585 hash1=$(git rev-parse HEAD) &&
1586 echo foo-2.0 >foo &&
1587 git add foo &&
1588 git commit -m second &&
1589 git tag v2.0
1590'
1591
1592test_expect_success 'creating third commit without tag' '
1593 hash2=$(git rev-parse HEAD) &&
1594 echo foo-dev >foo &&
1595 git add foo &&
1596 git commit -m third
1597'
1598
1599# simple linear checks of --continue
1600
1601test_expect_success 'checking that first commit is in all tags (hash)' '
1602 hash3=$(git rev-parse HEAD) &&
1603 cat >expected <<-\EOF &&
1604 v0.2.1
1605 v1.0
1606 v1.0.1
1607 v1.1.3
1608 v2.0
1609 EOF
1610 git tag -l --contains $hash1 v* >actual &&
1611 test_cmp expected actual
1612'
1613
1614test_expect_success 'tag --contains rejects cyclic replacement histories' '
1615 first=$(git rev-parse HEAD~2) &&
1616 second=$(git rev-parse HEAD~) &&
1617 third=$(git rev-parse HEAD) &&
1618 test_when_finished "
1619 git replace -d $first &&
1620 git replace -d $third &&
1621 git tag -d cycle-a cycle-b
1622 " &&
1623 git tag cycle-a "$first" &&
1624 git tag cycle-b "$third" &&
1625 git replace --graft "$first" "$third" "$second" &&
1626 git replace --graft "$third" "$first" &&
1627 test_must_fail git tag --contains="$second" --list "cycle-*" \
1628 >/dev/null 2>err &&
1629 test_grep "fatal: commit ancestry contains a cycle" err
1630'
1631
1632# other ways of specifying the commit
1633test_expect_success 'checking that first commit is in all tags (tag)' '
1634 cat >expected <<-\EOF &&
1635 v0.2.1
1636 v1.0
1637 v1.0.1
1638 v1.1.3
1639 v2.0
1640 EOF
1641 git tag -l --contains v1.0 v* >actual &&
1642 test_cmp expected actual
1643'
1644
1645test_expect_success 'checking that first commit is in all tags (relative)' '
1646 cat >expected <<-\EOF &&
1647 v0.2.1
1648 v1.0
1649 v1.0.1
1650 v1.1.3
1651 v2.0
1652 EOF
1653 git tag -l --contains HEAD~2 v* >actual &&
1654 test_cmp expected actual
1655'
1656
1657# All the --contains tests above, but with --no-contains
1658test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)' '
1659 git tag -l --no-contains $hash1 v* >actual &&
1660 test_must_be_empty actual
1661'
1662
1663test_expect_success 'checking that first commit is in all tags (tag)' '
1664 git tag -l --no-contains v1.0 v* >actual &&
1665 test_must_be_empty actual
1666'
1667
1668test_expect_success 'checking that first commit is in all tags (relative)' '
1669 git tag -l --no-contains HEAD~2 v* >actual &&
1670 test_must_be_empty actual
1671'
1672
1673test_expect_success 'checking that second commit only has one tag' '
1674 cat >expected <<-\EOF &&
1675 v2.0
1676 EOF
1677 git tag -l --contains $hash2 v* >actual &&
1678 test_cmp expected actual
1679'
1680
1681test_expect_success 'inverse of the last test, with --no-contains' '
1682 cat >expected <<-\EOF &&
1683 v0.2.1
1684 v1.0
1685 v1.0.1
1686 v1.1.3
1687 EOF
1688 git tag -l --no-contains $hash2 v* >actual &&
1689 test_cmp expected actual
1690'
1691
1692test_expect_success 'checking that third commit has no tags' '
1693 git tag -l --contains $hash3 v* >actual &&
1694 test_must_be_empty actual
1695'
1696
1697test_expect_success 'conversely --no-contains on the third commit lists all tags' '
1698 cat >expected <<-\EOF &&
1699 v0.2.1
1700 v1.0
1701 v1.0.1
1702 v1.1.3
1703 v2.0
1704 EOF
1705 git tag -l --no-contains $hash3 v* >actual &&
1706 test_cmp expected actual
1707'
1708
1709# how about a simple merge?
1710
1711test_expect_success 'creating simple branch' '
1712 git branch stable v2.0 &&
1713 git checkout stable &&
1714 echo foo-3.0 >foo &&
1715 git commit foo -m fourth &&
1716 git tag v3.0
1717'
1718
1719test_expect_success 'checking that branch head only has one tag' '
1720 hash4=$(git rev-parse HEAD) &&
1721 cat >expected <<-\EOF &&
1722 v3.0
1723 EOF
1724 git tag -l --contains $hash4 v* >actual &&
1725 test_cmp expected actual
1726'
1727
1728test_expect_success 'checking that branch head with --no-contains lists all but one tag' '
1729 cat >expected <<-\EOF &&
1730 v0.2.1
1731 v1.0
1732 v1.0.1
1733 v1.1.3
1734 v2.0
1735 EOF
1736 git tag -l --no-contains $hash4 v* >actual &&
1737 test_cmp expected actual
1738'
1739
1740test_expect_success 'merging original branch into this branch' '
1741 git merge --strategy=ours main &&
1742 git tag v4.0
1743'
1744
1745test_expect_success 'checking that original branch head has one tag now' '
1746 cat >expected <<-\EOF &&
1747 v4.0
1748 EOF
1749 git tag -l --contains $hash3 v* >actual &&
1750 test_cmp expected actual
1751'
1752
1753test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' '
1754 cat >expected <<-\EOF &&
1755 v0.2.1
1756 v1.0
1757 v1.0.1
1758 v1.1.3
1759 v2.0
1760 v3.0
1761 EOF
1762 git tag -l --no-contains $hash3 v* >actual &&
1763 test_cmp expected actual
1764'
1765
1766test_expect_success 'checking that initial commit is in all tags' '
1767 cat >expected <<-\EOF &&
1768 v0.2.1
1769 v1.0
1770 v1.0.1
1771 v1.1.3
1772 v2.0
1773 v3.0
1774 v4.0
1775 EOF
1776 git tag -l --contains $hash1 v* >actual &&
1777 test_cmp expected actual
1778'
1779
1780test_expect_success 'checking that --contains can be used in non-list mode' '
1781 cat >expected <<-\EOF &&
1782 v0.2.1
1783 v1.0
1784 v1.0.1
1785 v1.1.3
1786 v2.0
1787 v3.0
1788 v4.0
1789 EOF
1790 git tag --contains $hash1 v* >actual &&
1791 test_cmp expected actual
1792'
1793
1794test_expect_success 'checking that initial commit is in all tags with --no-contains' '
1795 git tag -l --no-contains $hash1 v* >actual &&
1796 test_must_be_empty actual
1797'
1798
1799# mixing modes and options:
1800
1801test_expect_success 'mixing incompatibles modes and options is forbidden' '
1802 test_must_fail git tag -a &&
1803 test_must_fail git tag -a -l &&
1804 test_must_fail git tag -s &&
1805 test_must_fail git tag -s -l &&
1806 test_must_fail git tag -m &&
1807 test_must_fail git tag -m -l &&
1808 test_must_fail git tag -m "hlagh" &&
1809 test_must_fail git tag -m "hlagh" -l &&
1810 test_must_fail git tag -F &&
1811 test_must_fail git tag -F -l &&
1812 test_must_fail git tag -f &&
1813 test_must_fail git tag -f -l &&
1814 test_must_fail git tag -a -s -m -F &&
1815 test_must_fail git tag -a -s -m -F -l &&
1816 test_must_fail git tag -l -v &&
1817 test_must_fail git tag -l -d &&
1818 test_must_fail git tag -l -v -d &&
1819 test_must_fail git tag -n 100 -v &&
1820 test_must_fail git tag -l -m msg &&
1821 test_must_fail git tag -l -F some file &&
1822 test_must_fail git tag -v -s &&
1823 test_must_fail git tag --contains tag-tree &&
1824 test_must_fail git tag --contains tag-blob &&
1825 test_must_fail git tag --no-contains tag-tree &&
1826 test_must_fail git tag --no-contains tag-blob &&
1827 test_must_fail git tag --contains --no-contains &&
1828 test_must_fail git tag --no-with HEAD &&
1829 test_must_fail git tag --no-without HEAD
1830'
1831
1832for option in --contains --with --no-contains --without --merged --no-merged --points-at
1833do
1834 test_expect_success "mixing incompatible modes with $option is forbidden" '
1835 test_must_fail git tag -d $option HEAD &&
1836 test_must_fail git tag -d $option HEAD some-tag &&
1837 test_must_fail git tag -v $option HEAD
1838 '
1839 test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" '
1840 git tag -n $option HEAD HEAD &&
1841 git tag $option HEAD HEAD &&
1842 git tag $option
1843 '
1844done
1845
1846# check points-at
1847
1848test_expect_success '--points-at can be used in non-list mode' '
1849 echo v4.0 >expect &&
1850 git tag --points-at=v4.0 "v*" >actual &&
1851 test_cmp expect actual
1852'
1853
1854test_expect_success '--points-at is a synonym for --points-at HEAD' '
1855 echo v4.0 >expect &&
1856 git tag --points-at >actual &&
1857 test_cmp expect actual
1858'
1859
1860test_expect_success '--points-at finds lightweight tags' '
1861 echo v4.0 >expect &&
1862 git tag --points-at v4.0 >actual &&
1863 test_cmp expect actual
1864'
1865
1866test_expect_success '--points-at finds annotated tags of commits' '
1867 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1868 echo annotated-v4.0 >expect &&
1869 git tag -l --points-at v4.0 "annotated*" >actual &&
1870 test_cmp expect actual
1871'
1872
1873test_expect_success '--points-at finds annotated tags of tags' '
1874 git tag -m "describing the v4.0 tag object" \
1875 annotated-again-v4.0 annotated-v4.0 &&
1876 cat >expect <<-\EOF &&
1877 annotated-again-v4.0
1878 annotated-v4.0
1879 EOF
1880 git tag --points-at=annotated-v4.0 >actual &&
1881 test_cmp expect actual
1882'
1883
1884test_expect_success 'recursive tagging should give advice' '
1885 cat >expect <<-EOF &&
1886 hint: You have created a nested tag. The object referred to by your new tag is
1887 hint: already a tag. If you meant to tag the object that it points to, use:
1888 hint:
1889 hint: git tag -f nested annotated-v4.0^{}
1890 hint: Disable this message with "git config set --global advice.nestedTag false"
1891 EOF
1892 git tag -m nested nested annotated-v4.0 2>actual &&
1893 test_cmp expect actual
1894'
1895
1896test_expect_success 'multiple --points-at are OR-ed together' '
1897 cat >expect <<-\EOF &&
1898 v2.0
1899 v3.0
1900 EOF
1901 git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1902 test_cmp expect actual
1903'
1904
1905test_expect_success 'lexical sort' '
1906 git tag foo1.3 &&
1907 git tag foo1.6 &&
1908 git tag foo1.10 &&
1909 git tag -l --sort=refname "foo*" >actual &&
1910 cat >expect <<-\EOF &&
1911 foo1.10
1912 foo1.3
1913 foo1.6
1914 EOF
1915 test_cmp expect actual
1916'
1917
1918test_expect_success 'version sort' '
1919 git tag -l --sort=version:refname "foo*" >actual &&
1920 cat >expect <<-\EOF &&
1921 foo1.3
1922 foo1.6
1923 foo1.10
1924 EOF
1925 test_cmp expect actual
1926'
1927
1928test_expect_success 'reverse version sort' '
1929 git tag -l --sort=-version:refname "foo*" >actual &&
1930 cat >expect <<-\EOF &&
1931 foo1.10
1932 foo1.6
1933 foo1.3
1934 EOF
1935 test_cmp expect actual
1936'
1937
1938test_expect_success 'reverse lexical sort' '
1939 git tag -l --sort=-refname "foo*" >actual &&
1940 cat >expect <<-\EOF &&
1941 foo1.6
1942 foo1.3
1943 foo1.10
1944 EOF
1945 test_cmp expect actual
1946'
1947
1948test_expect_success 'configured lexical sort' '
1949 test_config tag.sort "v:refname" &&
1950 git tag -l "foo*" >actual &&
1951 cat >expect <<-\EOF &&
1952 foo1.3
1953 foo1.6
1954 foo1.10
1955 EOF
1956 test_cmp expect actual
1957'
1958
1959test_expect_success 'option override configured sort' '
1960 test_config tag.sort "v:refname" &&
1961 git tag -l --sort=-refname "foo*" >actual &&
1962 cat >expect <<-\EOF &&
1963 foo1.6
1964 foo1.3
1965 foo1.10
1966 EOF
1967 test_cmp expect actual
1968'
1969
1970test_expect_success '--no-sort cancels config sort keys' '
1971 test_config tag.sort "-refname" &&
1972
1973 # objecttype is identical for all of them, so sort falls back on
1974 # default (ascending refname)
1975 git tag -l \
1976 --no-sort \
1977 --sort="objecttype" \
1978 "foo*" >actual &&
1979 cat >expect <<-\EOF &&
1980 foo1.10
1981 foo1.3
1982 foo1.6
1983 EOF
1984 test_cmp expect actual
1985'
1986
1987test_expect_success '--no-sort cancels command line sort keys' '
1988 # objecttype is identical for all of them, so sort falls back on
1989 # default (ascending refname)
1990 git tag -l \
1991 --sort="-refname" \
1992 --no-sort \
1993 --sort="objecttype" \
1994 "foo*" >actual &&
1995 cat >expect <<-\EOF &&
1996 foo1.10
1997 foo1.3
1998 foo1.6
1999 EOF
2000 test_cmp expect actual
2001'
2002
2003test_expect_success '--no-sort without subsequent --sort prints expected tags' '
2004 # Sort the results with `sort` for a consistent comparison against
2005 # expected
2006 git tag -l --no-sort "foo*" | sort >actual &&
2007 cat >expect <<-\EOF &&
2008 foo1.10
2009 foo1.3
2010 foo1.6
2011 EOF
2012 test_cmp expect actual
2013'
2014
2015test_expect_success 'invalid sort parameter on command line' '
2016 test_must_fail git tag -l --sort=notvalid "foo*" >actual
2017'
2018
2019test_expect_success 'invalid sort parameter in configuratoin' '
2020 test_config tag.sort "v:notvalid" &&
2021 test_must_fail git tag -l "foo*"
2022'
2023
2024test_expect_success 'version sort handles empty value for versionsort.{prereleaseSuffix,suffix}' '
2025 cp .git/config .git/config.orig &&
2026 test_when_finished mv .git/config.orig .git/config &&
2027
2028 cat >>.git/config <<-\EOF &&
2029 [versionsort]
2030 prereleaseSuffix
2031 suffix
2032 EOF
2033 cat >expect <<-\EOF &&
2034 error: missing value for '\''versionsort.suffix'\''
2035 error: missing value for '\''versionsort.prereleasesuffix'\''
2036 EOF
2037 git tag -l --sort=version:refname 2>actual &&
2038 test_cmp expect actual
2039'
2040
2041test_expect_success 'version sort with prerelease reordering' '
2042 test_config versionsort.prereleaseSuffix -rc &&
2043 git tag foo1.6-rc1 &&
2044 git tag foo1.6-rc2 &&
2045 git tag -l --sort=version:refname "foo*" >actual &&
2046 cat >expect <<-\EOF &&
2047 foo1.3
2048 foo1.6-rc1
2049 foo1.6-rc2
2050 foo1.6
2051 foo1.10
2052 EOF
2053 test_cmp expect actual
2054'
2055
2056test_expect_success 'reverse version sort with prerelease reordering' '
2057 test_config versionsort.prereleaseSuffix -rc &&
2058 git tag -l --sort=-version:refname "foo*" >actual &&
2059 cat >expect <<-\EOF &&
2060 foo1.10
2061 foo1.6
2062 foo1.6-rc2
2063 foo1.6-rc1
2064 foo1.3
2065 EOF
2066 test_cmp expect actual
2067'
2068
2069test_expect_success 'version sort with prerelease reordering and common leading character' '
2070 test_config versionsort.prereleaseSuffix -before &&
2071 git tag foo1.7-before1 &&
2072 git tag foo1.7 &&
2073 git tag foo1.7-after1 &&
2074 git tag -l --sort=version:refname "foo1.7*" >actual &&
2075 cat >expect <<-\EOF &&
2076 foo1.7-before1
2077 foo1.7
2078 foo1.7-after1
2079 EOF
2080 test_cmp expect actual
2081'
2082
2083test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
2084 test_config versionsort.prereleaseSuffix -before &&
2085 git config --add versionsort.prereleaseSuffix -after &&
2086 git tag -l --sort=version:refname "foo1.7*" >actual &&
2087 cat >expect <<-\EOF &&
2088 foo1.7-before1
2089 foo1.7-after1
2090 foo1.7
2091 EOF
2092 test_cmp expect actual
2093'
2094
2095test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
2096 test_config versionsort.prereleaseSuffix -bar &&
2097 git config --add versionsort.prereleaseSuffix -foo-baz &&
2098 git config --add versionsort.prereleaseSuffix -foo-bar &&
2099 git tag foo1.8-foo-bar &&
2100 git tag foo1.8-foo-baz &&
2101 git tag foo1.8 &&
2102 git tag -l --sort=version:refname "foo1.8*" >actual &&
2103 cat >expect <<-\EOF &&
2104 foo1.8-foo-baz
2105 foo1.8-foo-bar
2106 foo1.8
2107 EOF
2108 test_cmp expect actual
2109'
2110
2111test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
2112 test_config versionsort.prereleaseSuffix -pre &&
2113 git config --add versionsort.prereleaseSuffix -prerelease &&
2114 git tag foo1.9-pre1 &&
2115 git tag foo1.9-pre2 &&
2116 git tag foo1.9-prerelease1 &&
2117 git tag -l --sort=version:refname "foo1.9*" >actual &&
2118 cat >expect <<-\EOF &&
2119 foo1.9-pre1
2120 foo1.9-pre2
2121 foo1.9-prerelease1
2122 EOF
2123 test_cmp expect actual
2124'
2125
2126test_expect_success 'version sort with general suffix reordering' '
2127 test_config versionsort.suffix -alpha &&
2128 git config --add versionsort.suffix -beta &&
2129 git config --add versionsort.suffix "" &&
2130 git config --add versionsort.suffix -gamma &&
2131 git config --add versionsort.suffix -delta &&
2132 git tag foo1.10-alpha &&
2133 git tag foo1.10-beta &&
2134 git tag foo1.10-gamma &&
2135 git tag foo1.10-delta &&
2136 git tag foo1.10-unlisted-suffix &&
2137 git tag -l --sort=version:refname "foo1.10*" >actual &&
2138 cat >expect <<-\EOF &&
2139 foo1.10-alpha
2140 foo1.10-beta
2141 foo1.10
2142 foo1.10-unlisted-suffix
2143 foo1.10-gamma
2144 foo1.10-delta
2145 EOF
2146 test_cmp expect actual
2147'
2148
2149test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
2150 test_config versionsort.suffix -before &&
2151 test_config versionsort.prereleaseSuffix -after &&
2152 git tag -l --sort=version:refname "foo1.7*" >actual &&
2153 cat >expect <<-\EOF &&
2154 foo1.7-before1
2155 foo1.7
2156 foo1.7-after1
2157 EOF
2158 test_cmp expect actual
2159'
2160
2161test_expect_success 'version sort with very long prerelease suffix' '
2162 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
2163 git tag -l --sort=version:refname
2164'
2165
2166test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
2167 i=1 &&
2168 while test $i -lt 8000
2169 do
2170 echo "commit refs/heads/main
2171committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
2172data <<EOF
2173commit #$i
2174EOF" &&
2175 if test $i = 1
2176 then
2177 echo "from refs/heads/main^0"
2178 fi &&
2179 i=$(($i + 1)) || return 1
2180 done | git fast-import &&
2181 git checkout main &&
2182 git tag far-far-away HEAD^ &&
2183 run_with_limited_stack git tag --contains HEAD >actual &&
2184 test_must_be_empty actual &&
2185 run_with_limited_stack git tag --no-contains HEAD >actual &&
2186 test_line_count "-gt" 10 actual
2187'
2188
2189test_expect_success '--format should list tags as per format given' '
2190 cat >expect <<-\EOF &&
2191 refname : refs/tags/v1.0
2192 refname : refs/tags/v1.0.1
2193 refname : refs/tags/v1.1.3
2194 EOF
2195 git tag -l --format="refname : %(refname)" "v1*" >actual &&
2196 test_cmp expect actual
2197'
2198
2199test_expect_success '--format --omit-empty works' '
2200 cat >expect <<-\EOF &&
2201 refname : refs/tags/v1.0
2202
2203 refname : refs/tags/v1.1.3
2204 EOF
2205 git tag -l --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2206 test_cmp expect actual &&
2207 cat >expect <<-\EOF &&
2208 refname : refs/tags/v1.0
2209 refname : refs/tags/v1.1.3
2210 EOF
2211 git tag -l --omit-empty --format="%(if:notequals=refs/tags/v1.0.1)%(refname)%(then)refname : %(refname)%(end)" "v1*" >actual &&
2212 test_cmp expect actual
2213'
2214
2215test_expect_success 'git tag -l with --format="%(rest)" must fail' '
2216 test_must_fail git tag -l --format="%(rest)" "v1*"
2217'
2218
2219test_expect_success 'set up color tests' '
2220 echo "<RED>v1.0<RESET>" >expect.color &&
2221 echo "v1.0" >expect.bare &&
2222 color_args="--format=%(color:red)%(refname:short) --list v1.0"
2223'
2224
2225test_expect_success '%(color) omitted without tty' '
2226 TERM=vt100 git tag $color_args >actual.raw &&
2227 test_decode_color <actual.raw >actual &&
2228 test_cmp expect.bare actual
2229'
2230
2231test_expect_success TTY '%(color) present with tty' '
2232 test_terminal git tag $color_args >actual.raw &&
2233 test_decode_color <actual.raw >actual &&
2234 test_cmp expect.color actual
2235'
2236
2237test_expect_success '--color overrides auto-color' '
2238 git tag --color $color_args >actual.raw &&
2239 test_decode_color <actual.raw >actual &&
2240 test_cmp expect.color actual
2241'
2242
2243test_expect_success 'color.ui=always overrides auto-color' '
2244 git -c color.ui=always tag $color_args >actual.raw &&
2245 test_decode_color <actual.raw >actual &&
2246 test_cmp expect.color actual
2247'
2248
2249test_expect_success 'setup --merged test tags' '
2250 git tag mergetest-1 HEAD~2 &&
2251 git tag mergetest-2 HEAD~1 &&
2252 git tag mergetest-3 HEAD
2253'
2254
2255test_expect_success '--merged can be used in non-list mode' '
2256 cat >expect <<-\EOF &&
2257 mergetest-1
2258 mergetest-2
2259 EOF
2260 git tag --merged=mergetest-2 "mergetest*" >actual &&
2261 test_cmp expect actual
2262'
2263
2264test_expect_success '--merged is compatible with --no-merged' '
2265 git tag --merged HEAD --no-merged HEAD
2266'
2267
2268test_expect_success '--merged shows merged tags' '
2269 cat >expect <<-\EOF &&
2270 mergetest-1
2271 mergetest-2
2272 EOF
2273 git tag -l --merged=mergetest-2 mergetest-* >actual &&
2274 test_cmp expect actual
2275'
2276
2277test_expect_success '--no-merged show unmerged tags' '
2278 cat >expect <<-\EOF &&
2279 mergetest-3
2280 EOF
2281 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2282 test_cmp expect actual
2283'
2284
2285test_expect_success '--no-merged can be used in non-list mode' '
2286 git tag --no-merged=mergetest-2 mergetest-* >actual &&
2287 test_cmp expect actual
2288'
2289
2290test_expect_success 'ambiguous branch/tags not marked' '
2291 git tag ambiguous &&
2292 git branch ambiguous &&
2293 echo ambiguous >expect &&
2294 git tag -l ambiguous >actual &&
2295 test_cmp expect actual
2296'
2297
2298test_expect_success '--contains combined with --no-contains' '
2299 (
2300 git init no-contains &&
2301 cd no-contains &&
2302 test_commit v0.1 &&
2303 test_commit v0.2 &&
2304 test_commit v0.3 &&
2305 test_commit v0.4 &&
2306 test_commit v0.5 &&
2307 cat >expected <<-\EOF &&
2308 v0.2
2309 v0.3
2310 v0.4
2311 EOF
2312 git tag --contains v0.2 --no-contains v0.5 >actual &&
2313 test_cmp expected actual
2314 )
2315'
2316
2317# As the docs say, list tags which contain a specified *commit*. We
2318# don't recurse down to tags for trees or blobs pointed to by *those*
2319# commits.
2320test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2321 (
2322 cd no-contains &&
2323 blob=$(git rev-parse v0.3:v0.3.t) &&
2324 tree=$(git rev-parse v0.3^{tree}) &&
2325 git tag tag-blob $blob &&
2326 git tag tag-tree $tree &&
2327 git tag --contains v0.3 >actual &&
2328 cat >expected <<-\EOF &&
2329 v0.3
2330 v0.4
2331 v0.5
2332 EOF
2333 test_cmp expected actual &&
2334 git tag --no-contains v0.3 >actual &&
2335 cat >expected <<-\EOF &&
2336 v0.1
2337 v0.2
2338 EOF
2339 test_cmp expected actual
2340 )
2341'
2342
2343test_expect_success 'If tag is created then tag message file is unlinked' '
2344 test_when_finished "git tag -d foo" &&
2345 write_script fakeeditor <<-\EOF &&
2346 echo Message >.git/TAG_EDITMSG
2347 EOF
2348 GIT_EDITOR=./fakeeditor git tag -a foo &&
2349 test_path_is_missing .git/TAG_EDITMSG
2350'
2351
2352test_expect_success 'If tag cannot be created then tag message file is not unlinked' '
2353 test_when_finished "git tag -d foo/bar && rm .git/TAG_EDITMSG" &&
2354 write_script fakeeditor <<-\EOF &&
2355 echo Message >.git/TAG_EDITMSG
2356 EOF
2357 git tag foo/bar &&
2358 test_must_fail env GIT_EDITOR=./fakeeditor git tag -a foo &&
2359 test_path_exists .git/TAG_EDITMSG
2360'
2361
2362test_expect_success 'annotated tag version sort' '
2363 git tag -a -m "sample 1.0" vsample-1.0 &&
2364 git tag -a -m "sample 2.0" vsample-2.0 &&
2365 git tag -a -m "sample 10.0" vsample-10.0 &&
2366 cat >expect <<-EOF &&
2367 vsample-1.0
2368 vsample-2.0
2369 vsample-10.0
2370 EOF
2371
2372 git tag --list --sort=version:tag vsample-\* >actual &&
2373 test_cmp expect actual &&
2374
2375 # Ensure that we also handle this case alright in the case we have the
2376 # peeled values cached e.g. via the packed-refs file.
2377 git pack-refs --all &&
2378 git tag --list --sort=version:tag vsample-\* &&
2379 test_cmp expect actual
2380'
2381
2382test_done