t / t7600-merge.shon commit t3507: clean up style (5caab8d)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Lars Hjemli
   4#
   5
   6test_description='git merge
   7
   8Testing basic merge operations/option parsing.
   9
  10! [c0] commit 0
  11 ! [c1] commit 1
  12  ! [c2] commit 2
  13   ! [c3] commit 3
  14    ! [c4] c4
  15     ! [c5] c5
  16      ! [c6] c6
  17       * [master] Merge commit 'c1'
  18--------
  19       - [master] Merge commit 'c1'
  20 +     * [c1] commit 1
  21      +  [c6] c6
  22     +   [c5] c5
  23    ++   [c4] c4
  24   ++++  [c3] commit 3
  25  +      [c2] commit 2
  26+++++++* [c0] commit 0
  27'
  28
  29. ./test-lib.sh
  30. "$TEST_DIRECTORY"/lib-gpg.sh
  31
  32printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
  33printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
  34printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
  35printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
  36printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y
  37printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
  38printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
  39printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
  40printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z
  41
  42create_merge_msgs () {
  43        echo "Merge tag 'c2'" >msg.1-5 &&
  44        echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 &&
  45        {
  46                echo "Squashed commit of the following:" &&
  47                echo &&
  48                git log --no-merges ^HEAD c1
  49        } >squash.1 &&
  50        {
  51                echo "Squashed commit of the following:" &&
  52                echo &&
  53                git log --no-merges ^HEAD c2
  54        } >squash.1-5 &&
  55        {
  56                echo "Squashed commit of the following:" &&
  57                echo &&
  58                git log --no-merges ^HEAD c2 c3
  59        } >squash.1-5-9 &&
  60        {
  61                echo "* tag 'c3':" &&
  62                echo "  commit 3"
  63        } >msg.log
  64}
  65
  66verify_merge () {
  67        test_cmp "$2" "$1" &&
  68        git update-index --refresh &&
  69        git diff --exit-code &&
  70        if test -n "$3"
  71        then
  72                git show -s --pretty=tformat:%s HEAD >msg.act &&
  73                test_cmp "$3" msg.act
  74        fi
  75}
  76
  77verify_head () {
  78        echo "$1" >head.expected &&
  79        git rev-parse HEAD >head.actual &&
  80        test_cmp head.expected head.actual
  81}
  82
  83verify_parents () {
  84        printf '%s\n' "$@" >parents.expected &&
  85        >parents.actual &&
  86        i=1 &&
  87        while test $i -le $#
  88        do
  89                git rev-parse HEAD^$i >>parents.actual &&
  90                i=$(expr $i + 1) ||
  91                return 1
  92        done &&
  93        test_must_fail git rev-parse --verify "HEAD^$i" &&
  94        test_cmp parents.expected parents.actual
  95}
  96
  97verify_mergeheads () {
  98        printf '%s\n' "$@" >mergehead.expected &&
  99        while read sha1 rest
 100        do
 101                git rev-parse $sha1
 102        done <.git/MERGE_HEAD >mergehead.actual &&
 103        test_cmp mergehead.expected mergehead.actual
 104}
 105
 106verify_no_mergehead () {
 107        ! test -e .git/MERGE_HEAD
 108}
 109
 110test_expect_success 'setup' '
 111        git add file &&
 112        test_tick &&
 113        git commit -m "commit 0" &&
 114        git tag c0 &&
 115        c0=$(git rev-parse HEAD) &&
 116        cp file.1 file &&
 117        git add file &&
 118        test_tick &&
 119        git commit -m "commit 1" &&
 120        git tag c1 &&
 121        c1=$(git rev-parse HEAD) &&
 122        git reset --hard "$c0" &&
 123        cp file.5 file &&
 124        git add file &&
 125        test_tick &&
 126        git commit -m "commit 2" &&
 127        git tag c2 &&
 128        c2=$(git rev-parse HEAD) &&
 129        git reset --hard "$c0" &&
 130        cp file.9y file &&
 131        git add file &&
 132        test_tick &&
 133        git commit -m "commit 7" &&
 134        git tag c7 &&
 135        git reset --hard "$c0" &&
 136        cp file.9 file &&
 137        git add file &&
 138        test_tick &&
 139        git commit -m "commit 3" &&
 140        git tag c3 &&
 141        c3=$(git rev-parse HEAD) &&
 142        git reset --hard "$c0" &&
 143        create_merge_msgs
 144'
 145
 146test_debug 'git log --graph --decorate --oneline --all'
 147
 148test_expect_success 'test option parsing' '
 149        test_must_fail git merge -$ c1 &&
 150        test_must_fail git merge --no-such c1 &&
 151        test_must_fail git merge -s foobar c1 &&
 152        test_must_fail git merge -s=foobar c1 &&
 153        test_must_fail git merge -m &&
 154        test_must_fail git merge --abort foobar &&
 155        test_must_fail git merge --abort --quiet &&
 156        test_must_fail git merge --continue foobar &&
 157        test_must_fail git merge --continue --quiet &&
 158        test_must_fail git merge
 159'
 160
 161test_expect_success 'merge -h with invalid index' '
 162        mkdir broken &&
 163        (
 164                cd broken &&
 165                git init &&
 166                >.git/index &&
 167                test_expect_code 129 git merge -h 2>usage
 168        ) &&
 169        test_i18ngrep "[Uu]sage: git merge" broken/usage
 170'
 171
 172test_expect_success 'reject non-strategy with a git-merge-foo name' '
 173        test_must_fail git merge -s index c1
 174'
 175
 176test_expect_success 'merge c0 with c1' '
 177        echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
 178
 179        git reset --hard c0 &&
 180        git merge c1 &&
 181        verify_merge file result.1 &&
 182        verify_head "$c1" &&
 183
 184        git reflog -1 >reflog.actual &&
 185        sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
 186        test_cmp reflog.expected reflog.fuzzy
 187'
 188
 189test_debug 'git log --graph --decorate --oneline --all'
 190
 191test_expect_success 'merge c0 with c1 with --ff-only' '
 192        git reset --hard c0 &&
 193        git merge --ff-only c1 &&
 194        git merge --ff-only HEAD c0 c1 &&
 195        verify_merge file result.1 &&
 196        verify_head "$c1"
 197'
 198
 199test_debug 'git log --graph --decorate --oneline --all'
 200
 201test_expect_success 'merge from unborn branch' '
 202        git checkout -f master &&
 203        test_might_fail git branch -D kid &&
 204
 205        echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
 206
 207        git checkout --orphan kid &&
 208        test_when_finished "git checkout -f master" &&
 209        git rm -fr . &&
 210        test_tick &&
 211        git merge --ff-only c1 &&
 212        verify_merge file result.1 &&
 213        verify_head "$c1" &&
 214
 215        git reflog -1 >reflog.actual &&
 216        sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
 217        test_cmp reflog.expected reflog.fuzzy
 218'
 219
 220test_debug 'git log --graph --decorate --oneline --all'
 221
 222test_expect_success 'merge c1 with c2' '
 223        git reset --hard c1 &&
 224        test_tick &&
 225        git merge c2 &&
 226        verify_merge file result.1-5 msg.1-5 &&
 227        verify_parents $c1 $c2
 228'
 229
 230test_expect_success 'merge --squash c3 with c7' '
 231        git reset --hard c3 &&
 232        test_must_fail git merge --squash c7 &&
 233        cat result.9z >file &&
 234        git commit --no-edit -a &&
 235
 236        cat >expect <<-EOF &&
 237        Squashed commit of the following:
 238
 239        $(git show -s c7)
 240
 241        # Conflicts:
 242        #       file
 243        EOF
 244        git cat-file commit HEAD >raw &&
 245        sed -e '1,/^$/d' raw >actual &&
 246        test_cmp expect actual
 247'
 248
 249test_debug 'git log --graph --decorate --oneline --all'
 250
 251test_expect_success 'merge c1 with c2 and c3' '
 252        git reset --hard c1 &&
 253        test_tick &&
 254        git merge c2 c3 &&
 255        verify_merge file result.1-5-9 msg.1-5-9 &&
 256        verify_parents $c1 $c2 $c3
 257'
 258
 259test_debug 'git log --graph --decorate --oneline --all'
 260
 261test_expect_success 'merges with --ff-only' '
 262        git reset --hard c1 &&
 263        test_tick &&
 264        test_must_fail git merge --ff-only c2 &&
 265        test_must_fail git merge --ff-only c3 &&
 266        test_must_fail git merge --ff-only c2 c3 &&
 267        git reset --hard c0 &&
 268        git merge c3 &&
 269        verify_head $c3
 270'
 271
 272test_expect_success 'merges with merge.ff=only' '
 273        git reset --hard c1 &&
 274        test_tick &&
 275        test_config merge.ff "only" &&
 276        test_must_fail git merge c2 &&
 277        test_must_fail git merge c3 &&
 278        test_must_fail git merge c2 c3 &&
 279        git reset --hard c0 &&
 280        git merge c3 &&
 281        verify_head $c3
 282'
 283
 284test_expect_success 'merge c0 with c1 (no-commit)' '
 285        git reset --hard c0 &&
 286        git merge --no-commit c1 &&
 287        verify_merge file result.1 &&
 288        verify_head $c1
 289'
 290
 291test_debug 'git log --graph --decorate --oneline --all'
 292
 293test_expect_success 'merge c1 with c2 (no-commit)' '
 294        git reset --hard c1 &&
 295        git merge --no-commit c2 &&
 296        verify_merge file result.1-5 &&
 297        verify_head $c1 &&
 298        verify_mergeheads $c2
 299'
 300
 301test_debug 'git log --graph --decorate --oneline --all'
 302
 303test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
 304        git reset --hard c1 &&
 305        git merge --no-commit c2 c3 &&
 306        verify_merge file result.1-5-9 &&
 307        verify_head $c1 &&
 308        verify_mergeheads $c2 $c3
 309'
 310
 311test_debug 'git log --graph --decorate --oneline --all'
 312
 313test_expect_success 'merge c0 with c1 (squash)' '
 314        git reset --hard c0 &&
 315        git merge --squash c1 &&
 316        verify_merge file result.1 &&
 317        verify_head $c0 &&
 318        verify_no_mergehead &&
 319        test_cmp squash.1 .git/SQUASH_MSG
 320'
 321
 322test_debug 'git log --graph --decorate --oneline --all'
 323
 324test_expect_success 'merge c0 with c1 (squash, ff-only)' '
 325        git reset --hard c0 &&
 326        git merge --squash --ff-only c1 &&
 327        verify_merge file result.1 &&
 328        verify_head $c0 &&
 329        verify_no_mergehead &&
 330        test_cmp squash.1 .git/SQUASH_MSG
 331'
 332
 333test_debug 'git log --graph --decorate --oneline --all'
 334
 335test_expect_success 'merge c1 with c2 (squash)' '
 336        git reset --hard c1 &&
 337        git merge --squash c2 &&
 338        verify_merge file result.1-5 &&
 339        verify_head $c1 &&
 340        verify_no_mergehead &&
 341        test_cmp squash.1-5 .git/SQUASH_MSG
 342'
 343
 344test_debug 'git log --graph --decorate --oneline --all'
 345
 346test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
 347        git reset --hard c1 &&
 348        test_must_fail git merge --squash --ff-only c2
 349'
 350
 351test_debug 'git log --graph --decorate --oneline --all'
 352
 353test_expect_success 'merge c1 with c2 and c3 (squash)' '
 354        git reset --hard c1 &&
 355        git merge --squash c2 c3 &&
 356        verify_merge file result.1-5-9 &&
 357        verify_head $c1 &&
 358        verify_no_mergehead &&
 359        test_cmp squash.1-5-9 .git/SQUASH_MSG
 360'
 361
 362test_debug 'git log --graph --decorate --oneline --all'
 363
 364test_expect_success 'merge c1 with c2 (no-commit in config)' '
 365        git reset --hard c1 &&
 366        test_config branch.master.mergeoptions "--no-commit" &&
 367        git merge c2 &&
 368        verify_merge file result.1-5 &&
 369        verify_head $c1 &&
 370        verify_mergeheads $c2
 371'
 372
 373test_debug 'git log --graph --decorate --oneline --all'
 374
 375test_expect_success 'merge c1 with c2 (log in config)' '
 376        git reset --hard c1 &&
 377        git merge --log c2 &&
 378        git show -s --pretty=tformat:%s%n%b >expect &&
 379
 380        test_config branch.master.mergeoptions "--log" &&
 381        git reset --hard c1 &&
 382        git merge c2 &&
 383        git show -s --pretty=tformat:%s%n%b >actual &&
 384
 385        test_cmp expect actual
 386'
 387
 388test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
 389        git reset --hard c1 &&
 390        git merge c2 &&
 391        git show -s --pretty=tformat:%s%n%b >expect &&
 392
 393        test_config branch.master.mergeoptions "--no-log" &&
 394        test_config merge.log "true" &&
 395        git reset --hard c1 &&
 396        git merge c2 &&
 397        git show -s --pretty=tformat:%s%n%b >actual &&
 398
 399        test_cmp expect actual
 400'
 401
 402test_expect_success 'merge c1 with c2 (squash in config)' '
 403        git reset --hard c1 &&
 404        test_config branch.master.mergeoptions "--squash" &&
 405        git merge c2 &&
 406        verify_merge file result.1-5 &&
 407        verify_head $c1 &&
 408        verify_no_mergehead &&
 409        test_cmp squash.1-5 .git/SQUASH_MSG
 410'
 411
 412test_debug 'git log --graph --decorate --oneline --all'
 413
 414test_expect_success 'override config option -n with --summary' '
 415        git reset --hard c1 &&
 416        test_config branch.master.mergeoptions "-n" &&
 417        test_tick &&
 418        git merge --summary c2 >diffstat.txt &&
 419        verify_merge file result.1-5 msg.1-5 &&
 420        verify_parents $c1 $c2 &&
 421        if ! grep "^ file |  *2 +-$" diffstat.txt
 422        then
 423                echo "[OOPS] diffstat was not generated with --summary"
 424                false
 425        fi
 426'
 427
 428test_expect_success 'override config option -n with --stat' '
 429        git reset --hard c1 &&
 430        test_config branch.master.mergeoptions "-n" &&
 431        test_tick &&
 432        git merge --stat c2 >diffstat.txt &&
 433        verify_merge file result.1-5 msg.1-5 &&
 434        verify_parents $c1 $c2 &&
 435        if ! grep "^ file |  *2 +-$" diffstat.txt
 436        then
 437                echo "[OOPS] diffstat was not generated with --stat"
 438                false
 439        fi
 440'
 441
 442test_debug 'git log --graph --decorate --oneline --all'
 443
 444test_expect_success 'override config option --stat' '
 445        git reset --hard c1 &&
 446        test_config branch.master.mergeoptions "--stat" &&
 447        test_tick &&
 448        git merge -n c2 >diffstat.txt &&
 449        verify_merge file result.1-5 msg.1-5 &&
 450        verify_parents $c1 $c2 &&
 451        if grep "^ file |  *2 +-$" diffstat.txt
 452        then
 453                echo "[OOPS] diffstat was generated"
 454                false
 455        fi
 456'
 457
 458test_debug 'git log --graph --decorate --oneline --all'
 459
 460test_expect_success 'merge c1 with c2 (override --no-commit)' '
 461        git reset --hard c1 &&
 462        test_config branch.master.mergeoptions "--no-commit" &&
 463        test_tick &&
 464        git merge --commit c2 &&
 465        verify_merge file result.1-5 msg.1-5 &&
 466        verify_parents $c1 $c2
 467'
 468
 469test_debug 'git log --graph --decorate --oneline --all'
 470
 471test_expect_success 'merge c1 with c2 (override --squash)' '
 472        git reset --hard c1 &&
 473        test_config branch.master.mergeoptions "--squash" &&
 474        test_tick &&
 475        git merge --no-squash c2 &&
 476        verify_merge file result.1-5 msg.1-5 &&
 477        verify_parents $c1 $c2
 478'
 479
 480test_debug 'git log --graph --decorate --oneline --all'
 481
 482test_expect_success 'merge c0 with c1 (no-ff)' '
 483        git reset --hard c0 &&
 484        test_tick &&
 485        git merge --no-ff c1 &&
 486        verify_merge file result.1 &&
 487        verify_parents $c0 $c1
 488'
 489
 490test_debug 'git log --graph --decorate --oneline --all'
 491
 492test_expect_success 'merge c0 with c1 (merge.ff=false)' '
 493        git reset --hard c0 &&
 494        test_config merge.ff "false" &&
 495        test_tick &&
 496        git merge c1 &&
 497        verify_merge file result.1 &&
 498        verify_parents $c0 $c1
 499'
 500test_debug 'git log --graph --decorate --oneline --all'
 501
 502test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
 503        git reset --hard c0 &&
 504        test_config branch.master.mergeoptions "--ff" &&
 505        test_config merge.ff "false" &&
 506        test_tick &&
 507        git merge c1 &&
 508        verify_merge file result.1 &&
 509        verify_parents "$c0"
 510'
 511
 512test_expect_success 'tolerate unknown values for merge.ff' '
 513        git reset --hard c0 &&
 514        test_config merge.ff "something-new" &&
 515        test_tick &&
 516        git merge c1 2>message &&
 517        verify_head "$c1" &&
 518        test_must_be_empty message
 519'
 520
 521test_expect_success 'combining --squash and --no-ff is refused' '
 522        git reset --hard c0 &&
 523        test_must_fail git merge --squash --no-ff c1 &&
 524        test_must_fail git merge --no-ff --squash c1
 525'
 526
 527test_expect_success 'option --ff-only overwrites --no-ff' '
 528        git merge --no-ff --ff-only c1 &&
 529        test_must_fail git merge --no-ff --ff-only c2
 530'
 531
 532test_expect_success 'option --no-ff overrides merge.ff=only config' '
 533        git reset --hard c0 &&
 534        test_config merge.ff only &&
 535        git merge --no-ff c1
 536'
 537
 538test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
 539        git reset --hard c0 &&
 540        test_config branch.master.mergeoptions "--no-ff" &&
 541        git merge --ff c1 &&
 542        verify_merge file result.1 &&
 543        verify_head $c1
 544'
 545
 546test_expect_success 'merge log message' '
 547        git reset --hard c0 &&
 548        git merge --no-log c2 &&
 549        git show -s --pretty=format:%b HEAD >msg.act &&
 550        test_must_be_empty msg.act &&
 551
 552        git reset --hard c0 &&
 553        test_config branch.master.mergeoptions "--no-ff" &&
 554        git merge --no-log c2 &&
 555        git show -s --pretty=format:%b HEAD >msg.act &&
 556        test_must_be_empty msg.act &&
 557
 558        git merge --log c3 &&
 559        git show -s --pretty=format:%b HEAD >msg.act &&
 560        test_cmp msg.log msg.act &&
 561
 562        git reset --hard HEAD^ &&
 563        test_config merge.log "yes" &&
 564        git merge c3 &&
 565        git show -s --pretty=format:%b HEAD >msg.act &&
 566        test_cmp msg.log msg.act
 567'
 568
 569test_debug 'git log --graph --decorate --oneline --all'
 570
 571test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 572       git reset --hard c1 &&
 573       test_tick &&
 574       git merge c0 c2 c0 c1 &&
 575       verify_merge file result.1-5 &&
 576       verify_parents $c1 $c2
 577'
 578
 579test_debug 'git log --graph --decorate --oneline --all'
 580
 581test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 582       git reset --hard c1 &&
 583       test_tick &&
 584       git merge c0 c2 c0 c1 &&
 585       verify_merge file result.1-5 &&
 586       verify_parents $c1 $c2
 587'
 588
 589test_debug 'git log --graph --decorate --oneline --all'
 590
 591test_expect_success 'merge c1 with c1 and c2' '
 592       git reset --hard c1 &&
 593       test_tick &&
 594       git merge c1 c2 &&
 595       verify_merge file result.1-5 &&
 596       verify_parents $c1 $c2
 597'
 598
 599test_debug 'git log --graph --decorate --oneline --all'
 600
 601test_expect_success 'merge fast-forward in a dirty tree' '
 602       git reset --hard c0 &&
 603       mv file file1 &&
 604       cat file1 >file &&
 605       rm -f file1 &&
 606       git merge c2
 607'
 608
 609test_debug 'git log --graph --decorate --oneline --all'
 610
 611test_expect_success 'in-index merge' '
 612        git reset --hard c0 &&
 613        git merge --no-ff -s resolve c1 >out &&
 614        test_i18ngrep "Wonderful." out &&
 615        verify_parents $c0 $c1
 616'
 617
 618test_debug 'git log --graph --decorate --oneline --all'
 619
 620test_expect_success 'refresh the index before merging' '
 621        git reset --hard c1 &&
 622        cp file file.n && mv -f file.n file &&
 623        git merge c3
 624'
 625
 626cat >expected.branch <<\EOF
 627Merge branch 'c5-branch' (early part)
 628EOF
 629cat >expected.tag <<\EOF
 630Merge commit 'c5~1'
 631EOF
 632
 633test_expect_success 'merge early part of c2' '
 634        git reset --hard c3 &&
 635        echo c4 >c4.c &&
 636        git add c4.c &&
 637        git commit -m c4 &&
 638        git tag c4 &&
 639        echo c5 >c5.c &&
 640        git add c5.c &&
 641        git commit -m c5 &&
 642        git tag c5 &&
 643        git reset --hard c3 &&
 644        echo c6 >c6.c &&
 645        git add c6.c &&
 646        git commit -m c6 &&
 647        git tag c6 &&
 648        git branch -f c5-branch c5 &&
 649        git merge c5-branch~1 &&
 650        git show -s --pretty=tformat:%s HEAD >actual.branch &&
 651        git reset --keep HEAD^ &&
 652        git merge c5~1 &&
 653        git show -s --pretty=tformat:%s HEAD >actual.tag &&
 654        test_cmp expected.branch actual.branch &&
 655        test_cmp expected.tag actual.tag
 656'
 657
 658test_debug 'git log --graph --decorate --oneline --all'
 659
 660test_expect_success 'merge --no-ff --no-commit && commit' '
 661        git reset --hard c0 &&
 662        git merge --no-ff --no-commit c1 &&
 663        EDITOR=: git commit &&
 664        verify_parents $c0 $c1
 665'
 666
 667test_debug 'git log --graph --decorate --oneline --all'
 668
 669test_expect_success 'amending no-ff merge commit' '
 670        EDITOR=: git commit --amend &&
 671        verify_parents $c0 $c1
 672'
 673
 674test_debug 'git log --graph --decorate --oneline --all'
 675
 676cat >editor <<\EOF
 677#!/bin/sh
 678# Add a new message string that was not in the template
 679(
 680        echo "Merge work done on the side branch c1"
 681        echo
 682        cat "$1"
 683) >"$1.tmp" && mv "$1.tmp" "$1"
 684# strip comments and blank lines from end of message
 685sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected
 686EOF
 687chmod 755 editor
 688
 689test_expect_success 'merge --no-ff --edit' '
 690        git reset --hard c0 &&
 691        EDITOR=./editor git merge --no-ff --edit c1 &&
 692        verify_parents $c0 $c1 &&
 693        git cat-file commit HEAD >raw &&
 694        grep "work done on the side branch" raw &&
 695        sed "1,/^$/d" >actual raw &&
 696        test_cmp expected actual
 697'
 698
 699test_expect_success 'merge annotated/signed tag w/o tracking' '
 700        test_when_finished "rm -rf dst; git tag -d anno1" &&
 701        git tag -a -m "anno c1" anno1 c1 &&
 702        git init dst &&
 703        git rev-parse c1 >dst/expect &&
 704        (
 705                # c0 fast-forwards to c1 but because this repository
 706                # is not a "downstream" whose refs/tags follows along
 707                # tag from the "upstream", this pull defaults to --no-ff
 708                cd dst &&
 709                git pull .. c0 &&
 710                git pull .. anno1 &&
 711                git rev-parse HEAD^2 >actual &&
 712                test_cmp expect actual
 713        )
 714'
 715
 716test_expect_success 'merge annotated/signed tag w/ tracking' '
 717        test_when_finished "rm -rf dst; git tag -d anno1" &&
 718        git tag -a -m "anno c1" anno1 c1 &&
 719        git init dst &&
 720        git rev-parse c1 >dst/expect &&
 721        (
 722                # c0 fast-forwards to c1 and because this repository
 723                # is a "downstream" whose refs/tags follows along
 724                # tag from the "upstream", this pull defaults to --ff
 725                cd dst &&
 726                git remote add origin .. &&
 727                git pull origin c0 &&
 728                git fetch origin &&
 729                git merge anno1 &&
 730                git rev-parse HEAD >actual &&
 731                test_cmp expect actual
 732        )
 733'
 734
 735test_expect_success GPG 'merge --ff-only tag' '
 736        git reset --hard c0 &&
 737        git commit --allow-empty -m "A newer commit" &&
 738        git tag -s -m "A newer commit" signed &&
 739        git reset --hard c0 &&
 740
 741        git merge --ff-only signed &&
 742        git rev-parse signed^0 >expect &&
 743        git rev-parse HEAD >actual &&
 744        test_cmp expect actual
 745'
 746
 747test_expect_success GPG 'merge --no-edit tag should skip editor' '
 748        git reset --hard c0 &&
 749        git commit --allow-empty -m "A newer commit" &&
 750        git tag -f -s -m "A newer commit" signed &&
 751        git reset --hard c0 &&
 752
 753        EDITOR=false git merge --no-edit --no-ff signed &&
 754        git rev-parse signed^0 >expect &&
 755        git rev-parse HEAD^2 >actual &&
 756        test_cmp expect actual
 757'
 758
 759test_expect_success 'set up mod-256 conflict scenario' '
 760        # 256 near-identical stanzas...
 761        for i in $(test_seq 1 256); do
 762                for j in 1 2 3 4 5; do
 763                        echo $i-$j
 764                done
 765        done >file &&
 766        git add file &&
 767        git commit -m base &&
 768
 769        # one side changes the first line of each to "master"
 770        sed s/-1/-master/ file >tmp &&
 771        mv tmp file &&
 772        git commit -am master &&
 773
 774        # and the other to "side"; merging the two will
 775        # yield 256 separate conflicts
 776        git checkout -b side HEAD^ &&
 777        sed s/-1/-side/ file >tmp &&
 778        mv tmp file &&
 779        git commit -am side
 780'
 781
 782test_expect_success 'merge detects mod-256 conflicts (recursive)' '
 783        git reset --hard &&
 784        test_must_fail git merge -s recursive master
 785'
 786
 787test_expect_success 'merge detects mod-256 conflicts (resolve)' '
 788        git reset --hard &&
 789        test_must_fail git merge -s resolve master
 790'
 791
 792test_expect_success 'merge nothing into void' '
 793        git init void &&
 794        (
 795                cd void &&
 796                git remote add up .. &&
 797                git fetch up &&
 798                test_must_fail git merge FETCH_HEAD
 799        )
 800'
 801
 802test_expect_success 'merge can be completed with --continue' '
 803        git reset --hard c0 &&
 804        git merge --no-ff --no-commit c1 &&
 805        git merge --continue &&
 806        verify_parents $c0 $c1
 807'
 808
 809write_script .git/FAKE_EDITOR <<EOF
 810# kill -TERM command added below.
 811EOF
 812
 813test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
 814        git reset --hard c0 &&
 815        ! "$SHELL_PATH" -c '\''
 816          echo kill -TERM $$ >>.git/FAKE_EDITOR
 817          GIT_EDITOR=.git/FAKE_EDITOR
 818          export GIT_EDITOR
 819          exec git merge --no-ff --edit c1'\'' &&
 820        git merge --continue &&
 821        verify_parents $c0 $c1
 822'
 823
 824test_done