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