t / t7004-tag.shon commit Make git tag a builtin. (62e09ce)
   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
 335# blank and empty messages:
 336
 337get_tag_header empty-annotated-tag $commit commit $time >expect
 338test_expect_success \
 339        'creating a tag with an empty -m message should succeed' '
 340        git-tag -m "" empty-annotated-tag &&
 341        get_tag_msg empty-annotated-tag >actual &&
 342        git diff expect actual
 343'
 344
 345>emptyfile
 346get_tag_header emptyfile-annotated-tag $commit commit $time >expect
 347test_expect_success \
 348        'creating a tag with an empty -F messagefile should succeed' '
 349        git-tag -F emptyfile emptyfile-annotated-tag &&
 350        get_tag_msg emptyfile-annotated-tag >actual &&
 351        git diff expect actual
 352'
 353
 354printf '\n\n  \n\t\nLeading blank lines\n' >blanksfile
 355printf '\n\t \t  \nRepeated blank lines\n' >>blanksfile
 356printf '\n\n\nTrailing spaces      \t  \n' >>blanksfile
 357printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
 358get_tag_header blanks-annotated-tag $commit commit $time >expect
 359cat >>expect <<EOF
 360Leading blank lines
 361
 362Repeated blank lines
 363
 364Trailing spaces
 365
 366Trailing blank lines
 367EOF
 368test_expect_success \
 369        'extra blanks in the message for an annotated tag should be removed' '
 370        git-tag -F blanksfile blanks-annotated-tag &&
 371        get_tag_msg blanks-annotated-tag >actual &&
 372        git diff expect actual
 373'
 374
 375get_tag_header blank-annotated-tag $commit commit $time >expect
 376test_expect_success \
 377        'creating a tag with blank -m message with spaces should succeed' '
 378        git-tag -m "     " blank-annotated-tag &&
 379        get_tag_msg blank-annotated-tag >actual &&
 380        git diff expect actual
 381'
 382
 383echo '     ' >blankfile
 384echo ''      >>blankfile
 385echo '  '    >>blankfile
 386get_tag_header blankfile-annotated-tag $commit commit $time >expect
 387test_expect_success \
 388        'creating a tag with blank -F messagefile with spaces should succeed' '
 389        git-tag -F blankfile blankfile-annotated-tag &&
 390        get_tag_msg blankfile-annotated-tag >actual &&
 391        git diff expect actual
 392'
 393
 394printf '      ' >blanknonlfile
 395get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
 396test_expect_success \
 397        'creating a tag with -F file of spaces and no newline should succeed' '
 398        git-tag -F blanknonlfile blanknonlfile-annotated-tag &&
 399        get_tag_msg blanknonlfile-annotated-tag >actual &&
 400        git diff expect actual
 401'
 402
 403# messages with commented lines:
 404
 405cat >commentsfile <<EOF
 406# A comment
 407
 408############
 409The message.
 410############
 411One line.
 412
 413
 414# commented lines
 415# commented lines
 416
 417Another line.
 418# comments
 419
 420Last line.
 421EOF
 422get_tag_header comments-annotated-tag $commit commit $time >expect
 423cat >>expect <<EOF
 424The message.
 425One line.
 426
 427Another line.
 428
 429Last line.
 430EOF
 431test_expect_success \
 432        'creating a tag using a -F messagefile with #comments should succeed' '
 433        git-tag -F commentsfile comments-annotated-tag &&
 434        get_tag_msg comments-annotated-tag >actual &&
 435        git diff expect actual
 436'
 437
 438get_tag_header comment-annotated-tag $commit commit $time >expect
 439test_expect_success \
 440        'creating a tag with a #comment in the -m message should succeed' '
 441        git-tag -m "#comment" comment-annotated-tag &&
 442        get_tag_msg comment-annotated-tag >actual &&
 443        git diff expect actual
 444'
 445
 446echo '#comment' >commentfile
 447echo ''         >>commentfile
 448echo '####'     >>commentfile
 449get_tag_header commentfile-annotated-tag $commit commit $time >expect
 450test_expect_success \
 451        'creating a tag with #comments in the -F messagefile should succeed' '
 452        git-tag -F commentfile commentfile-annotated-tag &&
 453        get_tag_msg commentfile-annotated-tag >actual &&
 454        git diff expect actual
 455'
 456
 457printf '#comment' >commentnonlfile
 458get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
 459test_expect_success \
 460        'creating a tag with a file of #comment and no newline should succeed' '
 461        git-tag -F commentnonlfile commentnonlfile-annotated-tag &&
 462        get_tag_msg commentnonlfile-annotated-tag >actual &&
 463        git diff expect actual
 464'
 465
 466# listing messages for annotated non-signed tags:
 467
 468test_expect_success \
 469        'listing the one-line message of a non-signed tag should succeed' '
 470        git-tag -m "A msg" tag-one-line &&
 471
 472        echo "tag-one-line" >expect &&
 473        git-tag -l | grep "^tag-one-line" >actual &&
 474        git diff expect actual &&
 475        git-tag -n 0 -l | grep "^tag-one-line" >actual &&
 476        git diff expect actual &&
 477        git-tag -n 0 -l tag-one-line >actual &&
 478        git diff expect actual &&
 479
 480        echo "tag-one-line    A msg" >expect &&
 481        git-tag -n xxx -l | grep "^tag-one-line" >actual &&
 482        git diff expect actual &&
 483        git-tag -n "" -l | grep "^tag-one-line" >actual &&
 484        git diff expect actual &&
 485        git-tag -n 1 -l | grep "^tag-one-line" >actual &&
 486        git diff expect actual &&
 487        git-tag -n -l | grep "^tag-one-line" >actual &&
 488        git diff expect actual &&
 489        git-tag -n 1 -l tag-one-line >actual &&
 490        git diff expect actual &&
 491        git-tag -n 2 -l tag-one-line >actual &&
 492        git diff expect actual &&
 493        git-tag -n 999 -l tag-one-line >actual &&
 494        git diff expect actual
 495'
 496
 497test_expect_success \
 498        'listing the zero-lines message of a non-signed tag should succeed' '
 499        git-tag -m "" tag-zero-lines &&
 500
 501        echo "tag-zero-lines" >expect &&
 502        git-tag -l | grep "^tag-zero-lines" >actual &&
 503        git diff expect actual &&
 504        git-tag -n 0 -l | grep "^tag-zero-lines" >actual &&
 505        git diff expect actual &&
 506        git-tag -n 0 -l tag-zero-lines >actual &&
 507        git diff expect actual &&
 508
 509        echo "tag-zero-lines  " >expect &&
 510        git-tag -n 1 -l | grep "^tag-zero-lines" >actual &&
 511        git diff expect actual &&
 512        git-tag -n -l | grep "^tag-zero-lines" >actual &&
 513        git diff expect actual &&
 514        git-tag -n 1 -l tag-zero-lines >actual &&
 515        git diff expect actual &&
 516        git-tag -n 2 -l tag-zero-lines >actual &&
 517        git diff expect actual &&
 518        git-tag -n 999 -l tag-zero-lines >actual &&
 519        git diff expect actual
 520'
 521
 522echo 'tag line one' >annotagmsg
 523echo 'tag line two' >>annotagmsg
 524echo 'tag line three' >>annotagmsg
 525test_expect_success \
 526        'listing many message lines of a non-signed tag should succeed' '
 527        git-tag -F annotagmsg tag-lines &&
 528
 529        echo "tag-lines" >expect &&
 530        git-tag -l | grep "^tag-lines" >actual &&
 531        git diff expect actual &&
 532        git-tag -n 0 -l | grep "^tag-lines" >actual &&
 533        git diff expect actual &&
 534        git-tag -n 0 -l tag-lines >actual &&
 535        git diff expect actual &&
 536
 537        echo "tag-lines       tag line one" >expect &&
 538        git-tag -n 1 -l | grep "^tag-lines" >actual &&
 539        git diff expect actual &&
 540        git-tag -n -l | grep "^tag-lines" >actual &&
 541        git diff expect actual &&
 542        git-tag -n 1 -l tag-lines >actual &&
 543        git diff expect actual &&
 544
 545        echo "    tag line two" >>expect &&
 546        git-tag -n 2 -l | grep "^ *tag.line" >actual &&
 547        git diff expect actual &&
 548        git-tag -n 2 -l tag-lines >actual &&
 549        git diff expect actual &&
 550
 551        echo "    tag line three" >>expect &&
 552        git-tag -n 3 -l | grep "^ *tag.line" >actual &&
 553        git diff expect actual &&
 554        git-tag -n 3 -l tag-lines >actual &&
 555        git diff expect actual &&
 556        git-tag -n 4 -l | grep "^ *tag.line" >actual &&
 557        git diff expect actual &&
 558        git-tag -n 4 -l tag-lines >actual &&
 559        git diff expect actual &&
 560        git-tag -n 99 -l | grep "^ *tag.line" >actual &&
 561        git diff expect actual &&
 562        git-tag -n 99 -l tag-lines >actual &&
 563        git diff expect actual
 564'
 565
 566# trying to verify annotated non-signed tags:
 567
 568test_expect_success \
 569        'trying to verify an annotated non-signed tag should fail' '
 570        tag_exists annotated-tag &&
 571        ! git-tag -v annotated-tag
 572'
 573
 574test_expect_success \
 575        'trying to verify a file-annotated non-signed tag should fail' '
 576        tag_exists file-annotated-tag &&
 577        ! git-tag -v file-annotated-tag
 578'
 579
 580test_expect_success \
 581        'trying to verify two annotated non-signed tags should fail' '
 582        tag_exists annotated-tag file-annotated-tag &&
 583        ! git-tag -v annotated-tag file-annotated-tag
 584'
 585
 586# creating and verifying signed tags:
 587
 588gpg --version >/dev/null
 589if [ $? -eq 127 ]; then
 590        echo "Skipping signed tags tests, because gpg was not found"
 591        test_done
 592        exit
 593fi
 594
 595# As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
 596# the gpg version 1.0.6 didn't parse trust packets correctly, so for
 597# that version, creation of signed tags using the generated key fails.
 598case "$(gpg --version)" in
 599'gpg (GnuPG) 1.0.6'*)
 600        echo "Skipping signed tag tests, because a bug in 1.0.6 version"
 601        test_done
 602        exit
 603        ;;
 604esac
 605
 606# key generation info: gpg --homedir t/t7004 --gen-key
 607# Type DSA and Elgamal, size 2048 bits, no expiration date.
 608# Name and email: C O Mitter <committer@example.com>
 609# No password given, to enable non-interactive operation.
 610
 611cp -R ../t7004 ./gpghome
 612chmod 0700 gpghome
 613export GNUPGHOME="$(pwd)/gpghome"
 614
 615get_tag_header signed-tag $commit commit $time >expect
 616echo 'A signed tag message' >>expect
 617echo '-----BEGIN PGP SIGNATURE-----' >>expect
 618test_expect_success 'creating a signed tag with -m message should succeed' '
 619        git-tag -s -m "A signed tag message" signed-tag &&
 620        get_tag_msg signed-tag >actual &&
 621        git diff expect actual
 622'
 623
 624cat >sigmsgfile <<EOF
 625Another signed tag
 626message in a file.
 627EOF
 628get_tag_header file-signed-tag $commit commit $time >expect
 629cat sigmsgfile >>expect
 630echo '-----BEGIN PGP SIGNATURE-----' >>expect
 631test_expect_success \
 632        'creating a signed tag with -F messagefile should succeed' '
 633        git-tag -s -F sigmsgfile file-signed-tag &&
 634        get_tag_msg file-signed-tag >actual &&
 635        git diff expect actual
 636'
 637
 638cat >siginputmsg <<EOF
 639A signed tag message from
 640the standard input
 641EOF
 642get_tag_header stdin-signed-tag $commit commit $time >expect
 643cat siginputmsg >>expect
 644echo '-----BEGIN PGP SIGNATURE-----' >>expect
 645test_expect_success 'creating a signed tag with -F - should succeed' '
 646        git-tag -s -F - stdin-signed-tag <siginputmsg &&
 647        get_tag_msg stdin-signed-tag >actual &&
 648        git diff expect actual
 649'
 650
 651test_expect_success 'verifying a signed tag should succeed' \
 652        'git-tag -v signed-tag'
 653
 654test_expect_success 'verifying two signed tags in one command should succeed' \
 655        'git-tag -v signed-tag file-signed-tag'
 656
 657test_expect_success \
 658        'verifying many signed and non-signed tags should fail' '
 659        ! git-tag -v signed-tag annotated-tag &&
 660        ! git-tag -v file-annotated-tag file-signed-tag &&
 661        ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
 662        ! git-tag -v signed-tag annotated-tag file-signed-tag
 663'
 664
 665test_expect_success 'verifying a forged tag should fail' '
 666        forged=$(git cat-file tag signed-tag |
 667                sed -e "s/signed-tag/forged-tag/" |
 668                git mktag) &&
 669        git tag forged-tag $forged &&
 670        ! git-tag -v forged-tag
 671'
 672
 673# blank and empty messages for signed tags:
 674
 675get_tag_header empty-signed-tag $commit commit $time >expect
 676echo '-----BEGIN PGP SIGNATURE-----' >>expect
 677test_expect_success \
 678        'creating a signed tag with an empty -m message should succeed' '
 679        git-tag -s -m "" empty-signed-tag &&
 680        get_tag_msg empty-signed-tag >actual &&
 681        git diff expect actual &&
 682        git-tag -v empty-signed-tag
 683'
 684
 685>sigemptyfile
 686get_tag_header emptyfile-signed-tag $commit commit $time >expect
 687echo '-----BEGIN PGP SIGNATURE-----' >>expect
 688test_expect_success \
 689        'creating a signed tag with an empty -F messagefile should succeed' '
 690        git-tag -s -F sigemptyfile emptyfile-signed-tag &&
 691        get_tag_msg emptyfile-signed-tag >actual &&
 692        git diff expect actual &&
 693        git-tag -v emptyfile-signed-tag
 694'
 695
 696printf '\n\n  \n\t\nLeading blank lines\n' > sigblanksfile
 697printf '\n\t \t  \nRepeated blank lines\n' >>sigblanksfile
 698printf '\n\n\nTrailing spaces      \t  \n' >>sigblanksfile
 699printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
 700get_tag_header blanks-signed-tag $commit commit $time >expect
 701cat >>expect <<EOF
 702Leading blank lines
 703
 704Repeated blank lines
 705
 706Trailing spaces
 707
 708Trailing blank lines
 709EOF
 710echo '-----BEGIN PGP SIGNATURE-----' >>expect
 711test_expect_success \
 712        'extra blanks in the message for a signed tag should be removed' '
 713        git-tag -s -F sigblanksfile blanks-signed-tag &&
 714        get_tag_msg blanks-signed-tag >actual &&
 715        git diff expect actual &&
 716        git-tag -v blanks-signed-tag
 717'
 718
 719get_tag_header blank-signed-tag $commit commit $time >expect
 720echo '-----BEGIN PGP SIGNATURE-----' >>expect
 721test_expect_success \
 722        'creating a signed tag with a blank -m message should succeed' '
 723        git-tag -s -m "     " blank-signed-tag &&
 724        get_tag_msg blank-signed-tag >actual &&
 725        git diff expect actual &&
 726        git-tag -v blank-signed-tag
 727'
 728
 729echo '     ' >sigblankfile
 730echo ''      >>sigblankfile
 731echo '  '    >>sigblankfile
 732get_tag_header blankfile-signed-tag $commit commit $time >expect
 733echo '-----BEGIN PGP SIGNATURE-----' >>expect
 734test_expect_success \
 735        'creating a signed tag with blank -F file with spaces should succeed' '
 736        git-tag -s -F sigblankfile blankfile-signed-tag &&
 737        get_tag_msg blankfile-signed-tag >actual &&
 738        git diff expect actual &&
 739        git-tag -v blankfile-signed-tag
 740'
 741
 742printf '      ' >sigblanknonlfile
 743get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
 744echo '-----BEGIN PGP SIGNATURE-----' >>expect
 745test_expect_success \
 746        'creating a signed tag with spaces and no newline should succeed' '
 747        git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
 748        get_tag_msg blanknonlfile-signed-tag >actual &&
 749        git diff expect actual &&
 750        git-tag -v signed-tag
 751'
 752
 753# messages with commented lines for signed tags:
 754
 755cat >sigcommentsfile <<EOF
 756# A comment
 757
 758############
 759The message.
 760############
 761One line.
 762
 763
 764# commented lines
 765# commented lines
 766
 767Another line.
 768# comments
 769
 770Last line.
 771EOF
 772get_tag_header comments-signed-tag $commit commit $time >expect
 773cat >>expect <<EOF
 774The message.
 775One line.
 776
 777Another line.
 778
 779Last line.
 780EOF
 781echo '-----BEGIN PGP SIGNATURE-----' >>expect
 782test_expect_success \
 783        'creating a signed tag with a -F file with #comments should succeed' '
 784        git-tag -s -F sigcommentsfile comments-signed-tag &&
 785        get_tag_msg comments-signed-tag >actual &&
 786        git diff expect actual &&
 787        git-tag -v comments-signed-tag
 788'
 789
 790get_tag_header comment-signed-tag $commit commit $time >expect
 791echo '-----BEGIN PGP SIGNATURE-----' >>expect
 792test_expect_success \
 793        'creating a signed tag with #commented -m message should succeed' '
 794        git-tag -s -m "#comment" comment-signed-tag &&
 795        get_tag_msg comment-signed-tag >actual &&
 796        git diff expect actual &&
 797        git-tag -v comment-signed-tag
 798'
 799
 800echo '#comment' >sigcommentfile
 801echo ''         >>sigcommentfile
 802echo '####'     >>sigcommentfile
 803get_tag_header commentfile-signed-tag $commit commit $time >expect
 804echo '-----BEGIN PGP SIGNATURE-----' >>expect
 805test_expect_success \
 806        'creating a signed tag with #commented -F messagefile should succeed' '
 807        git-tag -s -F sigcommentfile commentfile-signed-tag &&
 808        get_tag_msg commentfile-signed-tag >actual &&
 809        git diff expect actual &&
 810        git-tag -v commentfile-signed-tag
 811'
 812
 813printf '#comment' >sigcommentnonlfile
 814get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
 815echo '-----BEGIN PGP SIGNATURE-----' >>expect
 816test_expect_success \
 817        'creating a signed tag with a #comment and no newline should succeed' '
 818        git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
 819        get_tag_msg commentnonlfile-signed-tag >actual &&
 820        git diff expect actual &&
 821        git-tag -v commentnonlfile-signed-tag
 822'
 823
 824# listing messages for signed tags:
 825
 826test_expect_success \
 827        'listing the one-line message of a signed tag should succeed' '
 828        git-tag -s -m "A message line signed" stag-one-line &&
 829
 830        echo "stag-one-line" >expect &&
 831        git-tag -l | grep "^stag-one-line" >actual &&
 832        git diff expect actual &&
 833        git-tag -n 0 -l | grep "^stag-one-line" >actual &&
 834        git diff expect actual &&
 835        git-tag -n 0 -l stag-one-line >actual &&
 836        git diff expect actual &&
 837
 838        echo "stag-one-line   A message line signed" >expect &&
 839        git-tag -n xxx -l | grep "^stag-one-line" >actual &&
 840        git diff expect actual &&
 841        git-tag -n "" -l | grep "^stag-one-line" >actual &&
 842        git diff expect actual &&
 843        git-tag -n 1 -l | grep "^stag-one-line" >actual &&
 844        git diff expect actual &&
 845        git-tag -n -l | grep "^stag-one-line" >actual &&
 846        git diff expect actual &&
 847        git-tag -n 1 -l stag-one-line >actual &&
 848        git diff expect actual &&
 849        git-tag -n 2 -l stag-one-line >actual &&
 850        git diff expect actual &&
 851        git-tag -n 999 -l stag-one-line >actual &&
 852        git diff expect actual
 853'
 854
 855test_expect_success \
 856        'listing the zero-lines message of a signed tag should succeed' '
 857        git-tag -s -m "" stag-zero-lines &&
 858
 859        echo "stag-zero-lines" >expect &&
 860        git-tag -l | grep "^stag-zero-lines" >actual &&
 861        git diff expect actual &&
 862        git-tag -n 0 -l | grep "^stag-zero-lines" >actual &&
 863        git diff expect actual &&
 864        git-tag -n 0 -l stag-zero-lines >actual &&
 865        git diff expect actual &&
 866
 867        echo "stag-zero-lines " >expect &&
 868        git-tag -n 1 -l | grep "^stag-zero-lines" >actual &&
 869        git diff expect actual &&
 870        git-tag -n -l | grep "^stag-zero-lines" >actual &&
 871        git diff expect actual &&
 872        git-tag -n 1 -l stag-zero-lines >actual &&
 873        git diff expect actual &&
 874        git-tag -n 2 -l stag-zero-lines >actual &&
 875        git diff expect actual &&
 876        git-tag -n 999 -l stag-zero-lines >actual &&
 877        git diff expect actual
 878'
 879
 880echo 'stag line one' >sigtagmsg
 881echo 'stag line two' >>sigtagmsg
 882echo 'stag line three' >>sigtagmsg
 883test_expect_success \
 884        'listing many message lines of a signed tag should succeed' '
 885        git-tag -s -F sigtagmsg stag-lines &&
 886
 887        echo "stag-lines" >expect &&
 888        git-tag -l | grep "^stag-lines" >actual &&
 889        git diff expect actual &&
 890        git-tag -n 0 -l | grep "^stag-lines" >actual &&
 891        git diff expect actual &&
 892        git-tag -n 0 -l stag-lines >actual &&
 893        git diff expect actual &&
 894
 895        echo "stag-lines      stag line one" >expect &&
 896        git-tag -n 1 -l | grep "^stag-lines" >actual &&
 897        git diff expect actual &&
 898        git-tag -n -l | grep "^stag-lines" >actual &&
 899        git diff expect actual &&
 900        git-tag -n 1 -l stag-lines >actual &&
 901        git diff expect actual &&
 902
 903        echo "    stag line two" >>expect &&
 904        git-tag -n 2 -l | grep "^ *stag.line" >actual &&
 905        git diff expect actual &&
 906        git-tag -n 2 -l stag-lines >actual &&
 907        git diff expect actual &&
 908
 909        echo "    stag line three" >>expect &&
 910        git-tag -n 3 -l | grep "^ *stag.line" >actual &&
 911        git diff expect actual &&
 912        git-tag -n 3 -l stag-lines >actual &&
 913        git diff expect actual &&
 914        git-tag -n 4 -l | grep "^ *stag.line" >actual &&
 915        git diff expect actual &&
 916        git-tag -n 4 -l stag-lines >actual &&
 917        git diff expect actual &&
 918        git-tag -n 99 -l | grep "^ *stag.line" >actual &&
 919        git diff expect actual &&
 920        git-tag -n 99 -l stag-lines >actual &&
 921        git diff expect actual
 922'
 923
 924# tags pointing to objects different from commits:
 925
 926tree=$(git rev-parse HEAD^{tree})
 927blob=$(git rev-parse HEAD:foo)
 928tag=$(git rev-parse signed-tag)
 929
 930get_tag_header tree-signed-tag $tree tree $time >expect
 931echo "A message for a tree" >>expect
 932echo '-----BEGIN PGP SIGNATURE-----' >>expect
 933test_expect_success \
 934        'creating a signed tag pointing to a tree should succeed' '
 935        git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
 936        get_tag_msg tree-signed-tag >actual &&
 937        git diff expect actual
 938'
 939
 940get_tag_header blob-signed-tag $blob blob $time >expect
 941echo "A message for a blob" >>expect
 942echo '-----BEGIN PGP SIGNATURE-----' >>expect
 943test_expect_success \
 944        'creating a signed tag pointing to a blob should succeed' '
 945        git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
 946        get_tag_msg blob-signed-tag >actual &&
 947        git diff expect actual
 948'
 949
 950get_tag_header tag-signed-tag $tag tag $time >expect
 951echo "A message for another tag" >>expect
 952echo '-----BEGIN PGP SIGNATURE-----' >>expect
 953test_expect_success \
 954        'creating a signed tag pointing to another tag should succeed' '
 955        git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
 956        get_tag_msg tag-signed-tag >actual &&
 957        git diff expect actual
 958'
 959
 960# try to verify without gpg:
 961
 962rm -rf gpghome
 963test_expect_failure \
 964        'verify signed tag fails when public key is not present' \
 965        'git-tag -v signed-tag'
 966
 967test_done