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