t / t7004-tag.shon commit Merge branch 'jt/commit-graph-per-object-store' (3bc484a)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Carlos Rica
   4#
   5
   6test_description='git tag
   7
   8Tests for operations with tags.'
   9
  10. ./test-lib.sh
  11. "$TEST_DIRECTORY"/lib-gpg.sh
  12. "$TEST_DIRECTORY"/lib-terminal.sh
  13
  14# creating and listing lightweight tags:
  15
  16tag_exists () {
  17        git show-ref --quiet --verify refs/tags/"$1"
  18}
  19
  20test_expect_success 'listing all tags in an empty tree should succeed' '
  21        git tag -l &&
  22        git tag
  23'
  24
  25test_expect_success 'listing all tags in an empty tree should output nothing' '
  26        test $(git tag -l | wc -l) -eq 0 &&
  27        test $(git tag | wc -l) -eq 0
  28'
  29
  30test_expect_success 'sort tags, ignore case' '
  31        (
  32                git init sort &&
  33                cd sort &&
  34                test_commit initial &&
  35                git tag tag-one &&
  36                git tag TAG-two &&
  37                git tag -l >actual &&
  38                cat >expected <<-\EOF &&
  39                TAG-two
  40                initial
  41                tag-one
  42                EOF
  43                test_cmp expected actual &&
  44                git tag -l -i >actual &&
  45                cat >expected <<-\EOF &&
  46                initial
  47                tag-one
  48                TAG-two
  49                EOF
  50                test_cmp expected actual
  51        )
  52'
  53
  54test_expect_success 'looking for a tag in an empty tree should fail' \
  55        '! (tag_exists mytag)'
  56
  57test_expect_success 'creating a tag in an empty tree should fail' '
  58        test_must_fail git tag mynotag &&
  59        ! tag_exists mynotag
  60'
  61
  62test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
  63        test_must_fail git tag mytaghead HEAD &&
  64        ! tag_exists mytaghead
  65'
  66
  67test_expect_success 'creating a tag for an unknown revision should fail' '
  68        test_must_fail git tag mytagnorev aaaaaaaaaaa &&
  69        ! tag_exists mytagnorev
  70'
  71
  72# commit used in the tests, test_tick is also called here to freeze the date:
  73test_expect_success 'creating a tag using default HEAD should succeed' '
  74        test_config core.logAllRefUpdates true &&
  75        test_tick &&
  76        echo foo >foo &&
  77        git add foo &&
  78        git commit -m Foo &&
  79        git tag mytag &&
  80        test_must_fail git reflog exists refs/tags/mytag
  81'
  82
  83test_expect_success 'creating a tag with --create-reflog should create reflog' '
  84        git log -1 \
  85                --format="format:tag: tagging %h (%s, %cd)%n" \
  86                --date=format:%Y-%m-%d >expected &&
  87        test_when_finished "git tag -d tag_with_reflog" &&
  88        git tag --create-reflog tag_with_reflog &&
  89        git reflog exists refs/tags/tag_with_reflog &&
  90        sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
  91        test_i18ncmp expected actual
  92'
  93
  94test_expect_success 'annotated tag with --create-reflog has correct message' '
  95        git log -1 \
  96                --format="format:tag: tagging %h (%s, %cd)%n" \
  97                --date=format:%Y-%m-%d >expected &&
  98        test_when_finished "git tag -d tag_with_reflog" &&
  99        git tag -m "annotated tag" --create-reflog tag_with_reflog &&
 100        git reflog exists refs/tags/tag_with_reflog &&
 101        sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
 102        test_i18ncmp expected actual
 103'
 104
 105test_expect_success '--create-reflog does not create reflog on failure' '
 106        test_must_fail git tag --create-reflog mytag &&
 107        test_must_fail git reflog exists refs/tags/mytag
 108'
 109
 110test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
 111        test_when_finished "git tag -d tag_with_reflog" &&
 112        test_config core.logAllRefUpdates always &&
 113        git tag tag_with_reflog &&
 114        git reflog exists refs/tags/tag_with_reflog
 115'
 116
 117test_expect_success 'listing all tags if one exists should succeed' '
 118        git tag -l &&
 119        git tag
 120'
 121
 122cat >expect <<EOF
 123mytag
 124EOF
 125test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
 126        git tag -l -l >actual &&
 127        test_cmp expect actual &&
 128        git tag --list --list >actual &&
 129        test_cmp expect actual &&
 130        git tag --list -l --list >actual &&
 131        test_cmp expect actual
 132'
 133
 134test_expect_success 'listing all tags if one exists should output that tag' '
 135        test $(git tag -l) = mytag &&
 136        test $(git tag) = mytag
 137'
 138
 139# pattern matching:
 140
 141test_expect_success 'listing a tag using a matching pattern should succeed' \
 142        'git tag -l mytag'
 143
 144test_expect_success 'listing a tag with --ignore-case' \
 145        'test $(git tag -l --ignore-case MYTAG) = mytag'
 146
 147test_expect_success \
 148        'listing a tag using a matching pattern should output that tag' \
 149        'test $(git tag -l mytag) = mytag'
 150
 151test_expect_success \
 152        'listing tags using a non-matching pattern should succeed' \
 153        'git tag -l xxx'
 154
 155test_expect_success \
 156        'listing tags using a non-matching pattern should output nothing' \
 157        'test $(git tag -l xxx | wc -l) -eq 0'
 158
 159# special cases for creating tags:
 160
 161test_expect_success \
 162        'trying to create a tag with the name of one existing should fail' \
 163        'test_must_fail git tag mytag'
 164
 165test_expect_success \
 166        'trying to create a tag with a non-valid name should fail' '
 167        test $(git tag -l | wc -l) -eq 1 &&
 168        test_must_fail git tag "" &&
 169        test_must_fail git tag .othertag &&
 170        test_must_fail git tag "other tag" &&
 171        test_must_fail git tag "othertag^" &&
 172        test_must_fail git tag "other~tag" &&
 173        test $(git tag -l | wc -l) -eq 1
 174'
 175
 176test_expect_success 'creating a tag using HEAD directly should succeed' '
 177        git tag myhead HEAD &&
 178        tag_exists myhead
 179'
 180
 181test_expect_success '--force can create a tag with the name of one existing' '
 182        tag_exists mytag &&
 183        git tag --force mytag &&
 184        tag_exists mytag'
 185
 186test_expect_success '--force is moot with a non-existing tag name' '
 187        test_when_finished git tag -d newtag forcetag &&
 188        git tag newtag >expect &&
 189        git tag --force forcetag >actual &&
 190        test_cmp expect actual
 191'
 192
 193# deleting tags:
 194
 195test_expect_success 'trying to delete an unknown tag should fail' '
 196        ! tag_exists unknown-tag &&
 197        test_must_fail git tag -d unknown-tag
 198'
 199
 200cat >expect <<EOF
 201myhead
 202mytag
 203EOF
 204test_expect_success \
 205        'trying to delete tags without params should succeed and do nothing' '
 206        git tag -l > actual && test_cmp expect actual &&
 207        git tag -d &&
 208        git tag -l > actual && test_cmp expect actual
 209'
 210
 211test_expect_success \
 212        'deleting two existing tags in one command should succeed' '
 213        tag_exists mytag &&
 214        tag_exists myhead &&
 215        git tag -d mytag myhead &&
 216        ! tag_exists mytag &&
 217        ! tag_exists myhead
 218'
 219
 220test_expect_success \
 221        'creating a tag with the name of another deleted one should succeed' '
 222        ! tag_exists mytag &&
 223        git tag mytag &&
 224        tag_exists mytag
 225'
 226
 227test_expect_success \
 228        'trying to delete two tags, existing and not, should fail in the 2nd' '
 229        tag_exists mytag &&
 230        ! tag_exists myhead &&
 231        test_must_fail git tag -d mytag anothertag &&
 232        ! tag_exists mytag &&
 233        ! tag_exists myhead
 234'
 235
 236test_expect_success 'trying to delete an already deleted tag should fail' \
 237        'test_must_fail git tag -d mytag'
 238
 239# listing various tags with pattern matching:
 240
 241cat >expect <<EOF
 242a1
 243aa1
 244cba
 245t210
 246t211
 247v0.2.1
 248v1.0
 249v1.0.1
 250v1.1.3
 251EOF
 252test_expect_success 'listing all tags should print them ordered' '
 253        git tag v1.0.1 &&
 254        git tag t211 &&
 255        git tag aa1 &&
 256        git tag v0.2.1 &&
 257        git tag v1.1.3 &&
 258        git tag cba &&
 259        git tag a1 &&
 260        git tag v1.0 &&
 261        git tag t210 &&
 262        git tag -l > actual &&
 263        test_cmp expect actual &&
 264        git tag > actual &&
 265        test_cmp expect actual
 266'
 267
 268cat >expect <<EOF
 269a1
 270aa1
 271cba
 272EOF
 273test_expect_success \
 274        'listing tags with substring as pattern must print those matching' '
 275        rm *a* &&
 276        git tag -l "*a*" > current &&
 277        test_cmp expect current
 278'
 279
 280cat >expect <<EOF
 281v0.2.1
 282v1.0.1
 283EOF
 284test_expect_success \
 285        'listing tags with a suffix as pattern must print those matching' '
 286        git tag -l "*.1" > actual &&
 287        test_cmp expect actual
 288'
 289
 290cat >expect <<EOF
 291t210
 292t211
 293EOF
 294test_expect_success \
 295        'listing tags with a prefix as pattern must print those matching' '
 296        git tag -l "t21*" > actual &&
 297        test_cmp expect actual
 298'
 299
 300cat >expect <<EOF
 301a1
 302EOF
 303test_expect_success \
 304        'listing tags using a name as pattern must print that one matching' '
 305        git tag -l a1 > actual &&
 306        test_cmp expect actual
 307'
 308
 309cat >expect <<EOF
 310v1.0
 311EOF
 312test_expect_success \
 313        'listing tags using a name as pattern must print that one matching' '
 314        git tag -l v1.0 > actual &&
 315        test_cmp expect actual
 316'
 317
 318cat >expect <<EOF
 319v1.0.1
 320v1.1.3
 321EOF
 322test_expect_success \
 323        'listing tags with ? in the pattern should print those matching' '
 324        git tag -l "v1.?.?" > actual &&
 325        test_cmp expect actual
 326'
 327
 328>expect
 329test_expect_success \
 330        'listing tags using v.* should print nothing because none have v.' '
 331        git tag -l "v.*" > actual &&
 332        test_cmp expect actual
 333'
 334
 335cat >expect <<EOF
 336v0.2.1
 337v1.0
 338v1.0.1
 339v1.1.3
 340EOF
 341test_expect_success \
 342        'listing tags using v* should print only those having v' '
 343        git tag -l "v*" > actual &&
 344        test_cmp expect actual
 345'
 346
 347test_expect_success 'tag -l can accept multiple patterns' '
 348        git tag -l "v1*" "v0*" >actual &&
 349        test_cmp expect actual
 350'
 351
 352# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
 353# could leave you with the impression that "-l <pattern> -l <pattern>"
 354# was how we wanted to accept multiple patterns.
 355#
 356# This test should not imply that this is a sane thing to support. but
 357# since the documentation was worded like it was let's at least find
 358# out if we're going to break this long-documented form of taking
 359# multiple patterns.
 360test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
 361        git tag -l "v1*" -l "v0*" >actual &&
 362        test_cmp expect actual
 363'
 364
 365test_expect_success 'listing tags in column' '
 366        COLUMNS=41 git tag -l --column=row >actual &&
 367        cat >expected <<\EOF &&
 368a1      aa1     cba     t210    t211
 369v0.2.1  v1.0    v1.0.1  v1.1.3
 370EOF
 371        test_cmp expected actual
 372'
 373
 374test_expect_success 'listing tags in column with column.*' '
 375        test_config column.tag row &&
 376        test_config column.ui dense &&
 377        COLUMNS=40 git tag -l >actual &&
 378        cat >expected <<\EOF &&
 379a1      aa1   cba     t210    t211
 380v0.2.1  v1.0  v1.0.1  v1.1.3
 381EOF
 382        test_cmp expected actual
 383'
 384
 385test_expect_success 'listing tag with -n --column should fail' '
 386        test_must_fail git tag --column -n
 387'
 388
 389test_expect_success 'listing tags -n in column with column.ui ignored' '
 390        test_config column.ui "row dense" &&
 391        COLUMNS=40 git tag -l -n >actual &&
 392        cat >expected <<\EOF &&
 393a1              Foo
 394aa1             Foo
 395cba             Foo
 396t210            Foo
 397t211            Foo
 398v0.2.1          Foo
 399v1.0            Foo
 400v1.0.1          Foo
 401v1.1.3          Foo
 402EOF
 403        test_cmp expected actual
 404'
 405
 406# creating and verifying lightweight tags:
 407
 408test_expect_success \
 409        'a non-annotated tag created without parameters should point to HEAD' '
 410        git tag non-annotated-tag &&
 411        test $(git cat-file -t non-annotated-tag) = commit &&
 412        test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
 413'
 414
 415test_expect_success 'trying to verify an unknown tag should fail' \
 416        'test_must_fail git tag -v unknown-tag'
 417
 418test_expect_success \
 419        'trying to verify a non-annotated and non-signed tag should fail' \
 420        'test_must_fail git tag -v non-annotated-tag'
 421
 422test_expect_success \
 423        'trying to verify many non-annotated or unknown tags, should fail' \
 424        'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
 425
 426# creating annotated tags:
 427
 428get_tag_msg () {
 429        git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
 430}
 431
 432# run test_tick before committing always gives the time in that timezone
 433get_tag_header () {
 434cat <<EOF
 435object $2
 436type $3
 437tag $1
 438tagger C O Mitter <committer@example.com> $4 -0700
 439
 440EOF
 441}
 442
 443commit=$(git rev-parse HEAD)
 444time=$test_tick
 445
 446get_tag_header annotated-tag $commit commit $time >expect
 447echo "A message" >>expect
 448test_expect_success \
 449        'creating an annotated tag with -m message should succeed' '
 450        git tag -m "A message" annotated-tag &&
 451        get_tag_msg annotated-tag >actual &&
 452        test_cmp expect actual
 453'
 454
 455get_tag_header annotated-tag-edit $commit commit $time >expect
 456echo "An edited message" >>expect
 457test_expect_success 'set up editor' '
 458        write_script fakeeditor <<-\EOF
 459        sed -e "s/A message/An edited message/g" <"$1" >"$1-"
 460        mv "$1-" "$1"
 461        EOF
 462'
 463test_expect_success \
 464        'creating an annotated tag with -m message --edit should succeed' '
 465        GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
 466        get_tag_msg annotated-tag-edit >actual &&
 467        test_cmp expect actual
 468'
 469
 470cat >msgfile <<EOF
 471Another message
 472in a file.
 473EOF
 474get_tag_header file-annotated-tag $commit commit $time >expect
 475cat msgfile >>expect
 476test_expect_success \
 477        'creating an annotated tag with -F messagefile should succeed' '
 478        git tag -F msgfile file-annotated-tag &&
 479        get_tag_msg file-annotated-tag >actual &&
 480        test_cmp expect actual
 481'
 482
 483get_tag_header file-annotated-tag-edit $commit commit $time >expect
 484sed -e "s/Another message/Another edited message/g" msgfile >>expect
 485test_expect_success 'set up editor' '
 486        write_script fakeeditor <<-\EOF
 487        sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
 488        mv "$1-" "$1"
 489        EOF
 490'
 491test_expect_success \
 492        'creating an annotated tag with -F messagefile --edit should succeed' '
 493        GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
 494        get_tag_msg file-annotated-tag-edit >actual &&
 495        test_cmp expect actual
 496'
 497
 498cat >inputmsg <<EOF
 499A message from the
 500standard input
 501EOF
 502get_tag_header stdin-annotated-tag $commit commit $time >expect
 503cat inputmsg >>expect
 504test_expect_success 'creating an annotated tag with -F - should succeed' '
 505        git tag -F - stdin-annotated-tag <inputmsg &&
 506        get_tag_msg stdin-annotated-tag >actual &&
 507        test_cmp expect actual
 508'
 509
 510test_expect_success \
 511        'trying to create a tag with a non-existing -F file should fail' '
 512        ! test -f nonexistingfile &&
 513        ! tag_exists notag &&
 514        test_must_fail git tag -F nonexistingfile notag &&
 515        ! tag_exists notag
 516'
 517
 518test_expect_success \
 519        'trying to create tags giving both -m or -F options should fail' '
 520        echo "message file 1" >msgfile1 &&
 521        echo "message file 2" >msgfile2 &&
 522        ! tag_exists msgtag &&
 523        test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
 524        ! tag_exists msgtag &&
 525        test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
 526        ! tag_exists msgtag &&
 527        test_must_fail git tag -m "message 1" -F msgfile1 \
 528                -m "message 2" msgtag &&
 529        ! tag_exists msgtag
 530'
 531
 532# blank and empty messages:
 533
 534get_tag_header empty-annotated-tag $commit commit $time >expect
 535test_expect_success \
 536        'creating a tag with an empty -m message should succeed' '
 537        git tag -m "" empty-annotated-tag &&
 538        get_tag_msg empty-annotated-tag >actual &&
 539        test_cmp expect actual
 540'
 541
 542>emptyfile
 543get_tag_header emptyfile-annotated-tag $commit commit $time >expect
 544test_expect_success \
 545        'creating a tag with an empty -F messagefile should succeed' '
 546        git tag -F emptyfile emptyfile-annotated-tag &&
 547        get_tag_msg emptyfile-annotated-tag >actual &&
 548        test_cmp expect actual
 549'
 550
 551printf '\n\n  \n\t\nLeading blank lines\n' >blanksfile
 552printf '\n\t \t  \nRepeated blank lines\n' >>blanksfile
 553printf '\n\n\nTrailing spaces      \t  \n' >>blanksfile
 554printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
 555get_tag_header blanks-annotated-tag $commit commit $time >expect
 556cat >>expect <<EOF
 557Leading blank lines
 558
 559Repeated blank lines
 560
 561Trailing spaces
 562
 563Trailing blank lines
 564EOF
 565test_expect_success \
 566        'extra blanks in the message for an annotated tag should be removed' '
 567        git tag -F blanksfile blanks-annotated-tag &&
 568        get_tag_msg blanks-annotated-tag >actual &&
 569        test_cmp expect actual
 570'
 571
 572get_tag_header blank-annotated-tag $commit commit $time >expect
 573test_expect_success \
 574        'creating a tag with blank -m message with spaces should succeed' '
 575        git tag -m "     " blank-annotated-tag &&
 576        get_tag_msg blank-annotated-tag >actual &&
 577        test_cmp expect actual
 578'
 579
 580echo '     ' >blankfile
 581echo ''      >>blankfile
 582echo '  '    >>blankfile
 583get_tag_header blankfile-annotated-tag $commit commit $time >expect
 584test_expect_success \
 585        'creating a tag with blank -F messagefile with spaces should succeed' '
 586        git tag -F blankfile blankfile-annotated-tag &&
 587        get_tag_msg blankfile-annotated-tag >actual &&
 588        test_cmp expect actual
 589'
 590
 591printf '      ' >blanknonlfile
 592get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
 593test_expect_success \
 594        'creating a tag with -F file of spaces and no newline should succeed' '
 595        git tag -F blanknonlfile blanknonlfile-annotated-tag &&
 596        get_tag_msg blanknonlfile-annotated-tag >actual &&
 597        test_cmp expect actual
 598'
 599
 600# messages with commented lines:
 601
 602cat >commentsfile <<EOF
 603# A comment
 604
 605############
 606The message.
 607############
 608One line.
 609
 610
 611# commented lines
 612# commented lines
 613
 614Another line.
 615# comments
 616
 617Last line.
 618EOF
 619get_tag_header comments-annotated-tag $commit commit $time >expect
 620cat >>expect <<EOF
 621The message.
 622One line.
 623
 624Another line.
 625
 626Last line.
 627EOF
 628test_expect_success \
 629        'creating a tag using a -F messagefile with #comments should succeed' '
 630        git tag -F commentsfile comments-annotated-tag &&
 631        get_tag_msg comments-annotated-tag >actual &&
 632        test_cmp expect actual
 633'
 634
 635get_tag_header comment-annotated-tag $commit commit $time >expect
 636test_expect_success \
 637        'creating a tag with a #comment in the -m message should succeed' '
 638        git tag -m "#comment" comment-annotated-tag &&
 639        get_tag_msg comment-annotated-tag >actual &&
 640        test_cmp expect actual
 641'
 642
 643echo '#comment' >commentfile
 644echo ''         >>commentfile
 645echo '####'     >>commentfile
 646get_tag_header commentfile-annotated-tag $commit commit $time >expect
 647test_expect_success \
 648        'creating a tag with #comments in the -F messagefile should succeed' '
 649        git tag -F commentfile commentfile-annotated-tag &&
 650        get_tag_msg commentfile-annotated-tag >actual &&
 651        test_cmp expect actual
 652'
 653
 654printf '#comment' >commentnonlfile
 655get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
 656test_expect_success \
 657        'creating a tag with a file of #comment and no newline should succeed' '
 658        git tag -F commentnonlfile commentnonlfile-annotated-tag &&
 659        get_tag_msg commentnonlfile-annotated-tag >actual &&
 660        test_cmp expect actual
 661'
 662
 663# listing messages for annotated non-signed tags:
 664
 665test_expect_success \
 666        'listing the one-line message of a non-signed tag should succeed' '
 667        git tag -m "A msg" tag-one-line &&
 668
 669        echo "tag-one-line" >expect &&
 670        git tag -l | grep "^tag-one-line" >actual &&
 671        test_cmp expect actual &&
 672        git tag -n0 -l | grep "^tag-one-line" >actual &&
 673        test_cmp expect actual &&
 674        git tag -n0 -l tag-one-line >actual &&
 675        test_cmp expect actual &&
 676
 677        git tag -n0 | grep "^tag-one-line" >actual &&
 678        test_cmp expect actual &&
 679        git tag -n0 tag-one-line >actual &&
 680        test_cmp expect actual &&
 681
 682        echo "tag-one-line    A msg" >expect &&
 683        git tag -n1 -l | grep "^tag-one-line" >actual &&
 684        test_cmp expect actual &&
 685        git tag -n -l | grep "^tag-one-line" >actual &&
 686        test_cmp expect actual &&
 687        git tag -n1 -l tag-one-line >actual &&
 688        test_cmp expect actual &&
 689        git tag -n2 -l tag-one-line >actual &&
 690        test_cmp expect actual &&
 691        git tag -n999 -l tag-one-line >actual &&
 692        test_cmp expect actual
 693'
 694
 695test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
 696        git tag -n 100 >actual &&
 697        test_must_be_empty actual &&
 698
 699        git tag -m "A msg" 100 &&
 700        echo "100             A msg" >expect &&
 701        git tag -n 100 >actual &&
 702        test_cmp expect actual
 703'
 704
 705test_expect_success \
 706        'listing the zero-lines message of a non-signed tag should succeed' '
 707        git tag -m "" tag-zero-lines &&
 708
 709        echo "tag-zero-lines" >expect &&
 710        git tag -l | grep "^tag-zero-lines" >actual &&
 711        test_cmp expect actual &&
 712        git tag -n0 -l | grep "^tag-zero-lines" >actual &&
 713        test_cmp expect actual &&
 714        git tag -n0 -l tag-zero-lines >actual &&
 715        test_cmp expect actual &&
 716
 717        echo "tag-zero-lines  " >expect &&
 718        git tag -n1 -l | grep "^tag-zero-lines" >actual &&
 719        test_cmp expect actual &&
 720        git tag -n -l | grep "^tag-zero-lines" >actual &&
 721        test_cmp expect actual &&
 722        git tag -n1 -l tag-zero-lines >actual &&
 723        test_cmp expect actual &&
 724        git tag -n2 -l tag-zero-lines >actual &&
 725        test_cmp expect actual &&
 726        git tag -n999 -l tag-zero-lines >actual &&
 727        test_cmp expect actual
 728'
 729
 730echo 'tag line one' >annotagmsg
 731echo 'tag line two' >>annotagmsg
 732echo 'tag line three' >>annotagmsg
 733test_expect_success \
 734        'listing many message lines of a non-signed tag should succeed' '
 735        git tag -F annotagmsg tag-lines &&
 736
 737        echo "tag-lines" >expect &&
 738        git tag -l | grep "^tag-lines" >actual &&
 739        test_cmp expect actual &&
 740        git tag -n0 -l | grep "^tag-lines" >actual &&
 741        test_cmp expect actual &&
 742        git tag -n0 -l tag-lines >actual &&
 743        test_cmp expect actual &&
 744
 745        echo "tag-lines       tag line one" >expect &&
 746        git tag -n1 -l | grep "^tag-lines" >actual &&
 747        test_cmp expect actual &&
 748        git tag -n -l | grep "^tag-lines" >actual &&
 749        test_cmp expect actual &&
 750        git tag -n1 -l tag-lines >actual &&
 751        test_cmp expect actual &&
 752
 753        echo "    tag line two" >>expect &&
 754        git tag -n2 -l | grep "^ *tag.line" >actual &&
 755        test_cmp expect actual &&
 756        git tag -n2 -l tag-lines >actual &&
 757        test_cmp expect actual &&
 758
 759        echo "    tag line three" >>expect &&
 760        git tag -n3 -l | grep "^ *tag.line" >actual &&
 761        test_cmp expect actual &&
 762        git tag -n3 -l tag-lines >actual &&
 763        test_cmp expect actual &&
 764        git tag -n4 -l | grep "^ *tag.line" >actual &&
 765        test_cmp expect actual &&
 766        git tag -n4 -l tag-lines >actual &&
 767        test_cmp expect actual &&
 768        git tag -n99 -l | grep "^ *tag.line" >actual &&
 769        test_cmp expect actual &&
 770        git tag -n99 -l tag-lines >actual &&
 771        test_cmp expect actual
 772'
 773
 774test_expect_success 'annotations for blobs are empty' '
 775        blob=$(git hash-object -w --stdin <<-\EOF
 776        Blob paragraph 1.
 777
 778        Blob paragraph 2.
 779        EOF
 780        ) &&
 781        git tag tag-blob $blob &&
 782        echo "tag-blob        " >expect &&
 783        git tag -n1 -l tag-blob >actual &&
 784        test_cmp expect actual
 785'
 786
 787# trying to verify annotated non-signed tags:
 788
 789test_expect_success GPG \
 790        'trying to verify an annotated non-signed tag should fail' '
 791        tag_exists annotated-tag &&
 792        test_must_fail git tag -v annotated-tag
 793'
 794
 795test_expect_success GPG \
 796        'trying to verify a file-annotated non-signed tag should fail' '
 797        tag_exists file-annotated-tag &&
 798        test_must_fail git tag -v file-annotated-tag
 799'
 800
 801test_expect_success GPG \
 802        'trying to verify two annotated non-signed tags should fail' '
 803        tag_exists annotated-tag file-annotated-tag &&
 804        test_must_fail git tag -v annotated-tag file-annotated-tag
 805'
 806
 807# creating and verifying signed tags:
 808
 809get_tag_header signed-tag $commit commit $time >expect
 810echo 'A signed tag message' >>expect
 811echo '-----BEGIN PGP SIGNATURE-----' >>expect
 812test_expect_success GPG 'creating a signed tag with -m message should succeed' '
 813        git tag -s -m "A signed tag message" signed-tag &&
 814        get_tag_msg signed-tag >actual &&
 815        test_cmp expect actual
 816'
 817
 818get_tag_header u-signed-tag $commit commit $time >expect
 819echo 'Another message' >>expect
 820echo '-----BEGIN PGP SIGNATURE-----' >>expect
 821test_expect_success GPG 'sign with a given key id' '
 822
 823        git tag -u committer@example.com -m "Another message" u-signed-tag &&
 824        get_tag_msg u-signed-tag >actual &&
 825        test_cmp expect actual
 826
 827'
 828
 829test_expect_success GPG 'sign with an unknown id (1)' '
 830
 831        test_must_fail git tag -u author@example.com \
 832                -m "Another message" o-signed-tag
 833
 834'
 835
 836test_expect_success GPG 'sign with an unknown id (2)' '
 837
 838        test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
 839
 840'
 841
 842cat >fakeeditor <<'EOF'
 843#!/bin/sh
 844test -n "$1" && exec >"$1"
 845echo A signed tag message
 846echo from a fake editor.
 847EOF
 848chmod +x fakeeditor
 849
 850get_tag_header implied-sign $commit commit $time >expect
 851./fakeeditor >>expect
 852echo '-----BEGIN PGP SIGNATURE-----' >>expect
 853test_expect_success GPG '-u implies signed tag' '
 854        GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
 855        get_tag_msg implied-sign >actual &&
 856        test_cmp expect actual
 857'
 858
 859cat >sigmsgfile <<EOF
 860Another signed tag
 861message in a file.
 862EOF
 863get_tag_header file-signed-tag $commit commit $time >expect
 864cat sigmsgfile >>expect
 865echo '-----BEGIN PGP SIGNATURE-----' >>expect
 866test_expect_success GPG \
 867        'creating a signed tag with -F messagefile should succeed' '
 868        git tag -s -F sigmsgfile file-signed-tag &&
 869        get_tag_msg file-signed-tag >actual &&
 870        test_cmp expect actual
 871'
 872
 873cat >siginputmsg <<EOF
 874A signed tag message from
 875the standard input
 876EOF
 877get_tag_header stdin-signed-tag $commit commit $time >expect
 878cat siginputmsg >>expect
 879echo '-----BEGIN PGP SIGNATURE-----' >>expect
 880test_expect_success GPG 'creating a signed tag with -F - should succeed' '
 881        git tag -s -F - stdin-signed-tag <siginputmsg &&
 882        get_tag_msg stdin-signed-tag >actual &&
 883        test_cmp expect actual
 884'
 885
 886get_tag_header implied-annotate $commit commit $time >expect
 887./fakeeditor >>expect
 888echo '-----BEGIN PGP SIGNATURE-----' >>expect
 889test_expect_success GPG '-s implies annotated tag' '
 890        GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
 891        get_tag_msg implied-annotate >actual &&
 892        test_cmp expect actual
 893'
 894
 895get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
 896echo "A message" >>expect
 897echo '-----BEGIN PGP SIGNATURE-----' >>expect
 898test_expect_success GPG \
 899        'git tag -s implied if configured with tag.forcesignannotated' \
 900        'test_config tag.forcesignannotated true &&
 901        git tag -m "A message" forcesignannotated-implied-sign &&
 902        get_tag_msg forcesignannotated-implied-sign >actual &&
 903        test_cmp expect actual
 904'
 905
 906test_expect_success GPG \
 907        'lightweight with no message when configured with tag.forcesignannotated' \
 908        'test_config tag.forcesignannotated true &&
 909        git tag forcesignannotated-lightweight &&
 910        tag_exists forcesignannotated-lightweight &&
 911        test_must_fail git tag -v forcesignannotated-no-message
 912'
 913
 914get_tag_header forcesignannotated-annotate $commit commit $time >expect
 915echo "A message" >>expect
 916test_expect_success GPG \
 917        'git tag -a disable configured tag.forcesignannotated' \
 918        'test_config tag.forcesignannotated true &&
 919        git tag -a -m "A message" forcesignannotated-annotate &&
 920        get_tag_msg forcesignannotated-annotate >actual &&
 921        test_cmp expect actual &&
 922        test_must_fail git tag -v forcesignannotated-annotate
 923'
 924
 925get_tag_header forcesignannotated-disabled $commit commit $time >expect
 926echo "A message" >>expect
 927echo '-----BEGIN PGP SIGNATURE-----' >>expect
 928test_expect_success GPG \
 929        'git tag --sign enable GPG sign' \
 930        'test_config tag.forcesignannotated false &&
 931        git tag --sign -m "A message" forcesignannotated-disabled &&
 932        get_tag_msg forcesignannotated-disabled >actual &&
 933        test_cmp expect actual
 934'
 935
 936test_expect_success GPG \
 937        'trying to create a signed tag with non-existing -F file should fail' '
 938        ! test -f nonexistingfile &&
 939        ! tag_exists nosigtag &&
 940        test_must_fail git tag -s -F nonexistingfile nosigtag &&
 941        ! tag_exists nosigtag
 942'
 943
 944test_expect_success GPG 'verifying a signed tag should succeed' \
 945        'git tag -v signed-tag'
 946
 947test_expect_success GPG 'verifying two signed tags in one command should succeed' \
 948        'git tag -v signed-tag file-signed-tag'
 949
 950test_expect_success GPG \
 951        'verifying many signed and non-signed tags should fail' '
 952        test_must_fail git tag -v signed-tag annotated-tag &&
 953        test_must_fail git tag -v file-annotated-tag file-signed-tag &&
 954        test_must_fail git tag -v annotated-tag \
 955                file-signed-tag file-annotated-tag &&
 956        test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
 957'
 958
 959test_expect_success GPG 'verifying a forged tag should fail' '
 960        forged=$(git cat-file tag signed-tag |
 961                sed -e "s/signed-tag/forged-tag/" |
 962                git mktag) &&
 963        git tag forged-tag $forged &&
 964        test_must_fail git tag -v forged-tag
 965'
 966
 967test_expect_success GPG 'verifying a proper tag with --format pass and format accordingly' '
 968        cat >expect <<-\EOF &&
 969        tagname : signed-tag
 970        EOF
 971        git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
 972        test_cmp expect actual
 973'
 974
 975test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
 976        test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
 977        test_must_be_empty actual
 978'
 979
 980# blank and empty messages for signed tags:
 981
 982get_tag_header empty-signed-tag $commit commit $time >expect
 983echo '-----BEGIN PGP SIGNATURE-----' >>expect
 984test_expect_success GPG \
 985        'creating a signed tag with an empty -m message should succeed' '
 986        git tag -s -m "" empty-signed-tag &&
 987        get_tag_msg empty-signed-tag >actual &&
 988        test_cmp expect actual &&
 989        git tag -v empty-signed-tag
 990'
 991
 992>sigemptyfile
 993get_tag_header emptyfile-signed-tag $commit commit $time >expect
 994echo '-----BEGIN PGP SIGNATURE-----' >>expect
 995test_expect_success GPG \
 996        'creating a signed tag with an empty -F messagefile should succeed' '
 997        git tag -s -F sigemptyfile emptyfile-signed-tag &&
 998        get_tag_msg emptyfile-signed-tag >actual &&
 999        test_cmp expect actual &&
1000        git tag -v emptyfile-signed-tag
1001'
1002
1003printf '\n\n  \n\t\nLeading blank lines\n' > sigblanksfile
1004printf '\n\t \t  \nRepeated blank lines\n' >>sigblanksfile
1005printf '\n\n\nTrailing spaces      \t  \n' >>sigblanksfile
1006printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
1007get_tag_header blanks-signed-tag $commit commit $time >expect
1008cat >>expect <<EOF
1009Leading blank lines
1010
1011Repeated blank lines
1012
1013Trailing spaces
1014
1015Trailing blank lines
1016EOF
1017echo '-----BEGIN PGP SIGNATURE-----' >>expect
1018test_expect_success GPG \
1019        'extra blanks in the message for a signed tag should be removed' '
1020        git tag -s -F sigblanksfile blanks-signed-tag &&
1021        get_tag_msg blanks-signed-tag >actual &&
1022        test_cmp expect actual &&
1023        git tag -v blanks-signed-tag
1024'
1025
1026get_tag_header blank-signed-tag $commit commit $time >expect
1027echo '-----BEGIN PGP SIGNATURE-----' >>expect
1028test_expect_success GPG \
1029        'creating a signed tag with a blank -m message should succeed' '
1030        git tag -s -m "     " blank-signed-tag &&
1031        get_tag_msg blank-signed-tag >actual &&
1032        test_cmp expect actual &&
1033        git tag -v blank-signed-tag
1034'
1035
1036echo '     ' >sigblankfile
1037echo ''      >>sigblankfile
1038echo '  '    >>sigblankfile
1039get_tag_header blankfile-signed-tag $commit commit $time >expect
1040echo '-----BEGIN PGP SIGNATURE-----' >>expect
1041test_expect_success GPG \
1042        'creating a signed tag with blank -F file with spaces should succeed' '
1043        git tag -s -F sigblankfile blankfile-signed-tag &&
1044        get_tag_msg blankfile-signed-tag >actual &&
1045        test_cmp expect actual &&
1046        git tag -v blankfile-signed-tag
1047'
1048
1049printf '      ' >sigblanknonlfile
1050get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
1051echo '-----BEGIN PGP SIGNATURE-----' >>expect
1052test_expect_success GPG \
1053        'creating a signed tag with spaces and no newline should succeed' '
1054        git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
1055        get_tag_msg blanknonlfile-signed-tag >actual &&
1056        test_cmp expect actual &&
1057        git tag -v blanknonlfile-signed-tag
1058'
1059
1060test_expect_success GPG 'signed tag with embedded PGP message' '
1061        cat >msg <<-\EOF &&
1062        -----BEGIN PGP MESSAGE-----
1063
1064        this is not a real PGP message
1065        -----END PGP MESSAGE-----
1066        EOF
1067        git tag -s -F msg confusing-pgp-message &&
1068        git tag -v confusing-pgp-message
1069'
1070
1071# messages with commented lines for signed tags:
1072
1073cat >sigcommentsfile <<EOF
1074# A comment
1075
1076############
1077The message.
1078############
1079One line.
1080
1081
1082# commented lines
1083# commented lines
1084
1085Another line.
1086# comments
1087
1088Last line.
1089EOF
1090get_tag_header comments-signed-tag $commit commit $time >expect
1091cat >>expect <<EOF
1092The message.
1093One line.
1094
1095Another line.
1096
1097Last line.
1098EOF
1099echo '-----BEGIN PGP SIGNATURE-----' >>expect
1100test_expect_success GPG \
1101        'creating a signed tag with a -F file with #comments should succeed' '
1102        git tag -s -F sigcommentsfile comments-signed-tag &&
1103        get_tag_msg comments-signed-tag >actual &&
1104        test_cmp expect actual &&
1105        git tag -v comments-signed-tag
1106'
1107
1108get_tag_header comment-signed-tag $commit commit $time >expect
1109echo '-----BEGIN PGP SIGNATURE-----' >>expect
1110test_expect_success GPG \
1111        'creating a signed tag with #commented -m message should succeed' '
1112        git tag -s -m "#comment" comment-signed-tag &&
1113        get_tag_msg comment-signed-tag >actual &&
1114        test_cmp expect actual &&
1115        git tag -v comment-signed-tag
1116'
1117
1118echo '#comment' >sigcommentfile
1119echo ''         >>sigcommentfile
1120echo '####'     >>sigcommentfile
1121get_tag_header commentfile-signed-tag $commit commit $time >expect
1122echo '-----BEGIN PGP SIGNATURE-----' >>expect
1123test_expect_success GPG \
1124        'creating a signed tag with #commented -F messagefile should succeed' '
1125        git tag -s -F sigcommentfile commentfile-signed-tag &&
1126        get_tag_msg commentfile-signed-tag >actual &&
1127        test_cmp expect actual &&
1128        git tag -v commentfile-signed-tag
1129'
1130
1131printf '#comment' >sigcommentnonlfile
1132get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
1133echo '-----BEGIN PGP SIGNATURE-----' >>expect
1134test_expect_success GPG \
1135        'creating a signed tag with a #comment and no newline should succeed' '
1136        git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
1137        get_tag_msg commentnonlfile-signed-tag >actual &&
1138        test_cmp expect actual &&
1139        git tag -v commentnonlfile-signed-tag
1140'
1141
1142# listing messages for signed tags:
1143
1144test_expect_success GPG \
1145        'listing the one-line message of a signed tag should succeed' '
1146        git tag -s -m "A message line signed" stag-one-line &&
1147
1148        echo "stag-one-line" >expect &&
1149        git tag -l | grep "^stag-one-line" >actual &&
1150        test_cmp expect actual &&
1151        git tag -n0 -l | grep "^stag-one-line" >actual &&
1152        test_cmp expect actual &&
1153        git tag -n0 -l stag-one-line >actual &&
1154        test_cmp expect actual &&
1155
1156        echo "stag-one-line   A message line signed" >expect &&
1157        git tag -n1 -l | grep "^stag-one-line" >actual &&
1158        test_cmp expect actual &&
1159        git tag -n -l | grep "^stag-one-line" >actual &&
1160        test_cmp expect actual &&
1161        git tag -n1 -l stag-one-line >actual &&
1162        test_cmp expect actual &&
1163        git tag -n2 -l stag-one-line >actual &&
1164        test_cmp expect actual &&
1165        git tag -n999 -l stag-one-line >actual &&
1166        test_cmp expect actual
1167'
1168
1169test_expect_success GPG \
1170        'listing the zero-lines message of a signed tag should succeed' '
1171        git tag -s -m "" stag-zero-lines &&
1172
1173        echo "stag-zero-lines" >expect &&
1174        git tag -l | grep "^stag-zero-lines" >actual &&
1175        test_cmp expect actual &&
1176        git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1177        test_cmp expect actual &&
1178        git tag -n0 -l stag-zero-lines >actual &&
1179        test_cmp expect actual &&
1180
1181        echo "stag-zero-lines " >expect &&
1182        git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1183        test_cmp expect actual &&
1184        git tag -n -l | grep "^stag-zero-lines" >actual &&
1185        test_cmp expect actual &&
1186        git tag -n1 -l stag-zero-lines >actual &&
1187        test_cmp expect actual &&
1188        git tag -n2 -l stag-zero-lines >actual &&
1189        test_cmp expect actual &&
1190        git tag -n999 -l stag-zero-lines >actual &&
1191        test_cmp expect actual
1192'
1193
1194echo 'stag line one' >sigtagmsg
1195echo 'stag line two' >>sigtagmsg
1196echo 'stag line three' >>sigtagmsg
1197test_expect_success GPG \
1198        'listing many message lines of a signed tag should succeed' '
1199        git tag -s -F sigtagmsg stag-lines &&
1200
1201        echo "stag-lines" >expect &&
1202        git tag -l | grep "^stag-lines" >actual &&
1203        test_cmp expect actual &&
1204        git tag -n0 -l | grep "^stag-lines" >actual &&
1205        test_cmp expect actual &&
1206        git tag -n0 -l stag-lines >actual &&
1207        test_cmp expect actual &&
1208
1209        echo "stag-lines      stag line one" >expect &&
1210        git tag -n1 -l | grep "^stag-lines" >actual &&
1211        test_cmp expect actual &&
1212        git tag -n -l | grep "^stag-lines" >actual &&
1213        test_cmp expect actual &&
1214        git tag -n1 -l stag-lines >actual &&
1215        test_cmp expect actual &&
1216
1217        echo "    stag line two" >>expect &&
1218        git tag -n2 -l | grep "^ *stag.line" >actual &&
1219        test_cmp expect actual &&
1220        git tag -n2 -l stag-lines >actual &&
1221        test_cmp expect actual &&
1222
1223        echo "    stag line three" >>expect &&
1224        git tag -n3 -l | grep "^ *stag.line" >actual &&
1225        test_cmp expect actual &&
1226        git tag -n3 -l stag-lines >actual &&
1227        test_cmp expect actual &&
1228        git tag -n4 -l | grep "^ *stag.line" >actual &&
1229        test_cmp expect actual &&
1230        git tag -n4 -l stag-lines >actual &&
1231        test_cmp expect actual &&
1232        git tag -n99 -l | grep "^ *stag.line" >actual &&
1233        test_cmp expect actual &&
1234        git tag -n99 -l stag-lines >actual &&
1235        test_cmp expect actual
1236'
1237
1238# tags pointing to objects different from commits:
1239
1240tree=$(git rev-parse HEAD^{tree})
1241blob=$(git rev-parse HEAD:foo)
1242tag=$(git rev-parse signed-tag 2>/dev/null)
1243
1244get_tag_header tree-signed-tag $tree tree $time >expect
1245echo "A message for a tree" >>expect
1246echo '-----BEGIN PGP SIGNATURE-----' >>expect
1247test_expect_success GPG \
1248        'creating a signed tag pointing to a tree should succeed' '
1249        git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
1250        get_tag_msg tree-signed-tag >actual &&
1251        test_cmp expect actual
1252'
1253
1254get_tag_header blob-signed-tag $blob blob $time >expect
1255echo "A message for a blob" >>expect
1256echo '-----BEGIN PGP SIGNATURE-----' >>expect
1257test_expect_success GPG \
1258        'creating a signed tag pointing to a blob should succeed' '
1259        git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
1260        get_tag_msg blob-signed-tag >actual &&
1261        test_cmp expect actual
1262'
1263
1264get_tag_header tag-signed-tag $tag tag $time >expect
1265echo "A message for another tag" >>expect
1266echo '-----BEGIN PGP SIGNATURE-----' >>expect
1267test_expect_success GPG \
1268        'creating a signed tag pointing to another tag should succeed' '
1269        git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
1270        get_tag_msg tag-signed-tag >actual &&
1271        test_cmp expect actual
1272'
1273
1274# usage with rfc1991 signatures
1275get_tag_header rfc1991-signed-tag $commit commit $time >expect
1276echo "RFC1991 signed tag" >>expect
1277echo '-----BEGIN PGP MESSAGE-----' >>expect
1278test_expect_success GPG,RFC1991 \
1279        'creating a signed tag with rfc1991' '
1280        echo "rfc1991" >gpghome/gpg.conf &&
1281        git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
1282        get_tag_msg rfc1991-signed-tag >actual &&
1283        test_cmp expect actual
1284'
1285
1286cat >fakeeditor <<'EOF'
1287#!/bin/sh
1288cp "$1" actual
1289EOF
1290chmod +x fakeeditor
1291
1292test_expect_success GPG,RFC1991 \
1293        'reediting a signed tag body omits signature' '
1294        echo "rfc1991" >gpghome/gpg.conf &&
1295        echo "RFC1991 signed tag" >expect &&
1296        GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1297        test_cmp expect actual
1298'
1299
1300test_expect_success GPG,RFC1991 \
1301        'verifying rfc1991 signature' '
1302        echo "rfc1991" >gpghome/gpg.conf &&
1303        git tag -v rfc1991-signed-tag
1304'
1305
1306test_expect_success GPG,RFC1991 \
1307        'list tag with rfc1991 signature' '
1308        echo "rfc1991" >gpghome/gpg.conf &&
1309        echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1310        git tag -l -n1 rfc1991-signed-tag >actual &&
1311        test_cmp expect actual &&
1312        git tag -l -n2 rfc1991-signed-tag >actual &&
1313        test_cmp expect actual &&
1314        git tag -l -n999 rfc1991-signed-tag >actual &&
1315        test_cmp expect actual
1316'
1317
1318rm -f gpghome/gpg.conf
1319
1320test_expect_success GPG,RFC1991 \
1321        'verifying rfc1991 signature without --rfc1991' '
1322        git tag -v rfc1991-signed-tag
1323'
1324
1325test_expect_success GPG,RFC1991 \
1326        'list tag with rfc1991 signature without --rfc1991' '
1327        echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
1328        git tag -l -n1 rfc1991-signed-tag >actual &&
1329        test_cmp expect actual &&
1330        git tag -l -n2 rfc1991-signed-tag >actual &&
1331        test_cmp expect actual &&
1332        git tag -l -n999 rfc1991-signed-tag >actual &&
1333        test_cmp expect actual
1334'
1335
1336test_expect_success GPG,RFC1991 \
1337        'reediting a signed tag body omits signature' '
1338        echo "RFC1991 signed tag" >expect &&
1339        GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
1340        test_cmp expect actual
1341'
1342
1343# try to sign with bad user.signingkey
1344test_expect_success GPG \
1345        'git tag -s fails if gpg is misconfigured (bad key)' \
1346        'test_config user.signingkey BobTheMouse &&
1347        test_must_fail git tag -s -m tail tag-gpg-failure'
1348
1349# try to produce invalid signature
1350test_expect_success GPG \
1351        'git tag -s fails if gpg is misconfigured (bad signature format)' \
1352        'test_config gpg.program echo &&
1353         test_must_fail git tag -s -m tail tag-gpg-failure'
1354
1355# try to sign with bad user.signingkey
1356test_expect_success GPGSM \
1357        'git tag -s fails if gpgsm is misconfigured (bad key)' \
1358        'test_config user.signingkey BobTheMouse &&
1359         test_config gpg.format x509 &&
1360         test_must_fail git tag -s -m tail tag-gpg-failure'
1361
1362# try to produce invalid signature
1363test_expect_success GPGSM \
1364        'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1365        'test_config gpg.x509.program echo &&
1366         test_config gpg.format x509 &&
1367         test_must_fail git tag -s -m tail tag-gpg-failure'
1368
1369# try to verify without gpg:
1370
1371rm -rf gpghome
1372test_expect_success GPG \
1373        'verify signed tag fails when public key is not present' \
1374        'test_must_fail git tag -v signed-tag'
1375
1376test_expect_success \
1377        'git tag -a fails if tag annotation is empty' '
1378        ! (GIT_EDITOR=cat git tag -a initial-comment)
1379'
1380
1381test_expect_success \
1382        'message in editor has initial comment' '
1383        ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
1384'
1385
1386test_expect_success 'message in editor has initial comment: first line' '
1387        # check the first line --- should be empty
1388        echo >first.expect &&
1389        sed -e 1q <actual >first.actual &&
1390        test_i18ncmp first.expect first.actual
1391'
1392
1393test_expect_success \
1394        'message in editor has initial comment: remainder' '
1395        # remove commented lines from the remainder -- should be empty
1396        sed -e 1d -e "/^#/d" <actual >rest.actual &&
1397        test_must_be_empty rest.actual
1398'
1399
1400get_tag_header reuse $commit commit $time >expect
1401echo "An annotation to be reused" >> expect
1402test_expect_success \
1403        'overwriting an annoted tag should use its previous body' '
1404        git tag -a -m "An annotation to be reused" reuse &&
1405        GIT_EDITOR=true git tag -f -a reuse &&
1406        get_tag_msg reuse >actual &&
1407        test_cmp expect actual
1408'
1409
1410test_expect_success 'filename for the message is relative to cwd' '
1411        mkdir subdir &&
1412        echo "Tag message in top directory" >msgfile-5 &&
1413        echo "Tag message in sub directory" >subdir/msgfile-5 &&
1414        (
1415                cd subdir &&
1416                git tag -a -F msgfile-5 tag-from-subdir
1417        ) &&
1418        git cat-file tag tag-from-subdir | grep "in sub directory"
1419'
1420
1421test_expect_success 'filename for the message is relative to cwd' '
1422        echo "Tag message in sub directory" >subdir/msgfile-6 &&
1423        (
1424                cd subdir &&
1425                git tag -a -F msgfile-6 tag-from-subdir-2
1426        ) &&
1427        git cat-file tag tag-from-subdir-2 | grep "in sub directory"
1428'
1429
1430# create a few more commits to test --contains
1431
1432hash1=$(git rev-parse HEAD)
1433
1434test_expect_success 'creating second commit and tag' '
1435        echo foo-2.0 >foo &&
1436        git add foo &&
1437        git commit -m second &&
1438        git tag v2.0
1439'
1440
1441hash2=$(git rev-parse HEAD)
1442
1443test_expect_success 'creating third commit without tag' '
1444        echo foo-dev >foo &&
1445        git add foo &&
1446        git commit -m third
1447'
1448
1449hash3=$(git rev-parse HEAD)
1450
1451# simple linear checks of --continue
1452
1453cat > expected <<EOF
1454v0.2.1
1455v1.0
1456v1.0.1
1457v1.1.3
1458v2.0
1459EOF
1460
1461test_expect_success 'checking that first commit is in all tags (hash)' "
1462        git tag -l --contains $hash1 v* >actual &&
1463        test_cmp expected actual
1464"
1465
1466# other ways of specifying the commit
1467test_expect_success 'checking that first commit is in all tags (tag)' "
1468        git tag -l --contains v1.0 v* >actual &&
1469        test_cmp expected actual
1470"
1471
1472test_expect_success 'checking that first commit is in all tags (relative)' "
1473        git tag -l --contains HEAD~2 v* >actual &&
1474        test_cmp expected actual
1475"
1476
1477# All the --contains tests above, but with --no-contains
1478test_expect_success 'checking that first commit is not listed in any tag with --no-contains  (hash)' "
1479        git tag -l --no-contains $hash1 v* >actual &&
1480        test_must_be_empty actual
1481"
1482
1483test_expect_success 'checking that first commit is in all tags (tag)' "
1484        git tag -l --no-contains v1.0 v* >actual &&
1485        test_must_be_empty actual
1486"
1487
1488test_expect_success 'checking that first commit is in all tags (relative)' "
1489        git tag -l --no-contains HEAD~2 v* >actual &&
1490        test_must_be_empty actual
1491"
1492
1493cat > expected <<EOF
1494v2.0
1495EOF
1496
1497test_expect_success 'checking that second commit only has one tag' "
1498        git tag -l --contains $hash2 v* >actual &&
1499        test_cmp expected actual
1500"
1501
1502cat > expected <<EOF
1503v0.2.1
1504v1.0
1505v1.0.1
1506v1.1.3
1507EOF
1508
1509test_expect_success 'inverse of the last test, with --no-contains' "
1510        git tag -l --no-contains $hash2 v* >actual &&
1511        test_cmp expected actual
1512"
1513
1514cat > expected <<EOF
1515EOF
1516
1517test_expect_success 'checking that third commit has no tags' "
1518        git tag -l --contains $hash3 v* >actual &&
1519        test_cmp expected actual
1520"
1521
1522cat > expected <<EOF
1523v0.2.1
1524v1.0
1525v1.0.1
1526v1.1.3
1527v2.0
1528EOF
1529
1530test_expect_success 'conversely --no-contains on the third commit lists all tags' "
1531        git tag -l --no-contains $hash3 v* >actual &&
1532        test_cmp expected actual
1533"
1534
1535# how about a simple merge?
1536
1537test_expect_success 'creating simple branch' '
1538        git branch stable v2.0 &&
1539        git checkout stable &&
1540        echo foo-3.0 > foo &&
1541        git commit foo -m fourth &&
1542        git tag v3.0
1543'
1544
1545hash4=$(git rev-parse HEAD)
1546
1547cat > expected <<EOF
1548v3.0
1549EOF
1550
1551test_expect_success 'checking that branch head only has one tag' "
1552        git tag -l --contains $hash4 v* >actual &&
1553        test_cmp expected actual
1554"
1555
1556cat > expected <<EOF
1557v0.2.1
1558v1.0
1559v1.0.1
1560v1.1.3
1561v2.0
1562EOF
1563
1564test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
1565        git tag -l --no-contains $hash4 v* >actual &&
1566        test_cmp expected actual
1567"
1568
1569test_expect_success 'merging original branch into this branch' '
1570        git merge --strategy=ours master &&
1571        git tag v4.0
1572'
1573
1574cat > expected <<EOF
1575v4.0
1576EOF
1577
1578test_expect_success 'checking that original branch head has one tag now' "
1579        git tag -l --contains $hash3 v* >actual &&
1580        test_cmp expected actual
1581"
1582
1583cat > expected <<EOF
1584v0.2.1
1585v1.0
1586v1.0.1
1587v1.1.3
1588v2.0
1589v3.0
1590EOF
1591
1592test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
1593        git tag -l --no-contains $hash3 v* >actual &&
1594        test_cmp expected actual
1595"
1596
1597cat > expected <<EOF
1598v0.2.1
1599v1.0
1600v1.0.1
1601v1.1.3
1602v2.0
1603v3.0
1604v4.0
1605EOF
1606
1607test_expect_success 'checking that initial commit is in all tags' "
1608        git tag -l --contains $hash1 v* >actual &&
1609        test_cmp expected actual
1610"
1611
1612test_expect_success 'checking that --contains can be used in non-list mode' '
1613        git tag --contains $hash1 v* >actual &&
1614        test_cmp expected actual
1615'
1616
1617test_expect_success 'checking that initial commit is in all tags with --no-contains' "
1618        git tag -l --no-contains $hash1 v* >actual &&
1619        test_must_be_empty actual
1620"
1621
1622# mixing modes and options:
1623
1624test_expect_success 'mixing incompatibles modes and options is forbidden' '
1625        test_must_fail git tag -a &&
1626        test_must_fail git tag -a -l &&
1627        test_must_fail git tag -s &&
1628        test_must_fail git tag -s -l &&
1629        test_must_fail git tag -m &&
1630        test_must_fail git tag -m -l &&
1631        test_must_fail git tag -m "hlagh" &&
1632        test_must_fail git tag -m "hlagh" -l &&
1633        test_must_fail git tag -F &&
1634        test_must_fail git tag -F -l &&
1635        test_must_fail git tag -f &&
1636        test_must_fail git tag -f -l &&
1637        test_must_fail git tag -a -s -m -F &&
1638        test_must_fail git tag -a -s -m -F -l &&
1639        test_must_fail git tag -l -v &&
1640        test_must_fail git tag -l -d &&
1641        test_must_fail git tag -l -v -d &&
1642        test_must_fail git tag -n 100 -v &&
1643        test_must_fail git tag -l -m msg &&
1644        test_must_fail git tag -l -F some file &&
1645        test_must_fail git tag -v -s &&
1646        test_must_fail git tag --contains tag-tree &&
1647        test_must_fail git tag --contains tag-blob &&
1648        test_must_fail git tag --no-contains tag-tree &&
1649        test_must_fail git tag --no-contains tag-blob &&
1650        test_must_fail git tag --contains --no-contains &&
1651        test_must_fail git tag --no-with HEAD &&
1652        test_must_fail git tag --no-without HEAD
1653'
1654
1655for option in --contains --with --no-contains --without --merged --no-merged --points-at
1656do
1657        test_expect_success "mixing incompatible modes with $option is forbidden" "
1658                test_must_fail git tag -d $option HEAD &&
1659                test_must_fail git tag -d $option HEAD some-tag &&
1660                test_must_fail git tag -v $option HEAD
1661        "
1662        test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
1663                git tag -n $option HEAD HEAD &&
1664                git tag $option HEAD HEAD &&
1665                git tag $option
1666        "
1667done
1668
1669# check points-at
1670
1671test_expect_success '--points-at can be used in non-list mode' '
1672        echo v4.0 >expect &&
1673        git tag --points-at=v4.0 "v*" >actual &&
1674        test_cmp expect actual
1675'
1676
1677test_expect_success '--points-at is a synonym for --points-at HEAD' '
1678        echo v4.0 >expect &&
1679        git tag --points-at >actual &&
1680        test_cmp expect actual
1681'
1682
1683test_expect_success '--points-at finds lightweight tags' '
1684        echo v4.0 >expect &&
1685        git tag --points-at v4.0 >actual &&
1686        test_cmp expect actual
1687'
1688
1689test_expect_success '--points-at finds annotated tags of commits' '
1690        git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
1691        echo annotated-v4.0 >expect &&
1692        git tag -l --points-at v4.0 "annotated*" >actual &&
1693        test_cmp expect actual
1694'
1695
1696test_expect_success '--points-at finds annotated tags of tags' '
1697        git tag -m "describing the v4.0 tag object" \
1698                annotated-again-v4.0 annotated-v4.0 &&
1699        cat >expect <<-\EOF &&
1700        annotated-again-v4.0
1701        annotated-v4.0
1702        EOF
1703        git tag --points-at=annotated-v4.0 >actual &&
1704        test_cmp expect actual
1705'
1706
1707test_expect_success 'multiple --points-at are OR-ed together' '
1708        cat >expect <<-\EOF &&
1709        v2.0
1710        v3.0
1711        EOF
1712        git tag --points-at=v2.0 --points-at=v3.0 >actual &&
1713        test_cmp expect actual
1714'
1715
1716test_expect_success 'lexical sort' '
1717        git tag foo1.3 &&
1718        git tag foo1.6 &&
1719        git tag foo1.10 &&
1720        git tag -l --sort=refname "foo*" >actual &&
1721        cat >expect <<-\EOF &&
1722        foo1.10
1723        foo1.3
1724        foo1.6
1725        EOF
1726        test_cmp expect actual
1727'
1728
1729test_expect_success 'version sort' '
1730        git tag -l --sort=version:refname "foo*" >actual &&
1731        cat >expect <<-\EOF &&
1732        foo1.3
1733        foo1.6
1734        foo1.10
1735        EOF
1736        test_cmp expect actual
1737'
1738
1739test_expect_success 'reverse version sort' '
1740        git tag -l --sort=-version:refname "foo*" >actual &&
1741        cat >expect <<-\EOF &&
1742        foo1.10
1743        foo1.6
1744        foo1.3
1745        EOF
1746        test_cmp expect actual
1747'
1748
1749test_expect_success 'reverse lexical sort' '
1750        git tag -l --sort=-refname "foo*" >actual &&
1751        cat >expect <<-\EOF &&
1752        foo1.6
1753        foo1.3
1754        foo1.10
1755        EOF
1756        test_cmp expect actual
1757'
1758
1759test_expect_success 'configured lexical sort' '
1760        test_config tag.sort "v:refname" &&
1761        git tag -l "foo*" >actual &&
1762        cat >expect <<-\EOF &&
1763        foo1.3
1764        foo1.6
1765        foo1.10
1766        EOF
1767        test_cmp expect actual
1768'
1769
1770test_expect_success 'option override configured sort' '
1771        test_config tag.sort "v:refname" &&
1772        git tag -l --sort=-refname "foo*" >actual &&
1773        cat >expect <<-\EOF &&
1774        foo1.6
1775        foo1.3
1776        foo1.10
1777        EOF
1778        test_cmp expect actual
1779'
1780
1781test_expect_success 'invalid sort parameter on command line' '
1782        test_must_fail git tag -l --sort=notvalid "foo*" >actual
1783'
1784
1785test_expect_success 'invalid sort parameter in configuratoin' '
1786        test_config tag.sort "v:notvalid" &&
1787        test_must_fail git tag -l "foo*"
1788'
1789
1790test_expect_success 'version sort with prerelease reordering' '
1791        test_config versionsort.prereleaseSuffix -rc &&
1792        git tag foo1.6-rc1 &&
1793        git tag foo1.6-rc2 &&
1794        git tag -l --sort=version:refname "foo*" >actual &&
1795        cat >expect <<-\EOF &&
1796        foo1.3
1797        foo1.6-rc1
1798        foo1.6-rc2
1799        foo1.6
1800        foo1.10
1801        EOF
1802        test_cmp expect actual
1803'
1804
1805test_expect_success 'reverse version sort with prerelease reordering' '
1806        test_config versionsort.prereleaseSuffix -rc &&
1807        git tag -l --sort=-version:refname "foo*" >actual &&
1808        cat >expect <<-\EOF &&
1809        foo1.10
1810        foo1.6
1811        foo1.6-rc2
1812        foo1.6-rc1
1813        foo1.3
1814        EOF
1815        test_cmp expect actual
1816'
1817
1818test_expect_success 'version sort with prerelease reordering and common leading character' '
1819        test_config versionsort.prereleaseSuffix -before &&
1820        git tag foo1.7-before1 &&
1821        git tag foo1.7 &&
1822        git tag foo1.7-after1 &&
1823        git tag -l --sort=version:refname "foo1.7*" >actual &&
1824        cat >expect <<-\EOF &&
1825        foo1.7-before1
1826        foo1.7
1827        foo1.7-after1
1828        EOF
1829        test_cmp expect actual
1830'
1831
1832test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1833        test_config versionsort.prereleaseSuffix -before &&
1834        git config --add versionsort.prereleaseSuffix -after &&
1835        git tag -l --sort=version:refname "foo1.7*" >actual &&
1836        cat >expect <<-\EOF &&
1837        foo1.7-before1
1838        foo1.7-after1
1839        foo1.7
1840        EOF
1841        test_cmp expect actual
1842'
1843
1844test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
1845        test_config versionsort.prereleaseSuffix -bar &&
1846        git config --add versionsort.prereleaseSuffix -foo-baz &&
1847        git config --add versionsort.prereleaseSuffix -foo-bar &&
1848        git tag foo1.8-foo-bar &&
1849        git tag foo1.8-foo-baz &&
1850        git tag foo1.8 &&
1851        git tag -l --sort=version:refname "foo1.8*" >actual &&
1852        cat >expect <<-\EOF &&
1853        foo1.8-foo-baz
1854        foo1.8-foo-bar
1855        foo1.8
1856        EOF
1857        test_cmp expect actual
1858'
1859
1860test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
1861        test_config versionsort.prereleaseSuffix -pre &&
1862        git config --add versionsort.prereleaseSuffix -prerelease &&
1863        git tag foo1.9-pre1 &&
1864        git tag foo1.9-pre2 &&
1865        git tag foo1.9-prerelease1 &&
1866        git tag -l --sort=version:refname "foo1.9*" >actual &&
1867        cat >expect <<-\EOF &&
1868        foo1.9-pre1
1869        foo1.9-pre2
1870        foo1.9-prerelease1
1871        EOF
1872        test_cmp expect actual
1873'
1874
1875test_expect_success 'version sort with general suffix reordering' '
1876        test_config versionsort.suffix -alpha &&
1877        git config --add versionsort.suffix -beta &&
1878        git config --add versionsort.suffix ""  &&
1879        git config --add versionsort.suffix -gamma &&
1880        git config --add versionsort.suffix -delta &&
1881        git tag foo1.10-alpha &&
1882        git tag foo1.10-beta &&
1883        git tag foo1.10-gamma &&
1884        git tag foo1.10-delta &&
1885        git tag foo1.10-unlisted-suffix &&
1886        git tag -l --sort=version:refname "foo1.10*" >actual &&
1887        cat >expect <<-\EOF &&
1888        foo1.10-alpha
1889        foo1.10-beta
1890        foo1.10
1891        foo1.10-unlisted-suffix
1892        foo1.10-gamma
1893        foo1.10-delta
1894        EOF
1895        test_cmp expect actual
1896'
1897
1898test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
1899        test_config versionsort.suffix -before &&
1900        test_config versionsort.prereleaseSuffix -after &&
1901        git tag -l --sort=version:refname "foo1.7*" >actual &&
1902        cat >expect <<-\EOF &&
1903        foo1.7-before1
1904        foo1.7
1905        foo1.7-after1
1906        EOF
1907        test_cmp expect actual
1908'
1909
1910test_expect_success 'version sort with very long prerelease suffix' '
1911        test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
1912        git tag -l --sort=version:refname
1913'
1914
1915test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1916        i=1 &&
1917        while test $i -lt 8000
1918        do
1919                echo "commit refs/heads/master
1920committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
1921data <<EOF
1922commit #$i
1923EOF"
1924                test $i = 1 && echo "from refs/heads/master^0"
1925                i=$(($i + 1))
1926        done | git fast-import &&
1927        git checkout master &&
1928        git tag far-far-away HEAD^ &&
1929        run_with_limited_stack git tag --contains HEAD >actual &&
1930        test_must_be_empty actual &&
1931        run_with_limited_stack git tag --no-contains HEAD >actual &&
1932        test_line_count "-gt" 10 actual
1933'
1934
1935test_expect_success '--format should list tags as per format given' '
1936        cat >expect <<-\EOF &&
1937        refname : refs/tags/v1.0
1938        refname : refs/tags/v1.0.1
1939        refname : refs/tags/v1.1.3
1940        EOF
1941        git tag -l --format="refname : %(refname)" "v1*" >actual &&
1942        test_cmp expect actual
1943'
1944
1945test_expect_success "set up color tests" '
1946        echo "<RED>v1.0<RESET>" >expect.color &&
1947        echo "v1.0" >expect.bare &&
1948        color_args="--format=%(color:red)%(refname:short) --list v1.0"
1949'
1950
1951test_expect_success '%(color) omitted without tty' '
1952        TERM=vt100 git tag $color_args >actual.raw &&
1953        test_decode_color <actual.raw >actual &&
1954        test_cmp expect.bare actual
1955'
1956
1957test_expect_success TTY '%(color) present with tty' '
1958        test_terminal git tag $color_args >actual.raw &&
1959        test_decode_color <actual.raw >actual &&
1960        test_cmp expect.color actual
1961'
1962
1963test_expect_success '--color overrides auto-color' '
1964        git tag --color $color_args >actual.raw &&
1965        test_decode_color <actual.raw >actual &&
1966        test_cmp expect.color actual
1967'
1968
1969test_expect_success 'color.ui=always overrides auto-color' '
1970        git -c color.ui=always tag $color_args >actual.raw &&
1971        test_decode_color <actual.raw >actual &&
1972        test_cmp expect.color actual
1973'
1974
1975test_expect_success 'setup --merged test tags' '
1976        git tag mergetest-1 HEAD~2 &&
1977        git tag mergetest-2 HEAD~1 &&
1978        git tag mergetest-3 HEAD
1979'
1980
1981test_expect_success '--merged can be used in non-list mode' '
1982        cat >expect <<-\EOF &&
1983        mergetest-1
1984        mergetest-2
1985        EOF
1986        git tag --merged=mergetest-2 "mergetest*" >actual &&
1987        test_cmp expect actual
1988'
1989
1990test_expect_success '--merged is incompatible with --no-merged' '
1991        test_must_fail git tag --merged HEAD --no-merged HEAD
1992'
1993
1994test_expect_success '--merged shows merged tags' '
1995        cat >expect <<-\EOF &&
1996        mergetest-1
1997        mergetest-2
1998        EOF
1999        git tag -l --merged=mergetest-2 mergetest-* >actual &&
2000        test_cmp expect actual
2001'
2002
2003test_expect_success '--no-merged show unmerged tags' '
2004        cat >expect <<-\EOF &&
2005        mergetest-3
2006        EOF
2007        git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
2008        test_cmp expect actual
2009'
2010
2011test_expect_success '--no-merged can be used in non-list mode' '
2012        git tag --no-merged=mergetest-2 mergetest-* >actual &&
2013        test_cmp expect actual
2014'
2015
2016test_expect_success 'ambiguous branch/tags not marked' '
2017        git tag ambiguous &&
2018        git branch ambiguous &&
2019        echo ambiguous >expect &&
2020        git tag -l ambiguous >actual &&
2021        test_cmp expect actual
2022'
2023
2024test_expect_success '--contains combined with --no-contains' '
2025        (
2026                git init no-contains &&
2027                cd no-contains &&
2028                test_commit v0.1 &&
2029                test_commit v0.2 &&
2030                test_commit v0.3 &&
2031                test_commit v0.4 &&
2032                test_commit v0.5 &&
2033                cat >expected <<-\EOF &&
2034                v0.2
2035                v0.3
2036                v0.4
2037                EOF
2038                git tag --contains v0.2 --no-contains v0.5 >actual &&
2039                test_cmp expected actual
2040        )
2041'
2042
2043# As the docs say, list tags which contain a specified *commit*. We
2044# don't recurse down to tags for trees or blobs pointed to by *those*
2045# commits.
2046test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
2047        cd no-contains &&
2048        blob=$(git rev-parse v0.3:v0.3.t) &&
2049        tree=$(git rev-parse v0.3^{tree}) &&
2050        git tag tag-blob $blob &&
2051        git tag tag-tree $tree &&
2052        git tag --contains v0.3 >actual &&
2053        cat >expected <<-\EOF &&
2054        v0.3
2055        v0.4
2056        v0.5
2057        EOF
2058        test_cmp expected actual &&
2059        git tag --no-contains v0.3 >actual &&
2060        cat >expected <<-\EOF &&
2061        v0.1
2062        v0.2
2063        EOF
2064        test_cmp expected actual
2065'
2066
2067test_done