1#!/bin/sh 2# 3# Copyright (c) 2007 Carlos Rica 4# 5 6test_description='git tag 7 8Tests for operations with tags.' 9 10. ./test-lib.sh 11. "$TEST_DIRECTORY"/lib-gpg.sh 12. "$TEST_DIRECTORY"/lib-terminal.sh 13 14# creating and listing lightweight tags: 15 16tag_exists () { 17 git show-ref --quiet --verify refs/tags/"$1" 18} 19 20test_expect_success 'listing all tags in an empty tree should succeed'' 21 git tag -l && 22 git tag 23' 24 25test_expect_success 'listing all tags in an empty tree should output nothing'' 26 test$(git tag -l | wc -l)-eq 0 && 27 test$(git tag | wc -l)-eq 0 28' 29 30test_expect_success 'sort tags, ignore case'' 31 ( 32 git init sort && 33 cd sort && 34 test_commit initial && 35 git tag tag-one && 36 git tag TAG-two && 37 git tag -l >actual && 38 cat >expected <<-\EOF && 39 TAG-two 40 initial 41 tag-one 42 EOF 43 test_cmp expected actual && 44 git tag -l -i >actual && 45 cat >expected <<-\EOF && 46 initial 47 tag-one 48 TAG-two 49 EOF 50 test_cmp expected actual 51 ) 52' 53 54test_expect_success 'looking for a tag in an empty tree should fail' \ 55'! (tag_exists mytag)' 56 57test_expect_success 'creating a tag in an empty tree should fail'' 58 test_must_fail git tag mynotag && 59 ! tag_exists mynotag 60' 61 62test_expect_success 'creating a tag for HEAD in an empty tree should fail'' 63 test_must_fail git tag mytaghead HEAD && 64 ! tag_exists mytaghead 65' 66 67test_expect_success 'creating a tag for an unknown revision should fail'' 68 test_must_fail git tag mytagnorev aaaaaaaaaaa && 69 ! tag_exists mytagnorev 70' 71 72# commit used in the tests, test_tick is also called here to freeze the date: 73test_expect_success 'creating a tag using default HEAD should succeed'' 74 test_config core.logAllRefUpdates true && 75 test_tick && 76 echo foo >foo && 77 git add foo && 78 git commit -m Foo && 79 git tag mytag && 80 test_must_fail git reflog exists refs/tags/mytag 81' 82 83test_expect_success 'creating a tag with --create-reflog should create reflog'' 84 git log -1 \ 85 --format="format:tag: tagging %h (%s, %cd)%n" \ 86 --date=format:%Y-%m-%d >expected && 87 test_when_finished "git tag -d tag_with_reflog" && 88 git tag --create-reflog tag_with_reflog && 89 git reflog exists refs/tags/tag_with_reflog && 90 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && 91 test_i18ncmp expected actual 92' 93 94test_expect_success 'annotated tag with --create-reflog has correct message'' 95 git log -1 \ 96 --format="format:tag: tagging %h (%s, %cd)%n" \ 97 --date=format:%Y-%m-%d >expected && 98 test_when_finished "git tag -d tag_with_reflog" && 99 git tag -m "annotated tag" --create-reflog tag_with_reflog && 100 git reflog exists refs/tags/tag_with_reflog && 101 sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && 102 test_i18ncmp expected actual 103' 104 105test_expect_success '--create-reflog does not create reflog on failure'' 106 test_must_fail git tag --create-reflog mytag && 107 test_must_fail git reflog exists refs/tags/mytag 108' 109 110test_expect_success 'option core.logAllRefUpdates=always creates reflog'' 111 test_when_finished "git tag -d tag_with_reflog" && 112 test_config core.logAllRefUpdates always && 113 git tag tag_with_reflog && 114 git reflog exists refs/tags/tag_with_reflog 115' 116 117test_expect_success 'listing all tags if one exists should succeed'' 118 git tag -l && 119 git tag 120' 121 122cat>expect <<EOF 123mytag 124EOF 125test_expect_success 'Multiple -l or --list options are equivalent to one -l option'' 126 git tag -l -l >actual && 127 test_cmp expect actual && 128 git tag --list --list >actual && 129 test_cmp expect actual && 130 git tag --list -l --list >actual && 131 test_cmp expect actual 132' 133 134test_expect_success 'listing all tags if one exists should output that tag'' 135 test$(git tag -l)= mytag && 136 test$(git tag)= mytag 137' 138 139# pattern matching: 140 141test_expect_success 'listing a tag using a matching pattern should succeed' \ 142'git tag -l mytag' 143 144test_expect_success 'listing a tag with --ignore-case' \ 145'test$(git tag -l --ignore-case MYTAG)= mytag' 146 147test_expect_success \ 148'listing a tag using a matching pattern should output that tag' \ 149'test$(git tag -l mytag)= mytag' 150 151test_expect_success \ 152'listing tags using a non-matching pattern should succeed' \ 153'git tag -l xxx' 154 155test_expect_success \ 156'listing tags using a non-matching pattern should output nothing' \ 157'test$(git tag -l xxx | wc -l)-eq 0' 158 159# special cases for creating tags: 160 161test_expect_success \ 162'trying to create a tag with the name of one existing should fail' \ 163'test_must_fail git tag mytag' 164 165test_expect_success \ 166'trying to create a tag with a non-valid name should fail'' 167 test$(git tag -l | wc -l)-eq 1 && 168 test_must_fail git tag "" && 169 test_must_fail git tag .othertag && 170 test_must_fail git tag "other tag" && 171 test_must_fail git tag "othertag^" && 172 test_must_fail git tag "other~tag" && 173 test$(git tag -l | wc -l)-eq 1 174' 175 176test_expect_success 'creating a tag using HEAD directly should succeed'' 177 git tag myhead HEAD && 178 tag_exists myhead 179' 180 181test_expect_success '--force can create a tag with the name of one existing'' 182 tag_exists mytag && 183 git tag --force mytag && 184 tag_exists mytag' 185 186test_expect_success '--force is moot with a non-existing tag name'' 187 test_when_finished git tag -d newtag forcetag && 188 git tag newtag >expect && 189 git tag --force forcetag >actual && 190 test_cmp expect actual 191' 192 193# deleting tags: 194 195test_expect_success 'trying to delete an unknown tag should fail'' 196 ! tag_exists unknown-tag && 197 test_must_fail git tag -d unknown-tag 198' 199 200cat>expect <<EOF 201myhead 202mytag 203EOF 204test_expect_success \ 205'trying to delete tags without params should succeed and do nothing'' 206 git tag -l > actual && test_cmp expect actual && 207 git tag -d && 208 git tag -l > actual && test_cmp expect actual 209' 210 211test_expect_success \ 212'deleting two existing tags in one command should succeed'' 213 tag_exists mytag && 214 tag_exists myhead && 215 git tag -d mytag myhead && 216 ! tag_exists mytag && 217 ! tag_exists myhead 218' 219 220test_expect_success \ 221'creating a tag with the name of another deleted one should succeed'' 222 ! tag_exists mytag && 223 git tag mytag && 224 tag_exists mytag 225' 226 227test_expect_success \ 228'trying to delete two tags, existing and not, should fail in the 2nd'' 229 tag_exists mytag && 230 ! tag_exists myhead && 231 test_must_fail git tag -d mytag anothertag && 232 ! tag_exists mytag && 233 ! tag_exists myhead 234' 235 236test_expect_success 'trying to delete an already deleted tag should fail' \ 237'test_must_fail git tag -d mytag' 238 239# listing various tags with pattern matching: 240 241cat>expect <<EOF 242a1 243aa1 244cba 245t210 246t211 247v0.2.1 248v1.0 249v1.0.1 250v1.1.3 251EOF 252test_expect_success 'listing all tags should print them ordered'' 253 git tag v1.0.1 && 254 git tag t211 && 255 git tag aa1 && 256 git tag v0.2.1 && 257 git tag v1.1.3 && 258 git tag cba && 259 git tag a1 && 260 git tag v1.0 && 261 git tag t210 && 262 git tag -l > actual && 263 test_cmp expect actual && 264 git tag > actual && 265 test_cmp expect actual 266' 267 268cat>expect <<EOF 269a1 270aa1 271cba 272EOF 273test_expect_success \ 274'listing tags with substring as pattern must print those matching'' 275 rm *a* && 276 git tag -l "*a*" > current && 277 test_cmp expect current 278' 279 280cat>expect <<EOF 281v0.2.1 282v1.0.1 283EOF 284test_expect_success \ 285'listing tags with a suffix as pattern must print those matching'' 286 git tag -l "*.1" > actual && 287 test_cmp expect actual 288' 289 290cat>expect <<EOF 291t210 292t211 293EOF 294test_expect_success \ 295'listing tags with a prefix as pattern must print those matching'' 296 git tag -l "t21*" > actual && 297 test_cmp expect actual 298' 299 300cat>expect <<EOF 301a1 302EOF 303test_expect_success \ 304'listing tags using a name as pattern must print that one matching'' 305 git tag -l a1 > actual && 306 test_cmp expect actual 307' 308 309cat>expect <<EOF 310v1.0 311EOF 312test_expect_success \ 313'listing tags using a name as pattern must print that one matching'' 314 git tag -l v1.0 > actual && 315 test_cmp expect actual 316' 317 318cat>expect <<EOF 319v1.0.1 320v1.1.3 321EOF 322test_expect_success \ 323'listing tags with ? in the pattern should print those matching'' 324 git tag -l "v1.?.?" > actual && 325 test_cmp expect actual 326' 327 328test_expect_success \ 329'listing tags using v.* should print nothing because none have v.'' 330 git tag -l "v.*" > actual && 331 test_must_be_empty actual 332' 333 334cat>expect <<EOF 335v0.2.1 336v1.0 337v1.0.1 338v1.1.3 339EOF 340test_expect_success \ 341'listing tags using v* should print only those having v'' 342 git tag -l "v*" > actual && 343 test_cmp expect actual 344' 345 346test_expect_success 'tag -l can accept multiple patterns'' 347 git tag -l "v1*" "v0*" >actual && 348 test_cmp expect actual 349' 350 351# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation 352# could leave you with the impression that "-l <pattern> -l <pattern>" 353# was how we wanted to accept multiple patterns. 354# 355# This test should not imply that this is a sane thing to support. but 356# since the documentation was worded like it was let's at least find 357# out if we're going to break this long-documented form of taking 358# multiple patterns. 359test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested'' 360 git tag -l "v1*" -l "v0*" >actual && 361 test_cmp expect actual 362' 363 364test_expect_success 'listing tags in column'' 365 COLUMNS=41 git tag -l --column=row >actual && 366 cat >expected <<\EOF && 367a1 aa1 cba t210 t211 368v0.2.1 v1.0 v1.0.1 v1.1.3 369EOF 370 test_cmp expected actual 371' 372 373test_expect_success 'listing tags in column with column.*'' 374 test_config column.tag row && 375 test_config column.ui dense && 376 COLUMNS=40 git tag -l >actual && 377 cat >expected <<\EOF && 378a1 aa1 cba t210 t211 379v0.2.1 v1.0 v1.0.1 v1.1.3 380EOF 381 test_cmp expected actual 382' 383 384test_expect_success 'listing tag with -n --column should fail'' 385 test_must_fail git tag --column -n 386' 387 388test_expect_success 'listing tags -n in column with column.ui ignored'' 389 test_config column.ui "row dense" && 390 COLUMNS=40 git tag -l -n >actual && 391 cat >expected <<\EOF && 392a1 Foo 393aa1 Foo 394cba Foo 395t210 Foo 396t211 Foo 397v0.2.1 Foo 398v1.0 Foo 399v1.0.1 Foo 400v1.1.3 Foo 401EOF 402 test_cmp expected actual 403' 404 405# creating and verifying lightweight tags: 406 407test_expect_success \ 408'a non-annotated tag created without parameters should point to HEAD'' 409 git tag non-annotated-tag && 410 test$(git cat-file -t non-annotated-tag)= commit && 411 test$(git rev-parse non-annotated-tag)=$(git rev-parse HEAD) 412' 413 414test_expect_success 'trying to verify an unknown tag should fail' \ 415'test_must_fail git tag -v unknown-tag' 416 417test_expect_success \ 418'trying to verify a non-annotated and non-signed tag should fail' \ 419'test_must_fail git tag -v non-annotated-tag' 420 421test_expect_success \ 422'trying to verify many non-annotated or unknown tags, should fail' \ 423'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' 424 425# creating annotated tags: 426 427get_tag_msg () { 428 git cat-file tag "$1"|sed-e"/BEGIN PGP/q" 429} 430 431# run test_tick before committing always gives the time in that timezone 432get_tag_header () { 433cat<<EOF 434object$2 435type$3 436tag$1 437tagger C O Mitter <committer@example.com>$4-0700 438 439EOF 440} 441 442commit=$(git rev-parse HEAD) 443time=$test_tick 444 445get_tag_header annotated-tag$commit commit $time>expect 446echo"A message">>expect 447test_expect_success \ 448'creating an annotated tag with -m message should succeed'' 449 git tag -m "A message" annotated-tag && 450 get_tag_msg annotated-tag >actual && 451 test_cmp expect actual 452' 453 454get_tag_header annotated-tag-edit$commit commit $time>expect 455echo"An edited message">>expect 456test_expect_success 'set up editor'' 457 write_script fakeeditor <<-\EOF 458 sed -e "s/A message/An edited message/g" <"$1" >"$1-" 459 mv "$1-" "$1" 460 EOF 461' 462test_expect_success \ 463'creating an annotated tag with -m message --edit should succeed'' 464 GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit && 465 get_tag_msg annotated-tag-edit >actual && 466 test_cmp expect actual 467' 468 469cat>msgfile <<EOF 470Another message 471in a file. 472EOF 473get_tag_header file-annotated-tag$commit commit $time>expect 474cat msgfile >>expect 475test_expect_success \ 476'creating an annotated tag with -F messagefile should succeed'' 477 git tag -F msgfile file-annotated-tag && 478 get_tag_msg file-annotated-tag >actual && 479 test_cmp expect actual 480' 481 482get_tag_header file-annotated-tag-edit$commit commit $time>expect 483sed-e"s/Another message/Another edited message/g" msgfile >>expect 484test_expect_success 'set up editor'' 485 write_script fakeeditor <<-\EOF 486 sed -e "s/Another message/Another edited message/g" <"$1" >"$1-" 487 mv "$1-" "$1" 488 EOF 489' 490test_expect_success \ 491'creating an annotated tag with -F messagefile --edit should succeed'' 492 GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit && 493 get_tag_msg file-annotated-tag-edit >actual && 494 test_cmp expect actual 495' 496 497cat>inputmsg <<EOF 498A message from the 499standard input 500EOF 501get_tag_header stdin-annotated-tag$commit commit $time>expect 502cat inputmsg >>expect 503test_expect_success 'creating an annotated tag with -F - should succeed'' 504 git tag -F - stdin-annotated-tag <inputmsg && 505 get_tag_msg stdin-annotated-tag >actual && 506 test_cmp expect actual 507' 508 509test_expect_success \ 510'trying to create a tag with a non-existing -F file should fail'' 511 ! test -f nonexistingfile && 512 ! tag_exists notag && 513 test_must_fail git tag -F nonexistingfile notag && 514 ! tag_exists notag 515' 516 517test_expect_success \ 518'trying to create tags giving both -m or -F options should fail'' 519 echo "message file 1" >msgfile1 && 520 echo "message file 2" >msgfile2 && 521 ! tag_exists msgtag && 522 test_must_fail git tag -m "message 1" -F msgfile1 msgtag && 523 ! tag_exists msgtag && 524 test_must_fail git tag -F msgfile1 -m "message 1" msgtag && 525 ! tag_exists msgtag && 526 test_must_fail git tag -m "message 1" -F msgfile1 \ 527 -m "message 2" msgtag && 528 ! tag_exists msgtag 529' 530 531# blank and empty messages: 532 533get_tag_header empty-annotated-tag$commit commit $time>expect 534test_expect_success \ 535'creating a tag with an empty -m message should succeed'' 536 git tag -m "" empty-annotated-tag && 537 get_tag_msg empty-annotated-tag >actual && 538 test_cmp expect actual 539' 540 541>emptyfile 542get_tag_header emptyfile-annotated-tag$commit commit $time>expect 543test_expect_success \ 544'creating a tag with an empty -F messagefile should succeed'' 545 git tag -F emptyfile emptyfile-annotated-tag && 546 get_tag_msg emptyfile-annotated-tag >actual && 547 test_cmp expect actual 548' 549 550printf'\n\n \n\t\nLeading blank lines\n'>blanksfile 551printf'\n\t \t \nRepeated blank lines\n'>>blanksfile 552printf'\n\n\nTrailing spaces\t \n'>>blanksfile 553printf'\nTrailing blank lines\n\n\t \n\n'>>blanksfile 554get_tag_header blanks-annotated-tag$commit commit $time>expect 555cat>>expect <<EOF 556Leading blank lines 557 558Repeated blank lines 559 560Trailing spaces 561 562Trailing blank lines 563EOF 564test_expect_success \ 565'extra blanks in the message for an annotated tag should be removed'' 566 git tag -F blanksfile blanks-annotated-tag && 567 get_tag_msg blanks-annotated-tag >actual && 568 test_cmp expect actual 569' 570 571get_tag_header blank-annotated-tag$commit commit $time>expect 572test_expect_success \ 573'creating a tag with blank -m message with spaces should succeed'' 574 git tag -m " " blank-annotated-tag && 575 get_tag_msg blank-annotated-tag >actual && 576 test_cmp expect actual 577' 578 579echo' '>blankfile 580echo''>>blankfile 581echo' '>>blankfile 582get_tag_header blankfile-annotated-tag$commit commit $time>expect 583test_expect_success \ 584'creating a tag with blank -F messagefile with spaces should succeed'' 585 git tag -F blankfile blankfile-annotated-tag && 586 get_tag_msg blankfile-annotated-tag >actual && 587 test_cmp expect actual 588' 589 590printf' '>blanknonlfile 591get_tag_header blanknonlfile-annotated-tag$commit commit $time>expect 592test_expect_success \ 593'creating a tag with -F file of spaces and no newline should succeed'' 594 git tag -F blanknonlfile blanknonlfile-annotated-tag && 595 get_tag_msg blanknonlfile-annotated-tag >actual && 596 test_cmp expect actual 597' 598 599# messages with commented lines: 600 601cat>commentsfile <<EOF 602# A comment 603 604############ 605The message. 606############ 607One line. 608 609 610# commented lines 611# commented lines 612 613Another line. 614# comments 615 616Last line. 617EOF 618get_tag_header comments-annotated-tag$commit commit $time>expect 619cat>>expect <<EOF 620The message. 621One line. 622 623Another line. 624 625Last line. 626EOF 627test_expect_success \ 628'creating a tag using a -F messagefile with #comments should succeed'' 629 git tag -F commentsfile comments-annotated-tag && 630 get_tag_msg comments-annotated-tag >actual && 631 test_cmp expect actual 632' 633 634get_tag_header comment-annotated-tag$commit commit $time>expect 635test_expect_success \ 636'creating a tag with a #comment in the -m message should succeed'' 637 git tag -m "#comment" comment-annotated-tag && 638 get_tag_msg comment-annotated-tag >actual && 639 test_cmp expect actual 640' 641 642echo'#comment'>commentfile 643echo''>>commentfile 644echo'####'>>commentfile 645get_tag_header commentfile-annotated-tag$commit commit $time>expect 646test_expect_success \ 647'creating a tag with #comments in the -F messagefile should succeed'' 648 git tag -F commentfile commentfile-annotated-tag && 649 get_tag_msg commentfile-annotated-tag >actual && 650 test_cmp expect actual 651' 652 653printf'#comment'>commentnonlfile 654get_tag_header commentnonlfile-annotated-tag$commit commit $time>expect 655test_expect_success \ 656'creating a tag with a file of #comment and no newline should succeed'' 657 git tag -F commentnonlfile commentnonlfile-annotated-tag && 658 get_tag_msg commentnonlfile-annotated-tag >actual && 659 test_cmp expect actual 660' 661 662# listing messages for annotated non-signed tags: 663 664test_expect_success \ 665'listing the one-line message of a non-signed tag should succeed'' 666 git tag -m "A msg" tag-one-line && 667 668 echo "tag-one-line" >expect && 669 git tag -l | grep "^tag-one-line" >actual && 670 test_cmp expect actual && 671 git tag -n0 -l | grep "^tag-one-line" >actual && 672 test_cmp expect actual && 673 git tag -n0 -l tag-one-line >actual && 674 test_cmp expect actual && 675 676 git tag -n0 | grep "^tag-one-line" >actual && 677 test_cmp expect actual && 678 git tag -n0 tag-one-line >actual && 679 test_cmp expect actual && 680 681 echo "tag-one-line A msg" >expect && 682 git tag -n1 -l | grep "^tag-one-line" >actual && 683 test_cmp expect actual && 684 git tag -n -l | grep "^tag-one-line" >actual && 685 test_cmp expect actual && 686 git tag -n1 -l tag-one-line >actual && 687 test_cmp expect actual && 688 git tag -n2 -l tag-one-line >actual && 689 test_cmp expect actual && 690 git tag -n999 -l tag-one-line >actual && 691 test_cmp expect actual 692' 693 694test_expect_success 'The -n 100 invocation means -n --list 100, not -n100'' 695 git tag -n 100 >actual && 696 test_must_be_empty actual && 697 698 git tag -m "A msg" 100 && 699 echo "100 A msg" >expect && 700 git tag -n 100 >actual && 701 test_cmp expect actual 702' 703 704test_expect_success \ 705'listing the zero-lines message of a non-signed tag should succeed'' 706 git tag -m "" tag-zero-lines && 707 708 echo "tag-zero-lines" >expect && 709 git tag -l | grep "^tag-zero-lines" >actual && 710 test_cmp expect actual && 711 git tag -n0 -l | grep "^tag-zero-lines" >actual && 712 test_cmp expect actual && 713 git tag -n0 -l tag-zero-lines >actual && 714 test_cmp expect actual && 715 716 echo "tag-zero-lines " >expect && 717 git tag -n1 -l | grep "^tag-zero-lines" >actual && 718 test_cmp expect actual && 719 git tag -n -l | grep "^tag-zero-lines" >actual && 720 test_cmp expect actual && 721 git tag -n1 -l tag-zero-lines >actual && 722 test_cmp expect actual && 723 git tag -n2 -l tag-zero-lines >actual && 724 test_cmp expect actual && 725 git tag -n999 -l tag-zero-lines >actual && 726 test_cmp expect actual 727' 728 729echo'tag line one'>annotagmsg 730echo'tag line two'>>annotagmsg 731echo'tag line three'>>annotagmsg 732test_expect_success \ 733'listing many message lines of a non-signed tag should succeed'' 734 git tag -F annotagmsg tag-lines && 735 736 echo "tag-lines" >expect && 737 git tag -l | grep "^tag-lines" >actual && 738 test_cmp expect actual && 739 git tag -n0 -l | grep "^tag-lines" >actual && 740 test_cmp expect actual && 741 git tag -n0 -l tag-lines >actual && 742 test_cmp expect actual && 743 744 echo "tag-lines tag line one" >expect && 745 git tag -n1 -l | grep "^tag-lines" >actual && 746 test_cmp expect actual && 747 git tag -n -l | grep "^tag-lines" >actual && 748 test_cmp expect actual && 749 git tag -n1 -l tag-lines >actual && 750 test_cmp expect actual && 751 752 echo " tag line two" >>expect && 753 git tag -n2 -l | grep "^ *tag.line" >actual && 754 test_cmp expect actual && 755 git tag -n2 -l tag-lines >actual && 756 test_cmp expect actual && 757 758 echo " tag line three" >>expect && 759 git tag -n3 -l | grep "^ *tag.line" >actual && 760 test_cmp expect actual && 761 git tag -n3 -l tag-lines >actual && 762 test_cmp expect actual && 763 git tag -n4 -l | grep "^ *tag.line" >actual && 764 test_cmp expect actual && 765 git tag -n4 -l tag-lines >actual && 766 test_cmp expect actual && 767 git tag -n99 -l | grep "^ *tag.line" >actual && 768 test_cmp expect actual && 769 git tag -n99 -l tag-lines >actual && 770 test_cmp expect actual 771' 772 773test_expect_success 'annotations for blobs are empty'' 774 blob=$(git hash-object -w --stdin <<-\EOF 775 Blob paragraph 1. 776 777 Blob paragraph 2. 778 EOF 779 ) && 780 git tag tag-blob$blob&& 781 echo "tag-blob " >expect && 782 git tag -n1 -l tag-blob >actual && 783 test_cmp expect actual 784' 785 786# trying to verify annotated non-signed tags: 787 788test_expect_success GPG \ 789'trying to verify an annotated non-signed tag should fail'' 790 tag_exists annotated-tag && 791 test_must_fail git tag -v annotated-tag 792' 793 794test_expect_success GPG \ 795'trying to verify a file-annotated non-signed tag should fail'' 796 tag_exists file-annotated-tag && 797 test_must_fail git tag -v file-annotated-tag 798' 799 800test_expect_success GPG \ 801'trying to verify two annotated non-signed tags should fail'' 802 tag_exists annotated-tag file-annotated-tag && 803 test_must_fail git tag -v annotated-tag file-annotated-tag 804' 805 806# creating and verifying signed tags: 807 808get_tag_header signed-tag$commit commit $time>expect 809echo'A signed tag message'>>expect 810echo'-----BEGIN PGP SIGNATURE-----'>>expect 811test_expect_success GPG 'creating a signed tag with -m message should succeed'' 812 git tag -s -m "A signed tag message" signed-tag && 813 get_tag_msg signed-tag >actual && 814 test_cmp expect actual 815' 816 817get_tag_header u-signed-tag$commit commit $time>expect 818echo'Another message'>>expect 819echo'-----BEGIN PGP SIGNATURE-----'>>expect 820test_expect_success GPG 'sign with a given key id'' 821 822 git tag -u committer@example.com -m "Another message" u-signed-tag && 823 get_tag_msg u-signed-tag >actual && 824 test_cmp expect actual 825 826' 827 828test_expect_success GPG 'sign with an unknown id (1)'' 829 830 test_must_fail git tag -u author@example.com \ 831 -m "Another message" o-signed-tag 832 833' 834 835test_expect_success GPG 'sign with an unknown id (2)'' 836 837 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag 838 839' 840 841cat>fakeeditor <<'EOF' 842#!/bin/sh 843test -n "$1" && exec >"$1" 844echo A signed tag message 845echo from a fake editor. 846EOF 847chmod+x fakeeditor 848 849get_tag_header implied-sign$commit commit $time>expect 850./fakeeditor >>expect 851echo'-----BEGIN PGP SIGNATURE-----'>>expect 852test_expect_success GPG '-u implies signed tag'' 853 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && 854 get_tag_msg implied-sign >actual && 855 test_cmp expect actual 856' 857 858cat>sigmsgfile <<EOF 859Another signed tag 860message in a file. 861EOF 862get_tag_header file-signed-tag$commit commit $time>expect 863cat sigmsgfile >>expect 864echo'-----BEGIN PGP SIGNATURE-----'>>expect 865test_expect_success GPG \ 866'creating a signed tag with -F messagefile should succeed'' 867 git tag -s -F sigmsgfile file-signed-tag && 868 get_tag_msg file-signed-tag >actual && 869 test_cmp expect actual 870' 871 872cat>siginputmsg <<EOF 873A signed tag message from 874the standard input 875EOF 876get_tag_header stdin-signed-tag$commit commit $time>expect 877cat siginputmsg >>expect 878echo'-----BEGIN PGP SIGNATURE-----'>>expect 879test_expect_success GPG 'creating a signed tag with -F - should succeed'' 880 git tag -s -F - stdin-signed-tag <siginputmsg && 881 get_tag_msg stdin-signed-tag >actual && 882 test_cmp expect actual 883' 884 885get_tag_header implied-annotate$commit commit $time>expect 886./fakeeditor >>expect 887echo'-----BEGIN PGP SIGNATURE-----'>>expect 888test_expect_success GPG '-s implies annotated tag'' 889 GIT_EDITOR=./fakeeditor git tag -s implied-annotate && 890 get_tag_msg implied-annotate >actual && 891 test_cmp expect actual 892' 893 894get_tag_header forcesignannotated-implied-sign$commit commit $time>expect 895echo"A message">>expect 896echo'-----BEGIN PGP SIGNATURE-----'>>expect 897test_expect_success GPG \ 898'git tag -s implied if configured with tag.forcesignannotated' \ 899'test_config tag.forcesignannotated true && 900 git tag -m "A message" forcesignannotated-implied-sign && 901 get_tag_msg forcesignannotated-implied-sign >actual && 902 test_cmp expect actual 903' 904 905test_expect_success GPG \ 906'lightweight with no message when configured with tag.forcesignannotated' \ 907'test_config tag.forcesignannotated true && 908 git tag forcesignannotated-lightweight && 909 tag_exists forcesignannotated-lightweight && 910 test_must_fail git tag -v forcesignannotated-no-message 911' 912 913get_tag_header forcesignannotated-annotate$commit commit $time>expect 914echo"A message">>expect 915test_expect_success GPG \ 916'git tag -a disable configured tag.forcesignannotated' \ 917'test_config tag.forcesignannotated true && 918 git tag -a -m "A message" forcesignannotated-annotate && 919 get_tag_msg forcesignannotated-annotate >actual && 920 test_cmp expect actual && 921 test_must_fail git tag -v forcesignannotated-annotate 922' 923 924get_tag_header forcesignannotated-disabled$commit commit $time>expect 925echo"A message">>expect 926echo'-----BEGIN PGP SIGNATURE-----'>>expect 927test_expect_success GPG \ 928'git tag --sign enable GPG sign' \ 929'test_config tag.forcesignannotated false && 930 git tag --sign -m "A message" forcesignannotated-disabled && 931 get_tag_msg forcesignannotated-disabled >actual && 932 test_cmp expect actual 933' 934 935get_tag_header gpgsign-enabled$commit commit $time>expect 936echo"A message">>expect 937echo'-----BEGIN PGP SIGNATURE-----'>>expect 938test_expect_success GPG \ 939'git tag configured tag.gpgsign enables GPG sign' \ 940'test_config tag.gpgsign true && 941 git tag -m "A message" gpgsign-enabled && 942 get_tag_msg gpgsign-enabled>actual && 943 test_cmp expect actual 944' 945 946get_tag_header no-sign$commit commit $time>expect 947echo"A message">>expect 948test_expect_success GPG \ 949'git tag --no-sign configured tag.gpgsign skip GPG sign' \ 950'test_config tag.gpgsign true && 951 git tag -a --no-sign -m "A message" no-sign && 952 get_tag_msg no-sign>actual && 953 test_cmp expect actual 954' 955 956test_expect_success GPG \ 957'trying to create a signed tag with non-existing -F file should fail'' 958 ! test -f nonexistingfile && 959 ! tag_exists nosigtag && 960 test_must_fail git tag -s -F nonexistingfile nosigtag && 961 ! tag_exists nosigtag 962' 963 964test_expect_success GPG 'verifying a signed tag should succeed' \ 965'git tag -v signed-tag' 966 967test_expect_success GPG 'verifying two signed tags in one command should succeed' \ 968'git tag -v signed-tag file-signed-tag' 969 970test_expect_success GPG \ 971'verifying many signed and non-signed tags should fail'' 972 test_must_fail git tag -v signed-tag annotated-tag && 973 test_must_fail git tag -v file-annotated-tag file-signed-tag && 974 test_must_fail git tag -v annotated-tag \ 975 file-signed-tag file-annotated-tag && 976 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag 977' 978 979test_expect_success GPG 'verifying a forged tag should fail'' 980 forged=$(git cat-file tag signed-tag | 981 sed -e "s/signed-tag/forged-tag/" | 982 git mktag) && 983 git tag forged-tag$forged&& 984 test_must_fail git tag -v forged-tag 985' 986 987test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly'' 988 cat >expect <<-\EOF && 989 tagname : signed-tag 990 EOF 991 git tag -v --format="tagname : %(tag)" "signed-tag" >actual && 992 test_cmp expect actual 993' 994 995test_expect_success GPG 'verifying a forged tag with --format should fail silently'' 996 test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual && 997 test_must_be_empty actual 998' 9991000# blank and empty messages for signed tags:10011002get_tag_header empty-signed-tag$commit commit $time>expect1003echo'-----BEGIN PGP SIGNATURE-----'>>expect1004test_expect_success GPG \1005'creating a signed tag with an empty -m message should succeed''1006 git tag -s -m "" empty-signed-tag &&1007 get_tag_msg empty-signed-tag >actual &&1008 test_cmp expect actual &&1009 git tag -v empty-signed-tag1010'10111012>sigemptyfile1013get_tag_header emptyfile-signed-tag$commit commit $time>expect1014echo'-----BEGIN PGP SIGNATURE-----'>>expect1015test_expect_success GPG \1016'creating a signed tag with an empty -F messagefile should succeed''1017 git tag -s -F sigemptyfile emptyfile-signed-tag &&1018 get_tag_msg emptyfile-signed-tag >actual &&1019 test_cmp expect actual &&1020 git tag -v emptyfile-signed-tag1021'10221023printf'\n\n \n\t\nLeading blank lines\n'> sigblanksfile1024printf'\n\t \t \nRepeated blank lines\n'>>sigblanksfile1025printf'\n\n\nTrailing spaces\t \n'>>sigblanksfile1026printf'\nTrailing blank lines\n\n\t \n\n'>>sigblanksfile1027get_tag_header blanks-signed-tag$commit commit $time>expect1028cat>>expect <<EOF1029Leading blank lines10301031Repeated blank lines10321033Trailing spaces10341035Trailing blank lines1036EOF1037echo'-----BEGIN PGP SIGNATURE-----'>>expect1038test_expect_success GPG \1039'extra blanks in the message for a signed tag should be removed''1040 git tag -s -F sigblanksfile blanks-signed-tag &&1041 get_tag_msg blanks-signed-tag >actual &&1042 test_cmp expect actual &&1043 git tag -v blanks-signed-tag1044'10451046get_tag_header blank-signed-tag$commit commit $time>expect1047echo'-----BEGIN PGP SIGNATURE-----'>>expect1048test_expect_success GPG \1049'creating a signed tag with a blank -m message should succeed''1050 git tag -s -m " " blank-signed-tag &&1051 get_tag_msg blank-signed-tag >actual &&1052 test_cmp expect actual &&1053 git tag -v blank-signed-tag1054'10551056echo' '>sigblankfile1057echo''>>sigblankfile1058echo' '>>sigblankfile1059get_tag_header blankfile-signed-tag$commit commit $time>expect1060echo'-----BEGIN PGP SIGNATURE-----'>>expect1061test_expect_success GPG \1062'creating a signed tag with blank -F file with spaces should succeed''1063 git tag -s -F sigblankfile blankfile-signed-tag &&1064 get_tag_msg blankfile-signed-tag >actual &&1065 test_cmp expect actual &&1066 git tag -v blankfile-signed-tag1067'10681069printf' '>sigblanknonlfile1070get_tag_header blanknonlfile-signed-tag$commit commit $time>expect1071echo'-----BEGIN PGP SIGNATURE-----'>>expect1072test_expect_success GPG \1073'creating a signed tag with spaces and no newline should succeed''1074 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&1075 get_tag_msg blanknonlfile-signed-tag >actual &&1076 test_cmp expect actual &&1077 git tag -v blanknonlfile-signed-tag1078'10791080test_expect_success GPG 'signed tag with embedded PGP message''1081 cat >msg <<-\EOF &&1082 -----BEGIN PGP MESSAGE-----10831084 this is not a real PGP message1085 -----END PGP MESSAGE-----1086 EOF1087 git tag -s -F msg confusing-pgp-message &&1088 git tag -v confusing-pgp-message1089'10901091# messages with commented lines for signed tags:10921093cat>sigcommentsfile <<EOF1094# A comment10951096############1097The message.1098############1099One line.110011011102# commented lines1103# commented lines11041105Another line.1106# comments11071108Last line.1109EOF1110get_tag_header comments-signed-tag$commit commit $time>expect1111cat>>expect <<EOF1112The message.1113One line.11141115Another line.11161117Last line.1118EOF1119echo'-----BEGIN PGP SIGNATURE-----'>>expect1120test_expect_success GPG \1121'creating a signed tag with a -F file with #comments should succeed''1122 git tag -s -F sigcommentsfile comments-signed-tag &&1123 get_tag_msg comments-signed-tag >actual &&1124 test_cmp expect actual &&1125 git tag -v comments-signed-tag1126'11271128get_tag_header comment-signed-tag$commit commit $time>expect1129echo'-----BEGIN PGP SIGNATURE-----'>>expect1130test_expect_success GPG \1131'creating a signed tag with #commented -m message should succeed''1132 git tag -s -m "#comment" comment-signed-tag &&1133 get_tag_msg comment-signed-tag >actual &&1134 test_cmp expect actual &&1135 git tag -v comment-signed-tag1136'11371138echo'#comment'>sigcommentfile1139echo''>>sigcommentfile1140echo'####'>>sigcommentfile1141get_tag_header commentfile-signed-tag$commit commit $time>expect1142echo'-----BEGIN PGP SIGNATURE-----'>>expect1143test_expect_success GPG \1144'creating a signed tag with #commented -F messagefile should succeed''1145 git tag -s -F sigcommentfile commentfile-signed-tag &&1146 get_tag_msg commentfile-signed-tag >actual &&1147 test_cmp expect actual &&1148 git tag -v commentfile-signed-tag1149'11501151printf'#comment'>sigcommentnonlfile1152get_tag_header commentnonlfile-signed-tag$commit commit $time>expect1153echo'-----BEGIN PGP SIGNATURE-----'>>expect1154test_expect_success GPG \1155'creating a signed tag with a #comment and no newline should succeed''1156 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&1157 get_tag_msg commentnonlfile-signed-tag >actual &&1158 test_cmp expect actual &&1159 git tag -v commentnonlfile-signed-tag1160'11611162# listing messages for signed tags:11631164test_expect_success GPG \1165'listing the one-line message of a signed tag should succeed''1166 git tag -s -m "A message line signed" stag-one-line &&11671168 echo "stag-one-line" >expect &&1169 git tag -l | grep "^stag-one-line" >actual &&1170 test_cmp expect actual &&1171 git tag -n0 -l | grep "^stag-one-line" >actual &&1172 test_cmp expect actual &&1173 git tag -n0 -l stag-one-line >actual &&1174 test_cmp expect actual &&11751176 echo "stag-one-line A message line signed" >expect &&1177 git tag -n1 -l | grep "^stag-one-line" >actual &&1178 test_cmp expect actual &&1179 git tag -n -l | grep "^stag-one-line" >actual &&1180 test_cmp expect actual &&1181 git tag -n1 -l stag-one-line >actual &&1182 test_cmp expect actual &&1183 git tag -n2 -l stag-one-line >actual &&1184 test_cmp expect actual &&1185 git tag -n999 -l stag-one-line >actual &&1186 test_cmp expect actual1187'11881189test_expect_success GPG \1190'listing the zero-lines message of a signed tag should succeed''1191 git tag -s -m "" stag-zero-lines &&11921193 echo "stag-zero-lines" >expect &&1194 git tag -l | grep "^stag-zero-lines" >actual &&1195 test_cmp expect actual &&1196 git tag -n0 -l | grep "^stag-zero-lines" >actual &&1197 test_cmp expect actual &&1198 git tag -n0 -l stag-zero-lines >actual &&1199 test_cmp expect actual &&12001201 echo "stag-zero-lines " >expect &&1202 git tag -n1 -l | grep "^stag-zero-lines" >actual &&1203 test_cmp expect actual &&1204 git tag -n -l | grep "^stag-zero-lines" >actual &&1205 test_cmp expect actual &&1206 git tag -n1 -l stag-zero-lines >actual &&1207 test_cmp expect actual &&1208 git tag -n2 -l stag-zero-lines >actual &&1209 test_cmp expect actual &&1210 git tag -n999 -l stag-zero-lines >actual &&1211 test_cmp expect actual1212'12131214echo'stag line one'>sigtagmsg1215echo'stag line two'>>sigtagmsg1216echo'stag line three'>>sigtagmsg1217test_expect_success GPG \1218'listing many message lines of a signed tag should succeed''1219 git tag -s -F sigtagmsg stag-lines &&12201221 echo "stag-lines" >expect &&1222 git tag -l | grep "^stag-lines" >actual &&1223 test_cmp expect actual &&1224 git tag -n0 -l | grep "^stag-lines" >actual &&1225 test_cmp expect actual &&1226 git tag -n0 -l stag-lines >actual &&1227 test_cmp expect actual &&12281229 echo "stag-lines stag line one" >expect &&1230 git tag -n1 -l | grep "^stag-lines" >actual &&1231 test_cmp expect actual &&1232 git tag -n -l | grep "^stag-lines" >actual &&1233 test_cmp expect actual &&1234 git tag -n1 -l stag-lines >actual &&1235 test_cmp expect actual &&12361237 echo " stag line two" >>expect &&1238 git tag -n2 -l | grep "^ *stag.line" >actual &&1239 test_cmp expect actual &&1240 git tag -n2 -l stag-lines >actual &&1241 test_cmp expect actual &&12421243 echo " stag line three" >>expect &&1244 git tag -n3 -l | grep "^ *stag.line" >actual &&1245 test_cmp expect actual &&1246 git tag -n3 -l stag-lines >actual &&1247 test_cmp expect actual &&1248 git tag -n4 -l | grep "^ *stag.line" >actual &&1249 test_cmp expect actual &&1250 git tag -n4 -l stag-lines >actual &&1251 test_cmp expect actual &&1252 git tag -n99 -l | grep "^ *stag.line" >actual &&1253 test_cmp expect actual &&1254 git tag -n99 -l stag-lines >actual &&1255 test_cmp expect actual1256'12571258# tags pointing to objects different from commits:12591260tree=$(git rev-parse HEAD^{tree})1261blob=$(git rev-parse HEAD:foo)1262tag=$(git rev-parse signed-tag 2>/dev/null)12631264get_tag_header tree-signed-tag$tree tree $time>expect1265echo"A message for a tree">>expect1266echo'-----BEGIN PGP SIGNATURE-----'>>expect1267test_expect_success GPG \1268'creating a signed tag pointing to a tree should succeed''1269 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&1270 get_tag_msg tree-signed-tag >actual &&1271 test_cmp expect actual1272'12731274get_tag_header blob-signed-tag$blob blob $time>expect1275echo"A message for a blob">>expect1276echo'-----BEGIN PGP SIGNATURE-----'>>expect1277test_expect_success GPG \1278'creating a signed tag pointing to a blob should succeed''1279 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&1280 get_tag_msg blob-signed-tag >actual &&1281 test_cmp expect actual1282'12831284get_tag_header tag-signed-tag$tag tag $time>expect1285echo"A message for another tag">>expect1286echo'-----BEGIN PGP SIGNATURE-----'>>expect1287test_expect_success GPG \1288'creating a signed tag pointing to another tag should succeed''1289 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&1290 get_tag_msg tag-signed-tag >actual &&1291 test_cmp expect actual1292'12931294# usage with rfc1991 signatures1295get_tag_header rfc1991-signed-tag$commit commit $time>expect1296echo"RFC1991 signed tag">>expect1297echo'-----BEGIN PGP MESSAGE-----'>>expect1298test_expect_success GPG,RFC1991 \1299'creating a signed tag with rfc1991''1300 echo "rfc1991" >gpghome/gpg.conf &&1301 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag$commit&&1302 get_tag_msg rfc1991-signed-tag >actual &&1303 test_cmp expect actual1304'13051306cat>fakeeditor <<'EOF'1307#!/bin/sh1308cp "$1" actual1309EOF1310chmod+x fakeeditor13111312test_expect_success GPG,RFC1991 \1313'reediting a signed tag body omits signature''1314 echo "rfc1991" >gpghome/gpg.conf &&1315 echo "RFC1991 signed tag" >expect &&1316 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag$commit&&1317 test_cmp expect actual1318'13191320test_expect_success GPG,RFC1991 \1321'verifying rfc1991 signature''1322 echo "rfc1991" >gpghome/gpg.conf &&1323 git tag -v rfc1991-signed-tag1324'13251326test_expect_success GPG,RFC1991 \1327'list tag with rfc1991 signature''1328 echo "rfc1991" >gpghome/gpg.conf &&1329 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&1330 git tag -l -n1 rfc1991-signed-tag >actual &&1331 test_cmp expect actual &&1332 git tag -l -n2 rfc1991-signed-tag >actual &&1333 test_cmp expect actual &&1334 git tag -l -n999 rfc1991-signed-tag >actual &&1335 test_cmp expect actual1336'13371338rm-f gpghome/gpg.conf13391340test_expect_success GPG,RFC1991 \1341'verifying rfc1991 signature without --rfc1991''1342 git tag -v rfc1991-signed-tag1343'13441345test_expect_success GPG,RFC1991 \1346'list tag with rfc1991 signature without --rfc1991''1347 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&1348 git tag -l -n1 rfc1991-signed-tag >actual &&1349 test_cmp expect actual &&1350 git tag -l -n2 rfc1991-signed-tag >actual &&1351 test_cmp expect actual &&1352 git tag -l -n999 rfc1991-signed-tag >actual &&1353 test_cmp expect actual1354'13551356test_expect_success GPG,RFC1991 \1357'reediting a signed tag body omits signature''1358 echo "RFC1991 signed tag" >expect &&1359 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag$commit&&1360 test_cmp expect actual1361'13621363# try to sign with bad user.signingkey1364test_expect_success GPG \1365'git tag -s fails if gpg is misconfigured (bad key)' \1366'test_config user.signingkey BobTheMouse &&1367 test_must_fail git tag -s -m tail tag-gpg-failure'13681369# try to produce invalid signature1370test_expect_success GPG \1371'git tag -s fails if gpg is misconfigured (bad signature format)' \1372'test_config gpg.program echo &&1373 test_must_fail git tag -s -m tail tag-gpg-failure'13741375# try to sign with bad user.signingkey1376test_expect_success GPGSM \1377'git tag -s fails if gpgsm is misconfigured (bad key)' \1378'test_config user.signingkey BobTheMouse &&1379 test_config gpg.format x509 &&1380 test_must_fail git tag -s -m tail tag-gpg-failure'13811382# try to produce invalid signature1383test_expect_success GPGSM \1384'git tag -s fails if gpgsm is misconfigured (bad signature format)' \1385'test_config gpg.x509.program echo &&1386 test_config gpg.format x509 &&1387 test_must_fail git tag -s -m tail tag-gpg-failure'13881389# try to verify without gpg:13901391rm-rf gpghome1392test_expect_success GPG \1393'verify signed tag fails when public key is not present' \1394'test_must_fail git tag -v signed-tag'13951396test_expect_success \1397'git tag -a fails if tag annotation is empty''1398 ! (GIT_EDITOR=cat git tag -a initial-comment)1399'14001401test_expect_success \1402'message in editor has initial comment''1403 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)1404'14051406test_expect_success 'message in editor has initial comment: first line''1407 # check the first line --- should be empty1408 echo >first.expect &&1409 sed -e 1q <actual >first.actual &&1410 test_i18ncmp first.expect first.actual1411'14121413test_expect_success \1414'message in editor has initial comment: remainder''1415 # remove commented lines from the remainder -- should be empty1416 sed -e 1d -e "/^#/d" <actual >rest.actual &&1417 test_must_be_empty rest.actual1418'14191420get_tag_header reuse $commit commit $time>expect1421echo"An annotation to be reused">> expect1422test_expect_success \1423'overwriting an annoted tag should use its previous body''1424 git tag -a -m "An annotation to be reused" reuse &&1425 GIT_EDITOR=true git tag -f -a reuse &&1426 get_tag_msg reuse >actual &&1427 test_cmp expect actual1428'14291430test_expect_success 'filename for the message is relative to cwd''1431 mkdir subdir &&1432 echo "Tag message in top directory" >msgfile-5 &&1433 echo "Tag message in sub directory" >subdir/msgfile-5 &&1434 (1435 cd subdir &&1436 git tag -a -F msgfile-5 tag-from-subdir1437 ) &&1438 git cat-file tag tag-from-subdir | grep "in sub directory"1439'14401441test_expect_success 'filename for the message is relative to cwd''1442 echo "Tag message in sub directory" >subdir/msgfile-6 &&1443 (1444 cd subdir &&1445 git tag -a -F msgfile-6 tag-from-subdir-21446 ) &&1447 git cat-file tag tag-from-subdir-2 | grep "in sub directory"1448'14491450# create a few more commits to test --contains14511452hash1=$(git rev-parse HEAD)14531454test_expect_success 'creating second commit and tag''1455 echo foo-2.0 >foo &&1456 git add foo &&1457 git commit -m second &&1458 git tag v2.01459'14601461hash2=$(git rev-parse HEAD)14621463test_expect_success 'creating third commit without tag''1464 echo foo-dev >foo &&1465 git add foo &&1466 git commit -m third1467'14681469hash3=$(git rev-parse HEAD)14701471# simple linear checks of --continue14721473cat> expected <<EOF1474v0.2.11475v1.01476v1.0.11477v1.1.31478v2.01479EOF14801481test_expect_success 'checking that first commit is in all tags (hash)'"1482 git tag -l --contains$hash1v* >actual &&1483 test_cmp expected actual1484"14851486# other ways of specifying the commit1487test_expect_success 'checking that first commit is in all tags (tag)'"1488 git tag -l --contains v1.0 v* >actual &&1489 test_cmp expected actual1490"14911492test_expect_success 'checking that first commit is in all tags (relative)'"1493 git tag -l --contains HEAD~2 v* >actual &&1494 test_cmp expected actual1495"14961497# All the --contains tests above, but with --no-contains1498test_expect_success 'checking that first commit is not listed in any tag with --no-contains (hash)'"1499 git tag -l --no-contains$hash1v* >actual &&1500 test_must_be_empty actual1501"15021503test_expect_success 'checking that first commit is in all tags (tag)'"1504 git tag -l --no-contains v1.0 v* >actual &&1505 test_must_be_empty actual1506"15071508test_expect_success 'checking that first commit is in all tags (relative)'"1509 git tag -l --no-contains HEAD~2 v* >actual &&1510 test_must_be_empty actual1511"15121513cat> expected <<EOF1514v2.01515EOF15161517test_expect_success 'checking that second commit only has one tag'"1518 git tag -l --contains$hash2v* >actual &&1519 test_cmp expected actual1520"15211522cat> expected <<EOF1523v0.2.11524v1.01525v1.0.11526v1.1.31527EOF15281529test_expect_success 'inverse of the last test, with --no-contains'"1530 git tag -l --no-contains$hash2v* >actual &&1531 test_cmp expected actual1532"15331534test_expect_success 'checking that third commit has no tags'"1535 git tag -l --contains$hash3v* >actual &&1536 test_must_be_empty actual1537"15381539cat> expected <<EOF1540v0.2.11541v1.01542v1.0.11543v1.1.31544v2.01545EOF15461547test_expect_success 'conversely --no-contains on the third commit lists all tags'"1548 git tag -l --no-contains$hash3v* >actual &&1549 test_cmp expected actual1550"15511552# how about a simple merge?15531554test_expect_success 'creating simple branch''1555 git branch stable v2.0 &&1556 git checkout stable &&1557 echo foo-3.0 > foo &&1558 git commit foo -m fourth &&1559 git tag v3.01560'15611562hash4=$(git rev-parse HEAD)15631564cat> expected <<EOF1565v3.01566EOF15671568test_expect_success 'checking that branch head only has one tag'"1569 git tag -l --contains$hash4v* >actual &&1570 test_cmp expected actual1571"15721573cat> expected <<EOF1574v0.2.11575v1.01576v1.0.11577v1.1.31578v2.01579EOF15801581test_expect_success 'checking that branch head with --no-contains lists all but one tag'"1582 git tag -l --no-contains$hash4v* >actual &&1583 test_cmp expected actual1584"15851586test_expect_success 'merging original branch into this branch''1587 git merge --strategy=ours master &&1588 git tag v4.01589'15901591cat> expected <<EOF1592v4.01593EOF15941595test_expect_success 'checking that original branch head has one tag now'"1596 git tag -l --contains$hash3v* >actual &&1597 test_cmp expected actual1598"15991600cat> expected <<EOF1601v0.2.11602v1.01603v1.0.11604v1.1.31605v2.01606v3.01607EOF16081609test_expect_success 'checking that original branch head with --no-contains lists all but one tag now'"1610 git tag -l --no-contains$hash3v* >actual &&1611 test_cmp expected actual1612"16131614cat> expected <<EOF1615v0.2.11616v1.01617v1.0.11618v1.1.31619v2.01620v3.01621v4.01622EOF16231624test_expect_success 'checking that initial commit is in all tags'"1625 git tag -l --contains$hash1v* >actual &&1626 test_cmp expected actual1627"16281629test_expect_success 'checking that --contains can be used in non-list mode''1630 git tag --contains$hash1v* >actual &&1631 test_cmp expected actual1632'16331634test_expect_success 'checking that initial commit is in all tags with --no-contains'"1635 git tag -l --no-contains$hash1v* >actual &&1636 test_must_be_empty actual1637"16381639# mixing modes and options:16401641test_expect_success 'mixing incompatibles modes and options is forbidden''1642 test_must_fail git tag -a &&1643 test_must_fail git tag -a -l &&1644 test_must_fail git tag -s &&1645 test_must_fail git tag -s -l &&1646 test_must_fail git tag -m &&1647 test_must_fail git tag -m -l &&1648 test_must_fail git tag -m "hlagh" &&1649 test_must_fail git tag -m "hlagh" -l &&1650 test_must_fail git tag -F &&1651 test_must_fail git tag -F -l &&1652 test_must_fail git tag -f &&1653 test_must_fail git tag -f -l &&1654 test_must_fail git tag -a -s -m -F &&1655 test_must_fail git tag -a -s -m -F -l &&1656 test_must_fail git tag -l -v &&1657 test_must_fail git tag -l -d &&1658 test_must_fail git tag -l -v -d &&1659 test_must_fail git tag -n 100 -v &&1660 test_must_fail git tag -l -m msg &&1661 test_must_fail git tag -l -F some file &&1662 test_must_fail git tag -v -s &&1663 test_must_fail git tag --contains tag-tree &&1664 test_must_fail git tag --contains tag-blob &&1665 test_must_fail git tag --no-contains tag-tree &&1666 test_must_fail git tag --no-contains tag-blob &&1667 test_must_fail git tag --contains --no-contains &&1668 test_must_fail git tag --no-with HEAD &&1669 test_must_fail git tag --no-without HEAD1670'16711672for option in--contains --with --no-contains --without --merged --no-merged --points-at1673do1674 test_expect_success "mixing incompatible modes with$optionis forbidden""1675 test_must_fail git tag -d$optionHEAD &&1676 test_must_fail git tag -d$optionHEAD some-tag &&1677 test_must_fail git tag -v$optionHEAD1678 "1679 test_expect_success "Doing 'git tag --list-like$option<commit> <pattern> is permitted""1680 git tag -n$optionHEAD HEAD &&1681 git tag$optionHEAD HEAD &&1682 git tag$option1683 "1684done16851686# check points-at16871688test_expect_success '--points-at can be used in non-list mode''1689 echo v4.0 >expect &&1690 git tag --points-at=v4.0 "v*" >actual &&1691 test_cmp expect actual1692'16931694test_expect_success '--points-at is a synonym for --points-at HEAD''1695 echo v4.0 >expect &&1696 git tag --points-at >actual &&1697 test_cmp expect actual1698'16991700test_expect_success '--points-at finds lightweight tags''1701 echo v4.0 >expect &&1702 git tag --points-at v4.0 >actual &&1703 test_cmp expect actual1704'17051706test_expect_success '--points-at finds annotated tags of commits''1707 git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&1708 echo annotated-v4.0 >expect &&1709 git tag -l --points-at v4.0 "annotated*" >actual &&1710 test_cmp expect actual1711'17121713test_expect_success '--points-at finds annotated tags of tags''1714 git tag -m "describing the v4.0 tag object" \1715 annotated-again-v4.0 annotated-v4.0 &&1716 cat >expect <<-\EOF &&1717 annotated-again-v4.01718 annotated-v4.01719 EOF1720 git tag --points-at=annotated-v4.0 >actual &&1721 test_cmp expect actual1722'17231724test_expect_success 'recursive tagging should give advice''1725 sed -e "s/|$//" <<-EOF >expect &&1726 hint: You have created a nested tag. The object referred to by your new tag is1727 hint: already a tag. If you meant to tag the object that it points to, use:1728 hint: |1729 hint: git tag -f nested annotated-v4.0^{}1730 EOF1731 git tag -m nested nested annotated-v4.0 2>actual &&1732 test_i18ncmp expect actual1733'17341735test_expect_success 'multiple --points-at are OR-ed together''1736 cat >expect <<-\EOF &&1737 v2.01738 v3.01739 EOF1740 git tag --points-at=v2.0 --points-at=v3.0 >actual &&1741 test_cmp expect actual1742'17431744test_expect_success 'lexical sort''1745 git tag foo1.3 &&1746 git tag foo1.6 &&1747 git tag foo1.10 &&1748 git tag -l --sort=refname "foo*" >actual &&1749 cat >expect <<-\EOF &&1750 foo1.101751 foo1.31752 foo1.61753 EOF1754 test_cmp expect actual1755'17561757test_expect_success 'version sort''1758 git tag -l --sort=version:refname "foo*" >actual &&1759 cat >expect <<-\EOF &&1760 foo1.31761 foo1.61762 foo1.101763 EOF1764 test_cmp expect actual1765'17661767test_expect_success 'reverse version sort''1768 git tag -l --sort=-version:refname "foo*" >actual &&1769 cat >expect <<-\EOF &&1770 foo1.101771 foo1.61772 foo1.31773 EOF1774 test_cmp expect actual1775'17761777test_expect_success 'reverse lexical sort''1778 git tag -l --sort=-refname "foo*" >actual &&1779 cat >expect <<-\EOF &&1780 foo1.61781 foo1.31782 foo1.101783 EOF1784 test_cmp expect actual1785'17861787test_expect_success 'configured lexical sort''1788 test_config tag.sort "v:refname" &&1789 git tag -l "foo*" >actual &&1790 cat >expect <<-\EOF &&1791 foo1.31792 foo1.61793 foo1.101794 EOF1795 test_cmp expect actual1796'17971798test_expect_success 'option override configured sort''1799 test_config tag.sort "v:refname" &&1800 git tag -l --sort=-refname "foo*" >actual &&1801 cat >expect <<-\EOF &&1802 foo1.61803 foo1.31804 foo1.101805 EOF1806 test_cmp expect actual1807'18081809test_expect_success 'invalid sort parameter on command line''1810 test_must_fail git tag -l --sort=notvalid "foo*" >actual1811'18121813test_expect_success 'invalid sort parameter in configuratoin''1814 test_config tag.sort "v:notvalid" &&1815 test_must_fail git tag -l "foo*"1816'18171818test_expect_success 'version sort with prerelease reordering''1819 test_config versionsort.prereleaseSuffix -rc &&1820 git tag foo1.6-rc1 &&1821 git tag foo1.6-rc2 &&1822 git tag -l --sort=version:refname "foo*" >actual &&1823 cat >expect <<-\EOF &&1824 foo1.31825 foo1.6-rc11826 foo1.6-rc21827 foo1.61828 foo1.101829 EOF1830 test_cmp expect actual1831'18321833test_expect_success 'reverse version sort with prerelease reordering''1834 test_config versionsort.prereleaseSuffix -rc &&1835 git tag -l --sort=-version:refname "foo*" >actual &&1836 cat >expect <<-\EOF &&1837 foo1.101838 foo1.61839 foo1.6-rc21840 foo1.6-rc11841 foo1.31842 EOF1843 test_cmp expect actual1844'18451846test_expect_success 'version sort with prerelease reordering and common leading character''1847 test_config versionsort.prereleaseSuffix -before &&1848 git tag foo1.7-before1 &&1849 git tag foo1.7 &&1850 git tag foo1.7-after1 &&1851 git tag -l --sort=version:refname "foo1.7*" >actual &&1852 cat >expect <<-\EOF &&1853 foo1.7-before11854 foo1.71855 foo1.7-after11856 EOF1857 test_cmp expect actual1858'18591860test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character''1861 test_config versionsort.prereleaseSuffix -before &&1862 git config --add versionsort.prereleaseSuffix -after &&1863 git tag -l --sort=version:refname "foo1.7*" >actual &&1864 cat >expect <<-\EOF &&1865 foo1.7-before11866 foo1.7-after11867 foo1.71868 EOF1869 test_cmp expect actual1870'18711872test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag''1873 test_config versionsort.prereleaseSuffix -bar &&1874 git config --add versionsort.prereleaseSuffix -foo-baz &&1875 git config --add versionsort.prereleaseSuffix -foo-bar &&1876 git tag foo1.8-foo-bar &&1877 git tag foo1.8-foo-baz &&1878 git tag foo1.8 &&1879 git tag -l --sort=version:refname "foo1.8*" >actual &&1880 cat >expect <<-\EOF &&1881 foo1.8-foo-baz1882 foo1.8-foo-bar1883 foo1.81884 EOF1885 test_cmp expect actual1886'18871888test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position''1889 test_config versionsort.prereleaseSuffix -pre &&1890 git config --add versionsort.prereleaseSuffix -prerelease &&1891 git tag foo1.9-pre1 &&1892 git tag foo1.9-pre2 &&1893 git tag foo1.9-prerelease1 &&1894 git tag -l --sort=version:refname "foo1.9*" >actual &&1895 cat >expect <<-\EOF &&1896 foo1.9-pre11897 foo1.9-pre21898 foo1.9-prerelease11899 EOF1900 test_cmp expect actual1901'19021903test_expect_success 'version sort with general suffix reordering''1904 test_config versionsort.suffix -alpha &&1905 git config --add versionsort.suffix -beta &&1906 git config --add versionsort.suffix "" &&1907 git config --add versionsort.suffix -gamma &&1908 git config --add versionsort.suffix -delta &&1909 git tag foo1.10-alpha &&1910 git tag foo1.10-beta &&1911 git tag foo1.10-gamma &&1912 git tag foo1.10-delta &&1913 git tag foo1.10-unlisted-suffix &&1914 git tag -l --sort=version:refname "foo1.10*" >actual &&1915 cat >expect <<-\EOF &&1916 foo1.10-alpha1917 foo1.10-beta1918 foo1.101919 foo1.10-unlisted-suffix1920 foo1.10-gamma1921 foo1.10-delta1922 EOF1923 test_cmp expect actual1924'19251926test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix''1927 test_config versionsort.suffix -before &&1928 test_config versionsort.prereleaseSuffix -after &&1929 git tag -l --sort=version:refname "foo1.7*" >actual &&1930 cat >expect <<-\EOF &&1931 foo1.7-before11932 foo1.71933 foo1.7-after11934 EOF1935 test_cmp expect actual1936'19371938test_expect_success 'version sort with very long prerelease suffix''1939 test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&1940 git tag -l --sort=version:refname1941'19421943test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo''1944 i=1 &&1945 while test$i-lt 80001946 do1947 echo "commit refs/heads/master1948committer A U Thor <author@example.com>$((1000000000 + $i * 100)) +02001949data <<EOF1950commit #$i1951EOF"1952 test$i= 1 && echo "from refs/heads/master^0"1953 i=$(($i + 1))1954 done | git fast-import &&1955 git checkout master &&1956 git tag far-far-away HEAD^ &&1957 run_with_limited_stack git tag --contains HEAD >actual &&1958 test_must_be_empty actual &&1959 run_with_limited_stack git tag --no-contains HEAD >actual &&1960 test_line_count "-gt" 10 actual1961'19621963test_expect_success '--format should list tags as per format given''1964 cat >expect <<-\EOF &&1965 refname : refs/tags/v1.01966 refname : refs/tags/v1.0.11967 refname : refs/tags/v1.1.31968 EOF1969 git tag -l --format="refname : %(refname)" "v1*" >actual &&1970 test_cmp expect actual1971'19721973test_expect_success "set up color tests"'1974 echo "<RED>v1.0<RESET>" >expect.color &&1975 echo "v1.0" >expect.bare &&1976 color_args="--format=%(color:red)%(refname:short) --list v1.0"1977'19781979test_expect_success '%(color) omitted without tty''1980 TERM=vt100 git tag$color_args>actual.raw &&1981 test_decode_color <actual.raw >actual &&1982 test_cmp expect.bare actual1983'19841985test_expect_success TTY '%(color) present with tty''1986 test_terminal git tag$color_args>actual.raw &&1987 test_decode_color <actual.raw >actual &&1988 test_cmp expect.color actual1989'19901991test_expect_success '--color overrides auto-color''1992 git tag --color$color_args>actual.raw &&1993 test_decode_color <actual.raw >actual &&1994 test_cmp expect.color actual1995'19961997test_expect_success 'color.ui=always overrides auto-color''1998 git -c color.ui=always tag$color_args>actual.raw &&1999 test_decode_color <actual.raw >actual &&2000 test_cmp expect.color actual2001'20022003test_expect_success 'setup --merged test tags''2004 git tag mergetest-1 HEAD~2 &&2005 git tag mergetest-2 HEAD~1 &&2006 git tag mergetest-3 HEAD2007'20082009test_expect_success '--merged can be used in non-list mode''2010 cat >expect <<-\EOF &&2011 mergetest-12012 mergetest-22013 EOF2014 git tag --merged=mergetest-2 "mergetest*" >actual &&2015 test_cmp expect actual2016'20172018test_expect_success '--merged is incompatible with --no-merged''2019 test_must_fail git tag --merged HEAD --no-merged HEAD2020'20212022test_expect_success '--merged shows merged tags''2023 cat >expect <<-\EOF &&2024 mergetest-12025 mergetest-22026 EOF2027 git tag -l --merged=mergetest-2 mergetest-* >actual &&2028 test_cmp expect actual2029'20302031test_expect_success '--no-merged show unmerged tags''2032 cat >expect <<-\EOF &&2033 mergetest-32034 EOF2035 git tag -l --no-merged=mergetest-2 mergetest-* >actual &&2036 test_cmp expect actual2037'20382039test_expect_success '--no-merged can be used in non-list mode''2040 git tag --no-merged=mergetest-2 mergetest-* >actual &&2041 test_cmp expect actual2042'20432044test_expect_success 'ambiguous branch/tags not marked''2045 git tag ambiguous &&2046 git branch ambiguous &&2047 echo ambiguous >expect &&2048 git tag -l ambiguous >actual &&2049 test_cmp expect actual2050'20512052test_expect_success '--contains combined with --no-contains''2053 (2054 git init no-contains &&2055 cd no-contains &&2056 test_commit v0.1 &&2057 test_commit v0.2 &&2058 test_commit v0.3 &&2059 test_commit v0.4 &&2060 test_commit v0.5 &&2061 cat >expected <<-\EOF &&2062 v0.22063 v0.32064 v0.42065 EOF2066 git tag --contains v0.2 --no-contains v0.5 >actual &&2067 test_cmp expected actual2068 )2069'20702071# As the docs say, list tags which contain a specified *commit*. We2072# don't recurse down to tags for trees or blobs pointed to by *those*2073# commits.2074test_expect_success 'Does --[no-]contains stop at commits? Yes!''2075 cd no-contains &&2076 blob=$(git rev-parse v0.3:v0.3.t)&&2077 tree=$(git rev-parse v0.3^{tree})&&2078 git tag tag-blob$blob&&2079 git tag tag-tree$tree&&2080 git tag --contains v0.3 >actual &&2081 cat >expected <<-\EOF &&2082 v0.32083 v0.42084 v0.52085 EOF2086 test_cmp expected actual &&2087 git tag --no-contains v0.3 >actual &&2088 cat >expected <<-\EOF &&2089 v0.12090 v0.22091 EOF2092 test_cmp expected actual2093'20942095test_done