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 13# creating and listing lightweight tags: 14 15tag_exists () { 16 git show-ref --quiet --verify refs/tags/"$1" 17} 18 19# todo: git tag -l now returns always zero, when fixed, change this test 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 'looking for a tag in an empty tree should fail' \ 31'! (tag_exists mytag)' 32 33test_expect_success 'creating a tag in an empty tree should fail'' 34 test_must_fail git tag mynotag && 35 ! tag_exists mynotag 36' 37 38test_expect_success 'creating a tag for HEAD in an empty tree should fail'' 39 test_must_fail git tag mytaghead HEAD && 40 ! tag_exists mytaghead 41' 42 43test_expect_success 'creating a tag for an unknown revision should fail'' 44 test_must_fail git tag mytagnorev aaaaaaaaaaa && 45 ! tag_exists mytagnorev 46' 47 48# commit used in the tests, test_tick is also called here to freeze the date: 49test_expect_success 'creating a tag using default HEAD should succeed'' 50 test_tick && 51 echo foo >foo && 52 git add foo && 53 git commit -m Foo && 54 git tag mytag 55' 56 57test_expect_success 'listing all tags if one exists should succeed'' 58 git tag -l && 59 git tag 60' 61 62test_expect_success 'listing all tags if one exists should output that tag'' 63 test `git tag -l` = mytag && 64 test `git tag` = mytag 65' 66 67# pattern matching: 68 69test_expect_success 'listing a tag using a matching pattern should succeed' \ 70'git tag -l mytag' 71 72test_expect_success \ 73'listing a tag using a matching pattern should output that tag' \ 74'test `git tag -l mytag` = mytag' 75 76# todo: git tag -l now returns always zero, when fixed, change this test 77test_expect_success \ 78'listing tags using a non-matching pattern should suceed' \ 79'git tag -l xxx' 80 81test_expect_success \ 82'listing tags using a non-matching pattern should output nothing' \ 83'test `git tag -l xxx | wc -l` -eq 0' 84 85# special cases for creating tags: 86 87test_expect_success \ 88'trying to create a tag with the name of one existing should fail' \ 89'test_must_fail git tag mytag' 90 91test_expect_success \ 92'trying to create a tag with a non-valid name should fail'' 93 test `git tag -l | wc -l` -eq 1 && 94 test_must_fail git tag "" && 95 test_must_fail git tag .othertag && 96 test_must_fail git tag "other tag" && 97 test_must_fail git tag "othertag^" && 98 test_must_fail git tag "other~tag" && 99 test `git tag -l | wc -l` -eq 1 100' 101 102test_expect_success 'creating a tag using HEAD directly should succeed'' 103 git tag myhead HEAD && 104 tag_exists myhead 105' 106 107test_expect_success '--force can create a tag with the name of one existing'' 108 tag_exists mytag && 109 git tag --force mytag && 110 tag_exists mytag' 111 112test_expect_success '--force is moot with a non-existing tag name'' 113 git tag newtag >expect && 114 git tag --force forcetag >actual && 115 test_cmp expect actual 116' 117git tag -d newtag forcetag 118 119# deleting tags: 120 121test_expect_success 'trying to delete an unknown tag should fail'' 122 ! tag_exists unknown-tag && 123 test_must_fail git tag -d unknown-tag 124' 125 126cat>expect <<EOF 127myhead 128mytag 129EOF 130test_expect_success \ 131'trying to delete tags without params should succeed and do nothing'' 132 git tag -l > actual && test_cmp expect actual && 133 git tag -d && 134 git tag -l > actual && test_cmp expect actual 135' 136 137test_expect_success \ 138'deleting two existing tags in one command should succeed'' 139 tag_exists mytag && 140 tag_exists myhead && 141 git tag -d mytag myhead && 142 ! tag_exists mytag && 143 ! tag_exists myhead 144' 145 146test_expect_success \ 147'creating a tag with the name of another deleted one should succeed'' 148 ! tag_exists mytag && 149 git tag mytag && 150 tag_exists mytag 151' 152 153test_expect_success \ 154'trying to delete two tags, existing and not, should fail in the 2nd'' 155 tag_exists mytag && 156 ! tag_exists myhead && 157 test_must_fail git tag -d mytag anothertag && 158 ! tag_exists mytag && 159 ! tag_exists myhead 160' 161 162test_expect_success 'trying to delete an already deleted tag should fail' \ 163'test_must_fail git tag -d mytag' 164 165# listing various tags with pattern matching: 166 167cat>expect <<EOF 168a1 169aa1 170cba 171t210 172t211 173v0.2.1 174v1.0 175v1.0.1 176v1.1.3 177EOF 178test_expect_success 'listing all tags should print them ordered'' 179 git tag v1.0.1 && 180 git tag t211 && 181 git tag aa1 && 182 git tag v0.2.1 && 183 git tag v1.1.3 && 184 git tag cba && 185 git tag a1 && 186 git tag v1.0 && 187 git tag t210 && 188 git tag -l > actual && 189 test_cmp expect actual && 190 git tag > actual && 191 test_cmp expect actual 192' 193 194cat>expect <<EOF 195a1 196aa1 197cba 198EOF 199test_expect_success \ 200'listing tags with substring as pattern must print those matching'' 201 rm *a* && 202 git tag -l "*a*" > current && 203 test_cmp expect current 204' 205 206cat>expect <<EOF 207v0.2.1 208v1.0.1 209EOF 210test_expect_success \ 211'listing tags with a suffix as pattern must print those matching'' 212 git tag -l "*.1" > actual && 213 test_cmp expect actual 214' 215 216cat>expect <<EOF 217t210 218t211 219EOF 220test_expect_success \ 221'listing tags with a prefix as pattern must print those matching'' 222 git tag -l "t21*" > actual && 223 test_cmp expect actual 224' 225 226cat>expect <<EOF 227a1 228EOF 229test_expect_success \ 230'listing tags using a name as pattern must print that one matching'' 231 git tag -l a1 > actual && 232 test_cmp expect actual 233' 234 235cat>expect <<EOF 236v1.0 237EOF 238test_expect_success \ 239'listing tags using a name as pattern must print that one matching'' 240 git tag -l v1.0 > actual && 241 test_cmp expect actual 242' 243 244cat>expect <<EOF 245v1.0.1 246v1.1.3 247EOF 248test_expect_success \ 249'listing tags with ? in the pattern should print those matching'' 250 git tag -l "v1.?.?" > actual && 251 test_cmp expect actual 252' 253 254>expect 255test_expect_success \ 256'listing tags using v.* should print nothing because none have v.'' 257 git tag -l "v.*" > actual && 258 test_cmp expect actual 259' 260 261cat>expect <<EOF 262v0.2.1 263v1.0 264v1.0.1 265v1.1.3 266EOF 267test_expect_success \ 268'listing tags using v* should print only those having v'' 269 git tag -l "v*" > actual && 270 test_cmp expect actual 271' 272 273test_expect_success 'tag -l can accept multiple patterns'' 274 git tag -l "v1*" "v0*" >actual && 275 test_cmp expect actual 276' 277 278test_expect_success 'listing tags in column'' 279 COLUMNS=40 git tag -l --column=row >actual && 280 cat >expected <<\EOF && 281a1 aa1 cba t210 t211 282v0.2.1 v1.0 v1.0.1 v1.1.3 283EOF 284 test_cmp expected actual 285' 286 287test_expect_success 'listing tags in column with column.*'' 288 git config column.tag row && 289 git config column.ui dense && 290 COLUMNS=40 git tag -l >actual && 291 git config --unset column.ui && 292 git config --unset column.tag && 293 cat >expected <<\EOF && 294a1 aa1 cba t210 t211 295v0.2.1 v1.0 v1.0.1 v1.1.3 296EOF 297 test_cmp expected actual 298' 299 300test_expect_success 'listing tag with -n --column should fail'' 301 test_must_fail git tag --column -n 302' 303 304test_expect_success 'listing tags -n in column with column.ui ignored'' 305 git config column.ui "row dense" && 306 COLUMNS=40 git tag -l -n >actual && 307 git config --unset column.ui && 308 cat >expected <<\EOF && 309a1 Foo 310aa1 Foo 311cba Foo 312t210 Foo 313t211 Foo 314v0.2.1 Foo 315v1.0 Foo 316v1.0.1 Foo 317v1.1.3 Foo 318EOF 319 test_cmp expected actual 320' 321 322# creating and verifying lightweight tags: 323 324test_expect_success \ 325'a non-annotated tag created without parameters should point to HEAD'' 326 git tag non-annotated-tag && 327 test$(git cat-file -t non-annotated-tag)= commit && 328 test$(git rev-parse non-annotated-tag)=$(git rev-parse HEAD) 329' 330 331test_expect_success 'trying to verify an unknown tag should fail' \ 332'test_must_fail git tag -v unknown-tag' 333 334test_expect_success \ 335'trying to verify a non-annotated and non-signed tag should fail' \ 336'test_must_fail git tag -v non-annotated-tag' 337 338test_expect_success \ 339'trying to verify many non-annotated or unknown tags, should fail' \ 340'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' 341 342# creating annotated tags: 343 344get_tag_msg () { 345 git cat-file tag "$1"|sed-e"/BEGIN PGP/q" 346} 347 348# run test_tick before committing always gives the time in that timezone 349get_tag_header () { 350cat<<EOF 351object$2 352type$3 353tag$1 354tagger C O Mitter <committer@example.com>$4-0700 355 356EOF 357} 358 359commit=$(git rev-parse HEAD) 360time=$test_tick 361 362get_tag_header annotated-tag$commit commit $time>expect 363echo"A message">>expect 364test_expect_success \ 365'creating an annotated tag with -m message should succeed'' 366 git tag -m "A message" annotated-tag && 367 get_tag_msg annotated-tag >actual && 368 test_cmp expect actual 369' 370 371cat>msgfile <<EOF 372Another message 373in a file. 374EOF 375get_tag_header file-annotated-tag$commit commit $time>expect 376cat msgfile >>expect 377test_expect_success \ 378'creating an annotated tag with -F messagefile should succeed'' 379 git tag -F msgfile file-annotated-tag && 380 get_tag_msg file-annotated-tag >actual && 381 test_cmp expect actual 382' 383 384cat>inputmsg <<EOF 385A message from the 386standard input 387EOF 388get_tag_header stdin-annotated-tag$commit commit $time>expect 389cat inputmsg >>expect 390test_expect_success 'creating an annotated tag with -F - should succeed'' 391 git tag -F - stdin-annotated-tag <inputmsg && 392 get_tag_msg stdin-annotated-tag >actual && 393 test_cmp expect actual 394' 395 396test_expect_success \ 397'trying to create a tag with a non-existing -F file should fail'' 398 ! test -f nonexistingfile && 399 ! tag_exists notag && 400 test_must_fail git tag -F nonexistingfile notag && 401 ! tag_exists notag 402' 403 404test_expect_success \ 405'trying to create tags giving both -m or -F options should fail'' 406 echo "message file 1" >msgfile1 && 407 echo "message file 2" >msgfile2 && 408 ! tag_exists msgtag && 409 test_must_fail git tag -m "message 1" -F msgfile1 msgtag && 410 ! tag_exists msgtag && 411 test_must_fail git tag -F msgfile1 -m "message 1" msgtag && 412 ! tag_exists msgtag && 413 test_must_fail git tag -m "message 1" -F msgfile1 \ 414 -m "message 2" msgtag && 415 ! tag_exists msgtag 416' 417 418# blank and empty messages: 419 420get_tag_header empty-annotated-tag$commit commit $time>expect 421test_expect_success \ 422'creating a tag with an empty -m message should succeed'' 423 git tag -m "" empty-annotated-tag && 424 get_tag_msg empty-annotated-tag >actual && 425 test_cmp expect actual 426' 427 428>emptyfile 429get_tag_header emptyfile-annotated-tag$commit commit $time>expect 430test_expect_success \ 431'creating a tag with an empty -F messagefile should succeed'' 432 git tag -F emptyfile emptyfile-annotated-tag && 433 get_tag_msg emptyfile-annotated-tag >actual && 434 test_cmp expect actual 435' 436 437printf'\n\n \n\t\nLeading blank lines\n'>blanksfile 438printf'\n\t \t \nRepeated blank lines\n'>>blanksfile 439printf'\n\n\nTrailing spaces\t \n'>>blanksfile 440printf'\nTrailing blank lines\n\n\t \n\n'>>blanksfile 441get_tag_header blanks-annotated-tag$commit commit $time>expect 442cat>>expect <<EOF 443Leading blank lines 444 445Repeated blank lines 446 447Trailing spaces 448 449Trailing blank lines 450EOF 451test_expect_success \ 452'extra blanks in the message for an annotated tag should be removed'' 453 git tag -F blanksfile blanks-annotated-tag && 454 get_tag_msg blanks-annotated-tag >actual && 455 test_cmp expect actual 456' 457 458get_tag_header blank-annotated-tag$commit commit $time>expect 459test_expect_success \ 460'creating a tag with blank -m message with spaces should succeed'' 461 git tag -m " " blank-annotated-tag && 462 get_tag_msg blank-annotated-tag >actual && 463 test_cmp expect actual 464' 465 466echo' '>blankfile 467echo''>>blankfile 468echo' '>>blankfile 469get_tag_header blankfile-annotated-tag$commit commit $time>expect 470test_expect_success \ 471'creating a tag with blank -F messagefile with spaces should succeed'' 472 git tag -F blankfile blankfile-annotated-tag && 473 get_tag_msg blankfile-annotated-tag >actual && 474 test_cmp expect actual 475' 476 477printf' '>blanknonlfile 478get_tag_header blanknonlfile-annotated-tag$commit commit $time>expect 479test_expect_success \ 480'creating a tag with -F file of spaces and no newline should succeed'' 481 git tag -F blanknonlfile blanknonlfile-annotated-tag && 482 get_tag_msg blanknonlfile-annotated-tag >actual && 483 test_cmp expect actual 484' 485 486# messages with commented lines: 487 488cat>commentsfile <<EOF 489# A comment 490 491############ 492The message. 493############ 494One line. 495 496 497# commented lines 498# commented lines 499 500Another line. 501# comments 502 503Last line. 504EOF 505get_tag_header comments-annotated-tag$commit commit $time>expect 506cat>>expect <<EOF 507The message. 508One line. 509 510Another line. 511 512Last line. 513EOF 514test_expect_success \ 515'creating a tag using a -F messagefile with #comments should succeed'' 516 git tag -F commentsfile comments-annotated-tag && 517 get_tag_msg comments-annotated-tag >actual && 518 test_cmp expect actual 519' 520 521get_tag_header comment-annotated-tag$commit commit $time>expect 522test_expect_success \ 523'creating a tag with a #comment in the -m message should succeed'' 524 git tag -m "#comment" comment-annotated-tag && 525 get_tag_msg comment-annotated-tag >actual && 526 test_cmp expect actual 527' 528 529echo'#comment'>commentfile 530echo''>>commentfile 531echo'####'>>commentfile 532get_tag_header commentfile-annotated-tag$commit commit $time>expect 533test_expect_success \ 534'creating a tag with #comments in the -F messagefile should succeed'' 535 git tag -F commentfile commentfile-annotated-tag && 536 get_tag_msg commentfile-annotated-tag >actual && 537 test_cmp expect actual 538' 539 540printf'#comment'>commentnonlfile 541get_tag_header commentnonlfile-annotated-tag$commit commit $time>expect 542test_expect_success \ 543'creating a tag with a file of #comment and no newline should succeed'' 544 git tag -F commentnonlfile commentnonlfile-annotated-tag && 545 get_tag_msg commentnonlfile-annotated-tag >actual && 546 test_cmp expect actual 547' 548 549# listing messages for annotated non-signed tags: 550 551test_expect_success \ 552'listing the one-line message of a non-signed tag should succeed'' 553 git tag -m "A msg" tag-one-line && 554 555 echo "tag-one-line" >expect && 556 git tag -l | grep "^tag-one-line" >actual && 557 test_cmp expect actual && 558 git tag -n0 -l | grep "^tag-one-line" >actual && 559 test_cmp expect actual && 560 git tag -n0 -l tag-one-line >actual && 561 test_cmp expect actual && 562 563 echo "tag-one-line A msg" >expect && 564 git tag -n1 -l | grep "^tag-one-line" >actual && 565 test_cmp expect actual && 566 git tag -n -l | grep "^tag-one-line" >actual && 567 test_cmp expect actual && 568 git tag -n1 -l tag-one-line >actual && 569 test_cmp expect actual && 570 git tag -n2 -l tag-one-line >actual && 571 test_cmp expect actual && 572 git tag -n999 -l tag-one-line >actual && 573 test_cmp expect actual 574' 575 576test_expect_success \ 577'listing the zero-lines message of a non-signed tag should succeed'' 578 git tag -m "" tag-zero-lines && 579 580 echo "tag-zero-lines" >expect && 581 git tag -l | grep "^tag-zero-lines" >actual && 582 test_cmp expect actual && 583 git tag -n0 -l | grep "^tag-zero-lines" >actual && 584 test_cmp expect actual && 585 git tag -n0 -l tag-zero-lines >actual && 586 test_cmp expect actual && 587 588 echo "tag-zero-lines " >expect && 589 git tag -n1 -l | grep "^tag-zero-lines" >actual && 590 test_cmp expect actual && 591 git tag -n -l | grep "^tag-zero-lines" >actual && 592 test_cmp expect actual && 593 git tag -n1 -l tag-zero-lines >actual && 594 test_cmp expect actual && 595 git tag -n2 -l tag-zero-lines >actual && 596 test_cmp expect actual && 597 git tag -n999 -l tag-zero-lines >actual && 598 test_cmp expect actual 599' 600 601echo'tag line one'>annotagmsg 602echo'tag line two'>>annotagmsg 603echo'tag line three'>>annotagmsg 604test_expect_success \ 605'listing many message lines of a non-signed tag should succeed'' 606 git tag -F annotagmsg tag-lines && 607 608 echo "tag-lines" >expect && 609 git tag -l | grep "^tag-lines" >actual && 610 test_cmp expect actual && 611 git tag -n0 -l | grep "^tag-lines" >actual && 612 test_cmp expect actual && 613 git tag -n0 -l tag-lines >actual && 614 test_cmp expect actual && 615 616 echo "tag-lines tag line one" >expect && 617 git tag -n1 -l | grep "^tag-lines" >actual && 618 test_cmp expect actual && 619 git tag -n -l | grep "^tag-lines" >actual && 620 test_cmp expect actual && 621 git tag -n1 -l tag-lines >actual && 622 test_cmp expect actual && 623 624 echo " tag line two" >>expect && 625 git tag -n2 -l | grep "^ *tag.line" >actual && 626 test_cmp expect actual && 627 git tag -n2 -l tag-lines >actual && 628 test_cmp expect actual && 629 630 echo " tag line three" >>expect && 631 git tag -n3 -l | grep "^ *tag.line" >actual && 632 test_cmp expect actual && 633 git tag -n3 -l tag-lines >actual && 634 test_cmp expect actual && 635 git tag -n4 -l | grep "^ *tag.line" >actual && 636 test_cmp expect actual && 637 git tag -n4 -l tag-lines >actual && 638 test_cmp expect actual && 639 git tag -n99 -l | grep "^ *tag.line" >actual && 640 test_cmp expect actual && 641 git tag -n99 -l tag-lines >actual && 642 test_cmp expect actual 643' 644 645test_expect_success 'annotations for blobs are empty'' 646 blob=$(git hash-object -w --stdin <<-\EOF 647 Blob paragraph 1. 648 649 Blob paragraph 2. 650 EOF 651 ) && 652 git tag tag-blob$blob&& 653 echo "tag-blob " >expect && 654 git tag -n1 -l tag-blob >actual && 655 test_cmp expect actual 656' 657 658# trying to verify annotated non-signed tags: 659 660test_expect_success GPG \ 661'trying to verify an annotated non-signed tag should fail'' 662 tag_exists annotated-tag && 663 test_must_fail git tag -v annotated-tag 664' 665 666test_expect_success GPG \ 667'trying to verify a file-annotated non-signed tag should fail'' 668 tag_exists file-annotated-tag && 669 test_must_fail git tag -v file-annotated-tag 670' 671 672test_expect_success GPG \ 673'trying to verify two annotated non-signed tags should fail'' 674 tag_exists annotated-tag file-annotated-tag && 675 test_must_fail git tag -v annotated-tag file-annotated-tag 676' 677 678# creating and verifying signed tags: 679 680get_tag_header signed-tag$commit commit $time>expect 681echo'A signed tag message'>>expect 682echo'-----BEGIN PGP SIGNATURE-----'>>expect 683test_expect_success GPG 'creating a signed tag with -m message should succeed'' 684 git tag -s -m "A signed tag message" signed-tag && 685 get_tag_msg signed-tag >actual && 686 test_cmp expect actual 687' 688 689get_tag_header u-signed-tag$commit commit $time>expect 690echo'Another message'>>expect 691echo'-----BEGIN PGP SIGNATURE-----'>>expect 692test_expect_success GPG 'sign with a given key id'' 693 694 git tag -u committer@example.com -m "Another message" u-signed-tag && 695 get_tag_msg u-signed-tag >actual && 696 test_cmp expect actual 697 698' 699 700test_expect_success GPG 'sign with an unknown id (1)'' 701 702 test_must_fail git tag -u author@example.com \ 703 -m "Another message" o-signed-tag 704 705' 706 707test_expect_success GPG 'sign with an unknown id (2)'' 708 709 test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag 710 711' 712 713cat>fakeeditor <<'EOF' 714#!/bin/sh 715test -n "$1" && exec >"$1" 716echo A signed tag message 717echo from a fake editor. 718EOF 719chmod+x fakeeditor 720 721get_tag_header implied-sign$commit commit $time>expect 722./fakeeditor >>expect 723echo'-----BEGIN PGP SIGNATURE-----'>>expect 724test_expect_success GPG '-u implies signed tag'' 725 GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && 726 get_tag_msg implied-sign >actual && 727 test_cmp expect actual 728' 729 730cat>sigmsgfile <<EOF 731Another signed tag 732message in a file. 733EOF 734get_tag_header file-signed-tag$commit commit $time>expect 735cat sigmsgfile >>expect 736echo'-----BEGIN PGP SIGNATURE-----'>>expect 737test_expect_success GPG \ 738'creating a signed tag with -F messagefile should succeed'' 739 git tag -s -F sigmsgfile file-signed-tag && 740 get_tag_msg file-signed-tag >actual && 741 test_cmp expect actual 742' 743 744cat>siginputmsg <<EOF 745A signed tag message from 746the standard input 747EOF 748get_tag_header stdin-signed-tag$commit commit $time>expect 749cat siginputmsg >>expect 750echo'-----BEGIN PGP SIGNATURE-----'>>expect 751test_expect_success GPG 'creating a signed tag with -F - should succeed'' 752 git tag -s -F - stdin-signed-tag <siginputmsg && 753 get_tag_msg stdin-signed-tag >actual && 754 test_cmp expect actual 755' 756 757get_tag_header implied-annotate$commit commit $time>expect 758./fakeeditor >>expect 759echo'-----BEGIN PGP SIGNATURE-----'>>expect 760test_expect_success GPG '-s implies annotated tag'' 761 GIT_EDITOR=./fakeeditor git tag -s implied-annotate && 762 get_tag_msg implied-annotate >actual && 763 test_cmp expect actual 764' 765 766test_expect_success GPG \ 767'trying to create a signed tag with non-existing -F file should fail'' 768 ! test -f nonexistingfile && 769 ! tag_exists nosigtag && 770 test_must_fail git tag -s -F nonexistingfile nosigtag && 771 ! tag_exists nosigtag 772' 773 774test_expect_success GPG 'verifying a signed tag should succeed' \ 775'git tag -v signed-tag' 776 777test_expect_success GPG 'verifying two signed tags in one command should succeed' \ 778'git tag -v signed-tag file-signed-tag' 779 780test_expect_success GPG \ 781'verifying many signed and non-signed tags should fail'' 782 test_must_fail git tag -v signed-tag annotated-tag && 783 test_must_fail git tag -v file-annotated-tag file-signed-tag && 784 test_must_fail git tag -v annotated-tag \ 785 file-signed-tag file-annotated-tag && 786 test_must_fail git tag -v signed-tag annotated-tag file-signed-tag 787' 788 789test_expect_success GPG 'verifying a forged tag should fail'' 790 forged=$(git cat-file tag signed-tag | 791 sed -e "s/signed-tag/forged-tag/" | 792 git mktag) && 793 git tag forged-tag$forged&& 794 test_must_fail git tag -v forged-tag 795' 796 797# blank and empty messages for signed tags: 798 799get_tag_header empty-signed-tag$commit commit $time>expect 800echo'-----BEGIN PGP SIGNATURE-----'>>expect 801test_expect_success GPG \ 802'creating a signed tag with an empty -m message should succeed'' 803 git tag -s -m "" empty-signed-tag && 804 get_tag_msg empty-signed-tag >actual && 805 test_cmp expect actual && 806 git tag -v empty-signed-tag 807' 808 809>sigemptyfile 810get_tag_header emptyfile-signed-tag$commit commit $time>expect 811echo'-----BEGIN PGP SIGNATURE-----'>>expect 812test_expect_success GPG \ 813'creating a signed tag with an empty -F messagefile should succeed'' 814 git tag -s -F sigemptyfile emptyfile-signed-tag && 815 get_tag_msg emptyfile-signed-tag >actual && 816 test_cmp expect actual && 817 git tag -v emptyfile-signed-tag 818' 819 820printf'\n\n \n\t\nLeading blank lines\n'> sigblanksfile 821printf'\n\t \t \nRepeated blank lines\n'>>sigblanksfile 822printf'\n\n\nTrailing spaces\t \n'>>sigblanksfile 823printf'\nTrailing blank lines\n\n\t \n\n'>>sigblanksfile 824get_tag_header blanks-signed-tag$commit commit $time>expect 825cat>>expect <<EOF 826Leading blank lines 827 828Repeated blank lines 829 830Trailing spaces 831 832Trailing blank lines 833EOF 834echo'-----BEGIN PGP SIGNATURE-----'>>expect 835test_expect_success GPG \ 836'extra blanks in the message for a signed tag should be removed'' 837 git tag -s -F sigblanksfile blanks-signed-tag && 838 get_tag_msg blanks-signed-tag >actual && 839 test_cmp expect actual && 840 git tag -v blanks-signed-tag 841' 842 843get_tag_header blank-signed-tag$commit commit $time>expect 844echo'-----BEGIN PGP SIGNATURE-----'>>expect 845test_expect_success GPG \ 846'creating a signed tag with a blank -m message should succeed'' 847 git tag -s -m " " blank-signed-tag && 848 get_tag_msg blank-signed-tag >actual && 849 test_cmp expect actual && 850 git tag -v blank-signed-tag 851' 852 853echo' '>sigblankfile 854echo''>>sigblankfile 855echo' '>>sigblankfile 856get_tag_header blankfile-signed-tag$commit commit $time>expect 857echo'-----BEGIN PGP SIGNATURE-----'>>expect 858test_expect_success GPG \ 859'creating a signed tag with blank -F file with spaces should succeed'' 860 git tag -s -F sigblankfile blankfile-signed-tag && 861 get_tag_msg blankfile-signed-tag >actual && 862 test_cmp expect actual && 863 git tag -v blankfile-signed-tag 864' 865 866printf' '>sigblanknonlfile 867get_tag_header blanknonlfile-signed-tag$commit commit $time>expect 868echo'-----BEGIN PGP SIGNATURE-----'>>expect 869test_expect_success GPG \ 870'creating a signed tag with spaces and no newline should succeed'' 871 git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && 872 get_tag_msg blanknonlfile-signed-tag >actual && 873 test_cmp expect actual && 874 git tag -v signed-tag 875' 876 877# messages with commented lines for signed tags: 878 879cat>sigcommentsfile <<EOF 880# A comment 881 882############ 883The message. 884############ 885One line. 886 887 888# commented lines 889# commented lines 890 891Another line. 892# comments 893 894Last line. 895EOF 896get_tag_header comments-signed-tag$commit commit $time>expect 897cat>>expect <<EOF 898The message. 899One line. 900 901Another line. 902 903Last line. 904EOF 905echo'-----BEGIN PGP SIGNATURE-----'>>expect 906test_expect_success GPG \ 907'creating a signed tag with a -F file with #comments should succeed'' 908 git tag -s -F sigcommentsfile comments-signed-tag && 909 get_tag_msg comments-signed-tag >actual && 910 test_cmp expect actual && 911 git tag -v comments-signed-tag 912' 913 914get_tag_header comment-signed-tag$commit commit $time>expect 915echo'-----BEGIN PGP SIGNATURE-----'>>expect 916test_expect_success GPG \ 917'creating a signed tag with #commented -m message should succeed'' 918 git tag -s -m "#comment" comment-signed-tag && 919 get_tag_msg comment-signed-tag >actual && 920 test_cmp expect actual && 921 git tag -v comment-signed-tag 922' 923 924echo'#comment'>sigcommentfile 925echo''>>sigcommentfile 926echo'####'>>sigcommentfile 927get_tag_header commentfile-signed-tag$commit commit $time>expect 928echo'-----BEGIN PGP SIGNATURE-----'>>expect 929test_expect_success GPG \ 930'creating a signed tag with #commented -F messagefile should succeed'' 931 git tag -s -F sigcommentfile commentfile-signed-tag && 932 get_tag_msg commentfile-signed-tag >actual && 933 test_cmp expect actual && 934 git tag -v commentfile-signed-tag 935' 936 937printf'#comment'>sigcommentnonlfile 938get_tag_header commentnonlfile-signed-tag$commit commit $time>expect 939echo'-----BEGIN PGP SIGNATURE-----'>>expect 940test_expect_success GPG \ 941'creating a signed tag with a #comment and no newline should succeed'' 942 git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && 943 get_tag_msg commentnonlfile-signed-tag >actual && 944 test_cmp expect actual && 945 git tag -v commentnonlfile-signed-tag 946' 947 948# listing messages for signed tags: 949 950test_expect_success GPG \ 951'listing the one-line message of a signed tag should succeed'' 952 git tag -s -m "A message line signed" stag-one-line && 953 954 echo "stag-one-line" >expect && 955 git tag -l | grep "^stag-one-line" >actual && 956 test_cmp expect actual && 957 git tag -n0 -l | grep "^stag-one-line" >actual && 958 test_cmp expect actual && 959 git tag -n0 -l stag-one-line >actual && 960 test_cmp expect actual && 961 962 echo "stag-one-line A message line signed" >expect && 963 git tag -n1 -l | grep "^stag-one-line" >actual && 964 test_cmp expect actual && 965 git tag -n -l | grep "^stag-one-line" >actual && 966 test_cmp expect actual && 967 git tag -n1 -l stag-one-line >actual && 968 test_cmp expect actual && 969 git tag -n2 -l stag-one-line >actual && 970 test_cmp expect actual && 971 git tag -n999 -l stag-one-line >actual && 972 test_cmp expect actual 973' 974 975test_expect_success GPG \ 976'listing the zero-lines message of a signed tag should succeed'' 977 git tag -s -m "" stag-zero-lines && 978 979 echo "stag-zero-lines" >expect && 980 git tag -l | grep "^stag-zero-lines" >actual && 981 test_cmp expect actual && 982 git tag -n0 -l | grep "^stag-zero-lines" >actual && 983 test_cmp expect actual && 984 git tag -n0 -l stag-zero-lines >actual && 985 test_cmp expect actual && 986 987 echo "stag-zero-lines " >expect && 988 git tag -n1 -l | grep "^stag-zero-lines" >actual && 989 test_cmp expect actual && 990 git tag -n -l | grep "^stag-zero-lines" >actual && 991 test_cmp expect actual && 992 git tag -n1 -l stag-zero-lines >actual && 993 test_cmp expect actual && 994 git tag -n2 -l stag-zero-lines >actual && 995 test_cmp expect actual && 996 git tag -n999 -l stag-zero-lines >actual && 997 test_cmp expect actual 998' 9991000echo'stag line one'>sigtagmsg1001echo'stag line two'>>sigtagmsg1002echo'stag line three'>>sigtagmsg1003test_expect_success GPG \1004'listing many message lines of a signed tag should succeed''1005 git tag -s -F sigtagmsg stag-lines &&10061007 echo "stag-lines" >expect &&1008 git tag -l | grep "^stag-lines" >actual &&1009 test_cmp expect actual &&1010 git tag -n0 -l | grep "^stag-lines" >actual &&1011 test_cmp expect actual &&1012 git tag -n0 -l stag-lines >actual &&1013 test_cmp expect actual &&10141015 echo "stag-lines stag line one" >expect &&1016 git tag -n1 -l | grep "^stag-lines" >actual &&1017 test_cmp expect actual &&1018 git tag -n -l | grep "^stag-lines" >actual &&1019 test_cmp expect actual &&1020 git tag -n1 -l stag-lines >actual &&1021 test_cmp expect actual &&10221023 echo " stag line two" >>expect &&1024 git tag -n2 -l | grep "^ *stag.line" >actual &&1025 test_cmp expect actual &&1026 git tag -n2 -l stag-lines >actual &&1027 test_cmp expect actual &&10281029 echo " stag line three" >>expect &&1030 git tag -n3 -l | grep "^ *stag.line" >actual &&1031 test_cmp expect actual &&1032 git tag -n3 -l stag-lines >actual &&1033 test_cmp expect actual &&1034 git tag -n4 -l | grep "^ *stag.line" >actual &&1035 test_cmp expect actual &&1036 git tag -n4 -l stag-lines >actual &&1037 test_cmp expect actual &&1038 git tag -n99 -l | grep "^ *stag.line" >actual &&1039 test_cmp expect actual &&1040 git tag -n99 -l stag-lines >actual &&1041 test_cmp expect actual1042'10431044# tags pointing to objects different from commits:10451046tree=$(git rev-parse HEAD^{tree})1047blob=$(git rev-parse HEAD:foo)1048tag=$(git rev-parse signed-tag 2>/dev/null)10491050get_tag_header tree-signed-tag$tree tree $time>expect1051echo"A message for a tree">>expect1052echo'-----BEGIN PGP SIGNATURE-----'>>expect1053test_expect_success GPG \1054'creating a signed tag pointing to a tree should succeed''1055 git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&1056 get_tag_msg tree-signed-tag >actual &&1057 test_cmp expect actual1058'10591060get_tag_header blob-signed-tag$blob blob $time>expect1061echo"A message for a blob">>expect1062echo'-----BEGIN PGP SIGNATURE-----'>>expect1063test_expect_success GPG \1064'creating a signed tag pointing to a blob should succeed''1065 git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&1066 get_tag_msg blob-signed-tag >actual &&1067 test_cmp expect actual1068'10691070get_tag_header tag-signed-tag$tag tag $time>expect1071echo"A message for another tag">>expect1072echo'-----BEGIN PGP SIGNATURE-----'>>expect1073test_expect_success GPG \1074'creating a signed tag pointing to another tag should succeed''1075 git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&1076 get_tag_msg tag-signed-tag >actual &&1077 test_cmp expect actual1078'10791080# usage with rfc1991 signatures1081get_tag_header rfc1991-signed-tag$commit commit $time>expect1082echo"RFC1991 signed tag">>expect1083echo'-----BEGIN PGP MESSAGE-----'>>expect1084test_expect_success GPG \1085'creating a signed tag with rfc1991''1086 echo "rfc1991" >gpghome/gpg.conf &&1087 git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag$commit&&1088 get_tag_msg rfc1991-signed-tag >actual &&1089 test_cmp expect actual1090'10911092cat>fakeeditor <<'EOF'1093#!/bin/sh1094cp "$1" actual1095EOF1096chmod+x fakeeditor10971098test_expect_success GPG \1099'reediting a signed tag body omits signature''1100 echo "rfc1991" >gpghome/gpg.conf &&1101 echo "RFC1991 signed tag" >expect &&1102 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag$commit&&1103 test_cmp expect actual1104'11051106test_expect_success GPG \1107'verifying rfc1991 signature''1108 echo "rfc1991" >gpghome/gpg.conf &&1109 git tag -v rfc1991-signed-tag1110'11111112test_expect_success GPG \1113'list tag with rfc1991 signature''1114 echo "rfc1991" >gpghome/gpg.conf &&1115 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&1116 git tag -l -n1 rfc1991-signed-tag >actual &&1117 test_cmp expect actual &&1118 git tag -l -n2 rfc1991-signed-tag >actual &&1119 test_cmp expect actual &&1120 git tag -l -n999 rfc1991-signed-tag >actual &&1121 test_cmp expect actual1122'11231124rm-f gpghome/gpg.conf11251126test_expect_success GPG \1127'verifying rfc1991 signature without --rfc1991''1128 git tag -v rfc1991-signed-tag1129'11301131test_expect_success GPG \1132'list tag with rfc1991 signature without --rfc1991''1133 echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&1134 git tag -l -n1 rfc1991-signed-tag >actual &&1135 test_cmp expect actual &&1136 git tag -l -n2 rfc1991-signed-tag >actual &&1137 test_cmp expect actual &&1138 git tag -l -n999 rfc1991-signed-tag >actual &&1139 test_cmp expect actual1140'11411142test_expect_success GPG \1143'reediting a signed tag body omits signature''1144 echo "RFC1991 signed tag" >expect &&1145 GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag$commit&&1146 test_cmp expect actual1147'11481149# try to sign with bad user.signingkey1150git config user.signingkey BobTheMouse1151test_expect_success GPG \1152'git tag -s fails if gpg is misconfigured' \1153'test_must_fail git tag -s -m tail tag-gpg-failure'1154git config --unset user.signingkey11551156# try to verify without gpg:11571158rm-rf gpghome1159test_expect_success GPG \1160'verify signed tag fails when public key is not present' \1161'test_must_fail git tag -v signed-tag'11621163test_expect_success \1164'git tag -a fails if tag annotation is empty''1165 ! (GIT_EDITOR=cat git tag -a initial-comment)1166'11671168test_expect_success \1169'message in editor has initial comment''1170 ! (GIT_EDITOR=cat git tag -a initial-comment > actual)1171'11721173test_expect_success 'message in editor has initial comment: first line''1174 # check the first line --- should be empty1175 echo >first.expect &&1176 sed -e 1q <actual >first.actual &&1177 test_i18ncmp first.expect first.actual1178'11791180test_expect_success \1181'message in editor has initial comment: remainder''1182 # remove commented lines from the remainder -- should be empty1183 >rest.expect1184 sed -e 1d -e '/^#/d' <actual >rest.actual &&1185 test_cmp rest.expect rest.actual1186'11871188get_tag_header reuse$commitcommit$time>expect1189echo "An annotation to be reused" >> expect1190test_expect_success \1191 'overwriting an annoted tag should use its previous body' '1192 git tag -a -m"An annotation to be reused" reuse &&1193 GIT_EDITOR=true git tag -f -a reuse &&1194 get_tag_msg reuse >actual &&1195 test_cmp expect actual1196'11971198test_expect_success 'filename for the message is relative to cwd' '1199mkdir subdir &&1200echo"Tag message in top directory">msgfile-5&&1201echo"Tag message in sub directory">subdir/msgfile-5&&1202(1203cd subdir &&1204 git tag -a -F msgfile-5 tag-from-subdir1205) &&1206 git cat-file tag tag-from-subdir|grep"in sub directory"1207'12081209test_expect_success 'filename for the message is relative to cwd' '1210echo"Tag message in sub directory">subdir/msgfile-6&&1211(1212cd subdir &&1213 git tag -a -F msgfile-6 tag-from-subdir-21214) &&1215 git cat-file tag tag-from-subdir-2|grep"in sub directory"1216'12171218# create a few more commits to test --contains12191220hash1=$(git rev-parse HEAD)12211222test_expect_success 'creating second commit and tag' '1223echo foo-2.0 >foo &&1224 git add foo &&1225 git commit -m second &&1226 git tag v2.01227'12281229hash2=$(git rev-parse HEAD)12301231test_expect_success 'creating third commit without tag' '1232echo foo-dev>foo &&1233 git add foo &&1234 git commit -m third1235'12361237hash3=$(git rev-parse HEAD)12381239# simple linear checks of --continue12401241cat > expected <<EOF1242v0.2.11243v1.01244v1.0.11245v1.1.31246v2.01247EOF12481249test_expect_success 'checking that first commit is in all tags (hash)' "1250 git tag -l --contains$hash1v* >actual &&1251 test_cmp expected actual1252"12531254# other ways of specifying the commit1255test_expect_success 'checking that first commit is in all tags (tag)' "1256 git tag -l --contains v1.0 v* >actual &&1257 test_cmp expected actual1258"12591260test_expect_success 'checking that first commit is in all tags (relative)' "1261 git tag -l --contains HEAD~2 v* >actual &&1262 test_cmp expected actual1263"12641265cat > expected <<EOF1266v2.01267EOF12681269test_expect_success 'checking that second commit only has one tag' "1270 git tag -l --contains$hash2v* >actual &&1271 test_cmp expected actual1272"127312741275cat > expected <<EOF1276EOF12771278test_expect_success 'checking that third commit has no tags' "1279 git tag -l --contains$hash3v* >actual &&1280 test_cmp expected actual1281"12821283# how about a simple merge?12841285test_expect_success 'creating simple branch' '1286 git branch stable v2.0 &&1287 git checkout stable &&1288echo foo-3.0 > foo &&1289 git commit foo -m fourth &&1290 git tag v3.01291'12921293hash4=$(git rev-parse HEAD)12941295cat > expected <<EOF1296v3.01297EOF12981299test_expect_success 'checking that branch head only has one tag' "1300 git tag -l --contains$hash4v* >actual &&1301 test_cmp expected actual1302"13031304test_expect_success 'merging original branch into this branch' '1305 git merge --strategy=ours master &&1306 git tag v4.01307'13081309cat > expected <<EOF1310v4.01311EOF13121313test_expect_success 'checking that original branch head has one tag now' "1314 git tag -l --contains$hash3v* >actual &&1315 test_cmp expected actual1316"13171318cat > expected <<EOF1319v0.2.11320v1.01321v1.0.11322v1.1.31323v2.01324v3.01325v4.01326EOF13271328test_expect_success 'checking that initial commit is in all tags' "1329 git tag -l --contains$hash1v* >actual &&1330 test_cmp expected actual1331"13321333# mixing modes and options:13341335test_expect_success 'mixing incompatibles modes and options is forbidden' '1336 test_must_fail git tag -a&&1337 test_must_fail git tag -l -v&&1338 test_must_fail git tag -n100&&1339 test_must_fail git tag -l -m msg &&1340 test_must_fail git tag -l -F some file&&1341 test_must_fail git tag -v -s1342'13431344# check points-at13451346test_expect_success '--points-at cannot be used in non-list mode' '1347 test_must_fail git tag --points-at=v4.0 foo1348'13491350test_expect_success '--points-at finds lightweight tags' '1351echo v4.0 >expect &&1352 git tag --points-at v4.0 >actual &&1353 test_cmp expect actual1354'13551356test_expect_success '--points-at finds annotated tags of commits' '1357 git tag -m"v4.0, annotated" annotated-v4.0 v4.0 &&1358echo annotated-v4.0 >expect &&1359 git tag -l --points-at v4.0 "annotated*">actual &&1360 test_cmp expect actual1361'13621363test_expect_success '--points-at finds annotated tags of tags' '1364 git tag -m"describing the v4.0 tag object" \1365 annotated-again-v4.0 annotated-v4.0 &&1366cat>expect <<-\EOF &&1367 annotated-again-v4.01368 annotated-v4.01369 EOF1370 git tag --points-at=annotated-v4.0 >actual &&1371 test_cmp expect actual1372'13731374test_expect_success 'multiple --points-at are OR-ed together' '1375cat>expect <<-\EOF &&1376 v2.01377 v3.01378 EOF1379 git tag --points-at=v2.0 --points-at=v3.0 >actual &&1380 test_cmp expect actual1381'13821383test_expect_success 'lexical sort' '1384 git tag foo1.3 &&1385 git tag foo1.6 &&1386 git tag foo1.10 &&1387 git tag -l --sort=refname "foo*">actual &&1388cat>expect <<-\EOF &&1389 foo1.101390 foo1.31391 foo1.61392 EOF1393 test_cmp expect actual1394'13951396test_expect_success 'version sort' '1397 git tag -l --sort=version:refname "foo*">actual &&1398cat>expect <<-\EOF &&1399 foo1.31400 foo1.61401 foo1.101402 EOF1403 test_cmp expect actual1404'14051406test_expect_success 'reverse version sort' '1407 git tag -l --sort=-version:refname "foo*">actual &&1408cat>expect <<-\EOF &&1409 foo1.101410 foo1.61411 foo1.31412 EOF1413 test_cmp expect actual1414'14151416test_expect_success 'reverse lexical sort' '1417 git tag -l --sort=-refname"foo*">actual &&1418cat>expect <<-\EOF &&1419 foo1.61420 foo1.31421 foo1.101422 EOF1423 test_cmp expect actual1424'14251426test_expect_success 'configured lexical sort' '1427 git config tag.sort"v:refname"&&1428 git tag -l"foo*">actual &&1429cat>expect <<-\EOF &&1430 foo1.31431 foo1.61432 foo1.101433 EOF1434 test_cmp expect actual1435'14361437test_expect_success 'option override configured sort' '1438 git tag -l --sort=-refname"foo*">actual &&1439cat>expect <<-\EOF &&1440 foo1.61441 foo1.31442 foo1.101443 EOF1444 test_cmp expect actual1445'14461447test_expect_success 'invalid sort parameter on command line' '1448 test_must_fail git tag -l --sort=notvalid "foo*">actual1449'14501451test_expect_success 'invalid sort parameter in configuratoin' '1452 git config tag.sort"v:notvalid"&&1453 git tag -l"foo*">actual &&1454cat>expect <<-\EOF &&1455 foo1.101456 foo1.31457 foo1.61458 EOF1459 test_cmp expect actual1460'14611462run_with_limited_stack () {1463 (ulimit -s 64 && "$@")1464}14651466test_lazy_prereq ULIMIT 'run_with_limited_stack true'14671468# we require ulimit, this excludes Windows1469test_expect_success ULIMIT '--contains works in a deep repo' '1470>expect &&1471 i=1&&1472whiletest$i-lt40001473do1474echo"commit refs/heads/master1475committer A U Thor <author@example.com>$((1000000000 + $i * 100)) +02001476data <<EOF1477commit #$i1478EOF"1479test$i=1&&echo"from refs/heads/master^0"1480 i=$(($i + 1))1481done| git fast-import&&1482 git checkout master &&1483 git tag far-far-away HEAD^ &&1484 run_with_limited_stack git tag --contains HEAD >actual &&1485 test_cmp expect actual1486'14871488test_done