t / t7004-tag.shon commit builtin-remote: prune remotes correctly that were added with --mirror (4ebc914)
   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        ! 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_success \
  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_success '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
 195EOF
 196test_expect_success \
 197        'listing tags with a suffix as pattern must print those matching' '
 198        git-tag -l "*.1" > actual &&
 199        git diff expect actual
 200'
 201
 202cat >expect <<EOF
 203t210
 204t211
 205EOF
 206test_expect_success \
 207        'listing tags with a prefix as pattern must print those matching' '
 208        git-tag -l "t21*" > actual &&
 209        git diff expect actual
 210'
 211
 212cat >expect <<EOF
 213a1
 214EOF
 215test_expect_success \
 216        'listing tags using a name as pattern must print that one matching' '
 217        git-tag -l a1 > actual &&
 218        git diff expect actual
 219'
 220
 221cat >expect <<EOF
 222v1.0
 223EOF
 224test_expect_success \
 225        'listing tags using a name as pattern must print that one matching' '
 226        git-tag -l v1.0 > actual &&
 227        git diff expect actual
 228'
 229
 230cat >expect <<EOF
 231v1.0.1
 232v1.1.3
 233EOF
 234test_expect_success \
 235        'listing tags with ? in the pattern should print those matching' '
 236        git-tag -l "v1.?.?" > actual &&
 237        git diff expect actual
 238'
 239
 240>expect
 241test_expect_success \
 242        'listing tags using v.* should print nothing because none have v.' '
 243        git-tag -l "v.*" > actual &&
 244        git diff expect actual
 245'
 246
 247cat >expect <<EOF
 248v0.2.1
 249v1.0
 250v1.0.1
 251v1.1.3
 252EOF
 253test_expect_success \
 254        'listing tags using v* should print only those having v' '
 255        git-tag -l "v*" > actual &&
 256        git diff expect actual
 257'
 258
 259# creating and verifying lightweight tags:
 260
 261test_expect_success \
 262        'a non-annotated tag created without parameters should point to HEAD' '
 263        git-tag non-annotated-tag &&
 264        test $(git cat-file -t non-annotated-tag) = commit &&
 265        test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
 266'
 267
 268test_expect_success 'trying to verify an unknown tag should fail' \
 269        '! git-tag -v unknown-tag'
 270
 271test_expect_success \
 272        'trying to verify a non-annotated and non-signed tag should fail' \
 273        '! git-tag -v non-annotated-tag'
 274
 275test_expect_success \
 276        'trying to verify many non-annotated or unknown tags, should fail' \
 277        '! git-tag -v unknown-tag1 non-annotated-tag unknown-tag2'
 278
 279# creating annotated tags:
 280
 281get_tag_msg () {
 282        git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
 283}
 284
 285# run test_tick before committing always gives the time in that timezone
 286get_tag_header () {
 287cat <<EOF
 288object $2
 289type $3
 290tag $1
 291tagger C O Mitter <committer@example.com> $4 -0700
 292
 293EOF
 294}
 295
 296commit=$(git rev-parse HEAD)
 297time=$test_tick
 298
 299get_tag_header annotated-tag $commit commit $time >expect
 300echo "A message" >>expect
 301test_expect_success \
 302        'creating an annotated tag with -m message should succeed' '
 303        git-tag -m "A message" annotated-tag &&
 304        get_tag_msg annotated-tag >actual &&
 305        git diff expect actual
 306'
 307
 308cat >msgfile <<EOF
 309Another message
 310in a file.
 311EOF
 312get_tag_header file-annotated-tag $commit commit $time >expect
 313cat msgfile >>expect
 314test_expect_success \
 315        'creating an annotated tag with -F messagefile should succeed' '
 316        git-tag -F msgfile file-annotated-tag &&
 317        get_tag_msg file-annotated-tag >actual &&
 318        git diff expect actual
 319'
 320
 321cat >inputmsg <<EOF
 322A message from the
 323standard input
 324EOF
 325get_tag_header stdin-annotated-tag $commit commit $time >expect
 326cat inputmsg >>expect
 327test_expect_success 'creating an annotated tag with -F - should succeed' '
 328        git-tag -F - stdin-annotated-tag <inputmsg &&
 329        get_tag_msg stdin-annotated-tag >actual &&
 330        git diff expect actual
 331'
 332
 333test_expect_success \
 334        'trying to create a tag with a non-existing -F file should fail' '
 335        ! test -f nonexistingfile &&
 336        ! tag_exists notag &&
 337        ! git-tag -F nonexistingfile notag &&
 338        ! tag_exists notag
 339'
 340
 341test_expect_success \
 342        'trying to create tags giving both -m or -F options should fail' '
 343        echo "message file 1" >msgfile1 &&
 344        echo "message file 2" >msgfile2 &&
 345        ! tag_exists msgtag &&
 346        ! git-tag -m "message 1" -F msgfile1 msgtag &&
 347        ! tag_exists msgtag &&
 348        ! git-tag -F msgfile1 -m "message 1" msgtag &&
 349        ! tag_exists msgtag &&
 350        ! git-tag -m "message 1" -F msgfile1 -m "message 2" msgtag &&
 351        ! tag_exists msgtag
 352'
 353
 354# blank and empty messages:
 355
 356get_tag_header empty-annotated-tag $commit commit $time >expect
 357test_expect_success \
 358        'creating a tag with an empty -m message should succeed' '
 359        git-tag -m "" empty-annotated-tag &&
 360        get_tag_msg empty-annotated-tag >actual &&
 361        git diff expect actual
 362'
 363
 364>emptyfile
 365get_tag_header emptyfile-annotated-tag $commit commit $time >expect
 366test_expect_success \
 367        'creating a tag with an empty -F messagefile should succeed' '
 368        git-tag -F emptyfile emptyfile-annotated-tag &&
 369        get_tag_msg emptyfile-annotated-tag >actual &&
 370        git diff expect actual
 371'
 372
 373printf '\n\n  \n\t\nLeading blank lines\n' >blanksfile
 374printf '\n\t \t  \nRepeated blank lines\n' >>blanksfile
 375printf '\n\n\nTrailing spaces      \t  \n' >>blanksfile
 376printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
 377get_tag_header blanks-annotated-tag $commit commit $time >expect
 378cat >>expect <<EOF
 379Leading blank lines
 380
 381Repeated blank lines
 382
 383Trailing spaces
 384
 385Trailing blank lines
 386EOF
 387test_expect_success \
 388        'extra blanks in the message for an annotated tag should be removed' '
 389        git-tag -F blanksfile blanks-annotated-tag &&
 390        get_tag_msg blanks-annotated-tag >actual &&
 391        git diff expect actual
 392'
 393
 394get_tag_header blank-annotated-tag $commit commit $time >expect
 395test_expect_success \
 396        'creating a tag with blank -m message with spaces should succeed' '
 397        git-tag -m "     " blank-annotated-tag &&
 398        get_tag_msg blank-annotated-tag >actual &&
 399        git diff expect actual
 400'
 401
 402echo '     ' >blankfile
 403echo ''      >>blankfile
 404echo '  '    >>blankfile
 405get_tag_header blankfile-annotated-tag $commit commit $time >expect
 406test_expect_success \
 407        'creating a tag with blank -F messagefile with spaces should succeed' '
 408        git-tag -F blankfile blankfile-annotated-tag &&
 409        get_tag_msg blankfile-annotated-tag >actual &&
 410        git diff expect actual
 411'
 412
 413printf '      ' >blanknonlfile
 414get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
 415test_expect_success \
 416        'creating a tag with -F file of spaces and no newline should succeed' '
 417        git-tag -F blanknonlfile blanknonlfile-annotated-tag &&
 418        get_tag_msg blanknonlfile-annotated-tag >actual &&
 419        git diff expect actual
 420'
 421
 422# messages with commented lines:
 423
 424cat >commentsfile <<EOF
 425# A comment
 426
 427############
 428The message.
 429############
 430One line.
 431
 432
 433# commented lines
 434# commented lines
 435
 436Another line.
 437# comments
 438
 439Last line.
 440EOF
 441get_tag_header comments-annotated-tag $commit commit $time >expect
 442cat >>expect <<EOF
 443The message.
 444One line.
 445
 446Another line.
 447
 448Last line.
 449EOF
 450test_expect_success \
 451        'creating a tag using a -F messagefile with #comments should succeed' '
 452        git-tag -F commentsfile comments-annotated-tag &&
 453        get_tag_msg comments-annotated-tag >actual &&
 454        git diff expect actual
 455'
 456
 457get_tag_header comment-annotated-tag $commit commit $time >expect
 458test_expect_success \
 459        'creating a tag with a #comment in the -m message should succeed' '
 460        git-tag -m "#comment" comment-annotated-tag &&
 461        get_tag_msg comment-annotated-tag >actual &&
 462        git diff expect actual
 463'
 464
 465echo '#comment' >commentfile
 466echo ''         >>commentfile
 467echo '####'     >>commentfile
 468get_tag_header commentfile-annotated-tag $commit commit $time >expect
 469test_expect_success \
 470        'creating a tag with #comments in the -F messagefile should succeed' '
 471        git-tag -F commentfile commentfile-annotated-tag &&
 472        get_tag_msg commentfile-annotated-tag >actual &&
 473        git diff expect actual
 474'
 475
 476printf '#comment' >commentnonlfile
 477get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
 478test_expect_success \
 479        'creating a tag with a file of #comment and no newline should succeed' '
 480        git-tag -F commentnonlfile commentnonlfile-annotated-tag &&
 481        get_tag_msg commentnonlfile-annotated-tag >actual &&
 482        git diff expect actual
 483'
 484
 485# listing messages for annotated non-signed tags:
 486
 487test_expect_success \
 488        'listing the one-line message of a non-signed tag should succeed' '
 489        git-tag -m "A msg" tag-one-line &&
 490
 491        echo "tag-one-line" >expect &&
 492        git-tag -l | grep "^tag-one-line" >actual &&
 493        git diff expect actual &&
 494        git-tag -n0 -l | grep "^tag-one-line" >actual &&
 495        git diff expect actual &&
 496        git-tag -n0 -l tag-one-line >actual &&
 497        git diff expect actual &&
 498
 499        echo "tag-one-line    A msg" >expect &&
 500        git-tag -n1 -l | grep "^tag-one-line" >actual &&
 501        git diff expect actual &&
 502        git-tag -n -l | grep "^tag-one-line" >actual &&
 503        git diff expect actual &&
 504        git-tag -n1 -l tag-one-line >actual &&
 505        git diff expect actual &&
 506        git-tag -n2 -l tag-one-line >actual &&
 507        git diff expect actual &&
 508        git-tag -n999 -l tag-one-line >actual &&
 509        git diff expect actual
 510'
 511
 512test_expect_success \
 513        'listing the zero-lines message of a non-signed tag should succeed' '
 514        git-tag -m "" tag-zero-lines &&
 515
 516        echo "tag-zero-lines" >expect &&
 517        git-tag -l | grep "^tag-zero-lines" >actual &&
 518        git diff expect actual &&
 519        git-tag -n0 -l | grep "^tag-zero-lines" >actual &&
 520        git diff expect actual &&
 521        git-tag -n0 -l tag-zero-lines >actual &&
 522        git diff expect actual &&
 523
 524        echo "tag-zero-lines  " >expect &&
 525        git-tag -n1 -l | grep "^tag-zero-lines" >actual &&
 526        git diff expect actual &&
 527        git-tag -n -l | grep "^tag-zero-lines" >actual &&
 528        git diff expect actual &&
 529        git-tag -n1 -l tag-zero-lines >actual &&
 530        git diff expect actual &&
 531        git-tag -n2 -l tag-zero-lines >actual &&
 532        git diff expect actual &&
 533        git-tag -n999 -l tag-zero-lines >actual &&
 534        git diff expect actual
 535'
 536
 537echo 'tag line one' >annotagmsg
 538echo 'tag line two' >>annotagmsg
 539echo 'tag line three' >>annotagmsg
 540test_expect_success \
 541        'listing many message lines of a non-signed tag should succeed' '
 542        git-tag -F annotagmsg tag-lines &&
 543
 544        echo "tag-lines" >expect &&
 545        git-tag -l | grep "^tag-lines" >actual &&
 546        git diff expect actual &&
 547        git-tag -n0 -l | grep "^tag-lines" >actual &&
 548        git diff expect actual &&
 549        git-tag -n0 -l tag-lines >actual &&
 550        git diff expect actual &&
 551
 552        echo "tag-lines       tag line one" >expect &&
 553        git-tag -n1 -l | grep "^tag-lines" >actual &&
 554        git diff expect actual &&
 555        git-tag -n -l | grep "^tag-lines" >actual &&
 556        git diff expect actual &&
 557        git-tag -n1 -l tag-lines >actual &&
 558        git diff expect actual &&
 559
 560        echo "    tag line two" >>expect &&
 561        git-tag -n2 -l | grep "^ *tag.line" >actual &&
 562        git diff expect actual &&
 563        git-tag -n2 -l tag-lines >actual &&
 564        git diff expect actual &&
 565
 566        echo "    tag line three" >>expect &&
 567        git-tag -n3 -l | grep "^ *tag.line" >actual &&
 568        git diff expect actual &&
 569        git-tag -n3 -l tag-lines >actual &&
 570        git diff expect actual &&
 571        git-tag -n4 -l | grep "^ *tag.line" >actual &&
 572        git diff expect actual &&
 573        git-tag -n4 -l tag-lines >actual &&
 574        git diff expect actual &&
 575        git-tag -n99 -l | grep "^ *tag.line" >actual &&
 576        git diff expect actual &&
 577        git-tag -n99 -l tag-lines >actual &&
 578        git diff expect actual
 579'
 580
 581# trying to verify annotated non-signed tags:
 582
 583test_expect_success \
 584        'trying to verify an annotated non-signed tag should fail' '
 585        tag_exists annotated-tag &&
 586        ! git-tag -v annotated-tag
 587'
 588
 589test_expect_success \
 590        'trying to verify a file-annotated non-signed tag should fail' '
 591        tag_exists file-annotated-tag &&
 592        ! git-tag -v file-annotated-tag
 593'
 594
 595test_expect_success \
 596        'trying to verify two annotated non-signed tags should fail' '
 597        tag_exists annotated-tag file-annotated-tag &&
 598        ! git-tag -v annotated-tag file-annotated-tag
 599'
 600
 601# creating and verifying signed tags:
 602
 603gpg --version >/dev/null
 604if [ $? -eq 127 ]; then
 605        echo "Skipping signed tags tests, because gpg was not found"
 606        test_done
 607        exit
 608fi
 609
 610# As said here: http://www.gnupg.org/documentation/faqs.html#q6.19
 611# the gpg version 1.0.6 didn't parse trust packets correctly, so for
 612# that version, creation of signed tags using the generated key fails.
 613case "$(gpg --version)" in
 614'gpg (GnuPG) 1.0.6'*)
 615        echo "Skipping signed tag tests, because a bug in 1.0.6 version"
 616        test_done
 617        exit
 618        ;;
 619esac
 620
 621# key generation info: gpg --homedir t/t7004 --gen-key
 622# Type DSA and Elgamal, size 2048 bits, no expiration date.
 623# Name and email: C O Mitter <committer@example.com>
 624# No password given, to enable non-interactive operation.
 625
 626cp -R ../t7004 ./gpghome
 627chmod 0700 gpghome
 628export GNUPGHOME="$(pwd)/gpghome"
 629
 630get_tag_header signed-tag $commit commit $time >expect
 631echo 'A signed tag message' >>expect
 632echo '-----BEGIN PGP SIGNATURE-----' >>expect
 633test_expect_success 'creating a signed tag with -m message should succeed' '
 634        git-tag -s -m "A signed tag message" signed-tag &&
 635        get_tag_msg signed-tag >actual &&
 636        git diff expect actual
 637'
 638
 639get_tag_header u-signed-tag $commit commit $time >expect
 640echo 'Another message' >>expect
 641echo '-----BEGIN PGP SIGNATURE-----' >>expect
 642test_expect_success 'sign with a given key id' '
 643
 644        git tag -u committer@example.com -m "Another message" u-signed-tag &&
 645        get_tag_msg u-signed-tag >actual &&
 646        git diff expect actual
 647
 648'
 649
 650test_expect_success 'sign with an unknown id (1)' '
 651
 652        ! git tag -u author@example.com -m "Another message" o-signed-tag
 653
 654'
 655
 656test_expect_success 'sign with an unknown id (2)' '
 657
 658        ! git tag -u DEADBEEF -m "Another message" o-signed-tag
 659
 660'
 661
 662cat >fakeeditor <<'EOF'
 663#!/bin/sh
 664test -n "$1" && exec >"$1"
 665echo A signed tag message
 666echo from a fake editor.
 667EOF
 668chmod +x fakeeditor
 669
 670get_tag_header implied-sign $commit commit $time >expect
 671./fakeeditor >>expect
 672echo '-----BEGIN PGP SIGNATURE-----' >>expect
 673test_expect_success '-u implies signed tag' '
 674        GIT_EDITOR=./fakeeditor git-tag -u CDDE430D implied-sign &&
 675        get_tag_msg implied-sign >actual &&
 676        git diff expect actual
 677'
 678
 679cat >sigmsgfile <<EOF
 680Another signed tag
 681message in a file.
 682EOF
 683get_tag_header file-signed-tag $commit commit $time >expect
 684cat sigmsgfile >>expect
 685echo '-----BEGIN PGP SIGNATURE-----' >>expect
 686test_expect_success \
 687        'creating a signed tag with -F messagefile should succeed' '
 688        git-tag -s -F sigmsgfile file-signed-tag &&
 689        get_tag_msg file-signed-tag >actual &&
 690        git diff expect actual
 691'
 692
 693cat >siginputmsg <<EOF
 694A signed tag message from
 695the standard input
 696EOF
 697get_tag_header stdin-signed-tag $commit commit $time >expect
 698cat siginputmsg >>expect
 699echo '-----BEGIN PGP SIGNATURE-----' >>expect
 700test_expect_success 'creating a signed tag with -F - should succeed' '
 701        git-tag -s -F - stdin-signed-tag <siginputmsg &&
 702        get_tag_msg stdin-signed-tag >actual &&
 703        git diff expect actual
 704'
 705
 706get_tag_header implied-annotate $commit commit $time >expect
 707./fakeeditor >>expect
 708echo '-----BEGIN PGP SIGNATURE-----' >>expect
 709test_expect_success '-s implies annotated tag' '
 710        GIT_EDITOR=./fakeeditor git-tag -s implied-annotate &&
 711        get_tag_msg implied-annotate >actual &&
 712        git diff expect actual
 713'
 714
 715test_expect_success \
 716        'trying to create a signed tag with non-existing -F file should fail' '
 717        ! test -f nonexistingfile &&
 718        ! tag_exists nosigtag &&
 719        ! git-tag -s -F nonexistingfile nosigtag &&
 720        ! tag_exists nosigtag
 721'
 722
 723test_expect_success 'verifying a signed tag should succeed' \
 724        'git-tag -v signed-tag'
 725
 726test_expect_success 'verifying two signed tags in one command should succeed' \
 727        'git-tag -v signed-tag file-signed-tag'
 728
 729test_expect_success \
 730        'verifying many signed and non-signed tags should fail' '
 731        ! git-tag -v signed-tag annotated-tag &&
 732        ! git-tag -v file-annotated-tag file-signed-tag &&
 733        ! git-tag -v annotated-tag file-signed-tag file-annotated-tag &&
 734        ! git-tag -v signed-tag annotated-tag file-signed-tag
 735'
 736
 737test_expect_success 'verifying a forged tag should fail' '
 738        forged=$(git cat-file tag signed-tag |
 739                sed -e "s/signed-tag/forged-tag/" |
 740                git mktag) &&
 741        git tag forged-tag $forged &&
 742        ! git-tag -v forged-tag
 743'
 744
 745# blank and empty messages for signed tags:
 746
 747get_tag_header empty-signed-tag $commit commit $time >expect
 748echo '-----BEGIN PGP SIGNATURE-----' >>expect
 749test_expect_success \
 750        'creating a signed tag with an empty -m message should succeed' '
 751        git-tag -s -m "" empty-signed-tag &&
 752        get_tag_msg empty-signed-tag >actual &&
 753        git diff expect actual &&
 754        git-tag -v empty-signed-tag
 755'
 756
 757>sigemptyfile
 758get_tag_header emptyfile-signed-tag $commit commit $time >expect
 759echo '-----BEGIN PGP SIGNATURE-----' >>expect
 760test_expect_success \
 761        'creating a signed tag with an empty -F messagefile should succeed' '
 762        git-tag -s -F sigemptyfile emptyfile-signed-tag &&
 763        get_tag_msg emptyfile-signed-tag >actual &&
 764        git diff expect actual &&
 765        git-tag -v emptyfile-signed-tag
 766'
 767
 768printf '\n\n  \n\t\nLeading blank lines\n' > sigblanksfile
 769printf '\n\t \t  \nRepeated blank lines\n' >>sigblanksfile
 770printf '\n\n\nTrailing spaces      \t  \n' >>sigblanksfile
 771printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
 772get_tag_header blanks-signed-tag $commit commit $time >expect
 773cat >>expect <<EOF
 774Leading blank lines
 775
 776Repeated blank lines
 777
 778Trailing spaces
 779
 780Trailing blank lines
 781EOF
 782echo '-----BEGIN PGP SIGNATURE-----' >>expect
 783test_expect_success \
 784        'extra blanks in the message for a signed tag should be removed' '
 785        git-tag -s -F sigblanksfile blanks-signed-tag &&
 786        get_tag_msg blanks-signed-tag >actual &&
 787        git diff expect actual &&
 788        git-tag -v blanks-signed-tag
 789'
 790
 791get_tag_header blank-signed-tag $commit commit $time >expect
 792echo '-----BEGIN PGP SIGNATURE-----' >>expect
 793test_expect_success \
 794        'creating a signed tag with a blank -m message should succeed' '
 795        git-tag -s -m "     " blank-signed-tag &&
 796        get_tag_msg blank-signed-tag >actual &&
 797        git diff expect actual &&
 798        git-tag -v blank-signed-tag
 799'
 800
 801echo '     ' >sigblankfile
 802echo ''      >>sigblankfile
 803echo '  '    >>sigblankfile
 804get_tag_header blankfile-signed-tag $commit commit $time >expect
 805echo '-----BEGIN PGP SIGNATURE-----' >>expect
 806test_expect_success \
 807        'creating a signed tag with blank -F file with spaces should succeed' '
 808        git-tag -s -F sigblankfile blankfile-signed-tag &&
 809        get_tag_msg blankfile-signed-tag >actual &&
 810        git diff expect actual &&
 811        git-tag -v blankfile-signed-tag
 812'
 813
 814printf '      ' >sigblanknonlfile
 815get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
 816echo '-----BEGIN PGP SIGNATURE-----' >>expect
 817test_expect_success \
 818        'creating a signed tag with spaces and no newline should succeed' '
 819        git-tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
 820        get_tag_msg blanknonlfile-signed-tag >actual &&
 821        git diff expect actual &&
 822        git-tag -v signed-tag
 823'
 824
 825# messages with commented lines for signed tags:
 826
 827cat >sigcommentsfile <<EOF
 828# A comment
 829
 830############
 831The message.
 832############
 833One line.
 834
 835
 836# commented lines
 837# commented lines
 838
 839Another line.
 840# comments
 841
 842Last line.
 843EOF
 844get_tag_header comments-signed-tag $commit commit $time >expect
 845cat >>expect <<EOF
 846The message.
 847One line.
 848
 849Another line.
 850
 851Last line.
 852EOF
 853echo '-----BEGIN PGP SIGNATURE-----' >>expect
 854test_expect_success \
 855        'creating a signed tag with a -F file with #comments should succeed' '
 856        git-tag -s -F sigcommentsfile comments-signed-tag &&
 857        get_tag_msg comments-signed-tag >actual &&
 858        git diff expect actual &&
 859        git-tag -v comments-signed-tag
 860'
 861
 862get_tag_header comment-signed-tag $commit commit $time >expect
 863echo '-----BEGIN PGP SIGNATURE-----' >>expect
 864test_expect_success \
 865        'creating a signed tag with #commented -m message should succeed' '
 866        git-tag -s -m "#comment" comment-signed-tag &&
 867        get_tag_msg comment-signed-tag >actual &&
 868        git diff expect actual &&
 869        git-tag -v comment-signed-tag
 870'
 871
 872echo '#comment' >sigcommentfile
 873echo ''         >>sigcommentfile
 874echo '####'     >>sigcommentfile
 875get_tag_header commentfile-signed-tag $commit commit $time >expect
 876echo '-----BEGIN PGP SIGNATURE-----' >>expect
 877test_expect_success \
 878        'creating a signed tag with #commented -F messagefile should succeed' '
 879        git-tag -s -F sigcommentfile commentfile-signed-tag &&
 880        get_tag_msg commentfile-signed-tag >actual &&
 881        git diff expect actual &&
 882        git-tag -v commentfile-signed-tag
 883'
 884
 885printf '#comment' >sigcommentnonlfile
 886get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
 887echo '-----BEGIN PGP SIGNATURE-----' >>expect
 888test_expect_success \
 889        'creating a signed tag with a #comment and no newline should succeed' '
 890        git-tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
 891        get_tag_msg commentnonlfile-signed-tag >actual &&
 892        git diff expect actual &&
 893        git-tag -v commentnonlfile-signed-tag
 894'
 895
 896# listing messages for signed tags:
 897
 898test_expect_success \
 899        'listing the one-line message of a signed tag should succeed' '
 900        git-tag -s -m "A message line signed" stag-one-line &&
 901
 902        echo "stag-one-line" >expect &&
 903        git-tag -l | grep "^stag-one-line" >actual &&
 904        git diff expect actual &&
 905        git-tag -n0 -l | grep "^stag-one-line" >actual &&
 906        git diff expect actual &&
 907        git-tag -n0 -l stag-one-line >actual &&
 908        git diff expect actual &&
 909
 910        echo "stag-one-line   A message line signed" >expect &&
 911        git-tag -n1 -l | grep "^stag-one-line" >actual &&
 912        git diff expect actual &&
 913        git-tag -n -l | grep "^stag-one-line" >actual &&
 914        git diff expect actual &&
 915        git-tag -n1 -l stag-one-line >actual &&
 916        git diff expect actual &&
 917        git-tag -n2 -l stag-one-line >actual &&
 918        git diff expect actual &&
 919        git-tag -n999 -l stag-one-line >actual &&
 920        git diff expect actual
 921'
 922
 923test_expect_success \
 924        'listing the zero-lines message of a signed tag should succeed' '
 925        git-tag -s -m "" stag-zero-lines &&
 926
 927        echo "stag-zero-lines" >expect &&
 928        git-tag -l | grep "^stag-zero-lines" >actual &&
 929        git diff expect actual &&
 930        git-tag -n0 -l | grep "^stag-zero-lines" >actual &&
 931        git diff expect actual &&
 932        git-tag -n0 -l stag-zero-lines >actual &&
 933        git diff expect actual &&
 934
 935        echo "stag-zero-lines " >expect &&
 936        git-tag -n1 -l | grep "^stag-zero-lines" >actual &&
 937        git diff expect actual &&
 938        git-tag -n -l | grep "^stag-zero-lines" >actual &&
 939        git diff expect actual &&
 940        git-tag -n1 -l stag-zero-lines >actual &&
 941        git diff expect actual &&
 942        git-tag -n2 -l stag-zero-lines >actual &&
 943        git diff expect actual &&
 944        git-tag -n999 -l stag-zero-lines >actual &&
 945        git diff expect actual
 946'
 947
 948echo 'stag line one' >sigtagmsg
 949echo 'stag line two' >>sigtagmsg
 950echo 'stag line three' >>sigtagmsg
 951test_expect_success \
 952        'listing many message lines of a signed tag should succeed' '
 953        git-tag -s -F sigtagmsg stag-lines &&
 954
 955        echo "stag-lines" >expect &&
 956        git-tag -l | grep "^stag-lines" >actual &&
 957        git diff expect actual &&
 958        git-tag -n0 -l | grep "^stag-lines" >actual &&
 959        git diff expect actual &&
 960        git-tag -n0 -l stag-lines >actual &&
 961        git diff expect actual &&
 962
 963        echo "stag-lines      stag line one" >expect &&
 964        git-tag -n1 -l | grep "^stag-lines" >actual &&
 965        git diff expect actual &&
 966        git-tag -n -l | grep "^stag-lines" >actual &&
 967        git diff expect actual &&
 968        git-tag -n1 -l stag-lines >actual &&
 969        git diff expect actual &&
 970
 971        echo "    stag line two" >>expect &&
 972        git-tag -n2 -l | grep "^ *stag.line" >actual &&
 973        git diff expect actual &&
 974        git-tag -n2 -l stag-lines >actual &&
 975        git diff expect actual &&
 976
 977        echo "    stag line three" >>expect &&
 978        git-tag -n3 -l | grep "^ *stag.line" >actual &&
 979        git diff expect actual &&
 980        git-tag -n3 -l stag-lines >actual &&
 981        git diff expect actual &&
 982        git-tag -n4 -l | grep "^ *stag.line" >actual &&
 983        git diff expect actual &&
 984        git-tag -n4 -l stag-lines >actual &&
 985        git diff expect actual &&
 986        git-tag -n99 -l | grep "^ *stag.line" >actual &&
 987        git diff expect actual &&
 988        git-tag -n99 -l stag-lines >actual &&
 989        git diff expect actual
 990'
 991
 992# tags pointing to objects different from commits:
 993
 994tree=$(git rev-parse HEAD^{tree})
 995blob=$(git rev-parse HEAD:foo)
 996tag=$(git rev-parse signed-tag)
 997
 998get_tag_header tree-signed-tag $tree tree $time >expect
 999echo "A message for a tree" >>expect
1000echo '-----BEGIN PGP SIGNATURE-----' >>expect
1001test_expect_success \
1002        'creating a signed tag pointing to a tree should succeed' '
1003        git-tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1004        get_tag_msg tree-signed-tag >actual &&
1005        git diff expect actual
1006'
1007
1008get_tag_header blob-signed-tag $blob blob $time >expect
1009echo "A message for a blob" >>expect
1010echo '-----BEGIN PGP SIGNATURE-----' >>expect
1011test_expect_success \
1012        'creating a signed tag pointing to a blob should succeed' '
1013        git-tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1014        get_tag_msg blob-signed-tag >actual &&
1015        git diff expect actual
1016'
1017
1018get_tag_header tag-signed-tag $tag tag $time >expect
1019echo "A message for another tag" >>expect
1020echo '-----BEGIN PGP SIGNATURE-----' >>expect
1021test_expect_success \
1022        'creating a signed tag pointing to another tag should succeed' '
1023        git-tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1024        get_tag_msg tag-signed-tag >actual &&
1025        git diff expect actual
1026'
1027
1028# try to sign with bad user.signingkey
1029git config user.signingkey BobTheMouse
1030test_expect_success \
1031        'git-tag -s fails if gpg is misconfigured' \
1032        '! git tag -s -m tail tag-gpg-failure'
1033git config --unset user.signingkey
1034
1035# try to verify without gpg:
1036
1037rm -rf gpghome
1038test_expect_success \
1039        'verify signed tag fails when public key is not present' \
1040        '! git-tag -v signed-tag'
1041
1042test_expect_success \
1043        'git-tag -a fails if tag annotation is empty' '
1044        ! (GIT_EDITOR=cat git tag -a initial-comment)
1045'
1046
1047test_expect_success \
1048        'message in editor has initial comment' '
1049        GIT_EDITOR=cat git tag -a initial-comment > actual
1050        # check the first line --- should be empty
1051        first=$(sed -e 1q <actual) &&
1052        test -z "$first" &&
1053        # remove commented lines from the remainder -- should be empty
1054        rest=$(sed -e 1d -e '/^#/d' <actual) &&
1055        test -z "$rest"
1056'
1057
1058get_tag_header reuse $commit commit $time >expect
1059echo "An annotation to be reused" >> expect
1060test_expect_success \
1061        'overwriting an annoted tag should use its previous body' '
1062        git tag -a -m "An annotation to be reused" reuse &&
1063        GIT_EDITOR=true git tag -f -a reuse &&
1064        get_tag_msg reuse >actual &&
1065        git diff expect actual
1066'
1067
1068test_done