t / t7600-merge.shon commit git-quiltimport: add --keep-non-patch option (1eadaa3)
   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        {
 237                cat <<-EOF
 238                Squashed commit of the following:
 239
 240                $(git show -s c7)
 241
 242                # Conflicts:
 243                #       file
 244                EOF
 245        } >expect &&
 246        git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
 247        test_cmp expect actual
 248'
 249
 250test_debug 'git log --graph --decorate --oneline --all'
 251
 252test_expect_success 'merge c1 with c2 and c3' '
 253        git reset --hard c1 &&
 254        test_tick &&
 255        git merge c2 c3 &&
 256        verify_merge file result.1-5-9 msg.1-5-9 &&
 257        verify_parents $c1 $c2 $c3
 258'
 259
 260test_debug 'git log --graph --decorate --oneline --all'
 261
 262test_expect_success 'merges with --ff-only' '
 263        git reset --hard c1 &&
 264        test_tick &&
 265        test_must_fail git merge --ff-only c2 &&
 266        test_must_fail git merge --ff-only c3 &&
 267        test_must_fail git merge --ff-only c2 c3 &&
 268        git reset --hard c0 &&
 269        git merge c3 &&
 270        verify_head $c3
 271'
 272
 273test_expect_success 'merges with merge.ff=only' '
 274        git reset --hard c1 &&
 275        test_tick &&
 276        test_config merge.ff "only" &&
 277        test_must_fail git merge c2 &&
 278        test_must_fail git merge c3 &&
 279        test_must_fail git merge c2 c3 &&
 280        git reset --hard c0 &&
 281        git merge c3 &&
 282        verify_head $c3
 283'
 284
 285test_expect_success 'merge c0 with c1 (no-commit)' '
 286        git reset --hard c0 &&
 287        git merge --no-commit c1 &&
 288        verify_merge file result.1 &&
 289        verify_head $c1
 290'
 291
 292test_debug 'git log --graph --decorate --oneline --all'
 293
 294test_expect_success 'merge c1 with c2 (no-commit)' '
 295        git reset --hard c1 &&
 296        git merge --no-commit c2 &&
 297        verify_merge file result.1-5 &&
 298        verify_head $c1 &&
 299        verify_mergeheads $c2
 300'
 301
 302test_debug 'git log --graph --decorate --oneline --all'
 303
 304test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
 305        git reset --hard c1 &&
 306        git merge --no-commit c2 c3 &&
 307        verify_merge file result.1-5-9 &&
 308        verify_head $c1 &&
 309        verify_mergeheads $c2 $c3
 310'
 311
 312test_debug 'git log --graph --decorate --oneline --all'
 313
 314test_expect_success 'merge c0 with c1 (squash)' '
 315        git reset --hard c0 &&
 316        git merge --squash c1 &&
 317        verify_merge file result.1 &&
 318        verify_head $c0 &&
 319        verify_no_mergehead &&
 320        test_cmp squash.1 .git/SQUASH_MSG
 321'
 322
 323test_debug 'git log --graph --decorate --oneline --all'
 324
 325test_expect_success 'merge c0 with c1 (squash, ff-only)' '
 326        git reset --hard c0 &&
 327        git merge --squash --ff-only c1 &&
 328        verify_merge file result.1 &&
 329        verify_head $c0 &&
 330        verify_no_mergehead &&
 331        test_cmp squash.1 .git/SQUASH_MSG
 332'
 333
 334test_debug 'git log --graph --decorate --oneline --all'
 335
 336test_expect_success 'merge c1 with c2 (squash)' '
 337        git reset --hard c1 &&
 338        git merge --squash c2 &&
 339        verify_merge file result.1-5 &&
 340        verify_head $c1 &&
 341        verify_no_mergehead &&
 342        test_cmp squash.1-5 .git/SQUASH_MSG
 343'
 344
 345test_debug 'git log --graph --decorate --oneline --all'
 346
 347test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
 348        git reset --hard c1 &&
 349        test_must_fail git merge --squash --ff-only c2
 350'
 351
 352test_debug 'git log --graph --decorate --oneline --all'
 353
 354test_expect_success 'merge c1 with c2 and c3 (squash)' '
 355        git reset --hard c1 &&
 356        git merge --squash c2 c3 &&
 357        verify_merge file result.1-5-9 &&
 358        verify_head $c1 &&
 359        verify_no_mergehead &&
 360        test_cmp squash.1-5-9 .git/SQUASH_MSG
 361'
 362
 363test_debug 'git log --graph --decorate --oneline --all'
 364
 365test_expect_success 'merge c1 with c2 (no-commit in config)' '
 366        git reset --hard c1 &&
 367        test_config branch.master.mergeoptions "--no-commit" &&
 368        git merge c2 &&
 369        verify_merge file result.1-5 &&
 370        verify_head $c1 &&
 371        verify_mergeheads $c2
 372'
 373
 374test_debug 'git log --graph --decorate --oneline --all'
 375
 376test_expect_success 'merge c1 with c2 (log in config)' '
 377        git reset --hard c1 &&
 378        git merge --log c2 &&
 379        git show -s --pretty=tformat:%s%n%b >expect &&
 380
 381        test_config branch.master.mergeoptions "--log" &&
 382        git reset --hard c1 &&
 383        git merge c2 &&
 384        git show -s --pretty=tformat:%s%n%b >actual &&
 385
 386        test_cmp expect actual
 387'
 388
 389test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
 390        git reset --hard c1 &&
 391        git merge c2 &&
 392        git show -s --pretty=tformat:%s%n%b >expect &&
 393
 394        test_config branch.master.mergeoptions "--no-log" &&
 395        test_config merge.log "true" &&
 396        git reset --hard c1 &&
 397        git merge c2 &&
 398        git show -s --pretty=tformat:%s%n%b >actual &&
 399
 400        test_cmp expect actual
 401'
 402
 403test_expect_success 'merge c1 with c2 (squash in config)' '
 404        git reset --hard c1 &&
 405        test_config branch.master.mergeoptions "--squash" &&
 406        git merge c2 &&
 407        verify_merge file result.1-5 &&
 408        verify_head $c1 &&
 409        verify_no_mergehead &&
 410        test_cmp squash.1-5 .git/SQUASH_MSG
 411'
 412
 413test_debug 'git log --graph --decorate --oneline --all'
 414
 415test_expect_success 'override config option -n with --summary' '
 416        git reset --hard c1 &&
 417        test_config branch.master.mergeoptions "-n" &&
 418        test_tick &&
 419        git merge --summary c2 >diffstat.txt &&
 420        verify_merge file result.1-5 msg.1-5 &&
 421        verify_parents $c1 $c2 &&
 422        if ! grep "^ file |  *2 +-$" diffstat.txt
 423        then
 424                echo "[OOPS] diffstat was not generated with --summary"
 425                false
 426        fi
 427'
 428
 429test_expect_success 'override config option -n with --stat' '
 430        git reset --hard c1 &&
 431        test_config branch.master.mergeoptions "-n" &&
 432        test_tick &&
 433        git merge --stat c2 >diffstat.txt &&
 434        verify_merge file result.1-5 msg.1-5 &&
 435        verify_parents $c1 $c2 &&
 436        if ! grep "^ file |  *2 +-$" diffstat.txt
 437        then
 438                echo "[OOPS] diffstat was not generated with --stat"
 439                false
 440        fi
 441'
 442
 443test_debug 'git log --graph --decorate --oneline --all'
 444
 445test_expect_success 'override config option --stat' '
 446        git reset --hard c1 &&
 447        test_config branch.master.mergeoptions "--stat" &&
 448        test_tick &&
 449        git merge -n c2 >diffstat.txt &&
 450        verify_merge file result.1-5 msg.1-5 &&
 451        verify_parents $c1 $c2 &&
 452        if grep "^ file |  *2 +-$" diffstat.txt
 453        then
 454                echo "[OOPS] diffstat was generated"
 455                false
 456        fi
 457'
 458
 459test_debug 'git log --graph --decorate --oneline --all'
 460
 461test_expect_success 'merge c1 with c2 (override --no-commit)' '
 462        git reset --hard c1 &&
 463        test_config branch.master.mergeoptions "--no-commit" &&
 464        test_tick &&
 465        git merge --commit c2 &&
 466        verify_merge file result.1-5 msg.1-5 &&
 467        verify_parents $c1 $c2
 468'
 469
 470test_debug 'git log --graph --decorate --oneline --all'
 471
 472test_expect_success 'merge c1 with c2 (override --squash)' '
 473        git reset --hard c1 &&
 474        test_config branch.master.mergeoptions "--squash" &&
 475        test_tick &&
 476        git merge --no-squash c2 &&
 477        verify_merge file result.1-5 msg.1-5 &&
 478        verify_parents $c1 $c2
 479'
 480
 481test_debug 'git log --graph --decorate --oneline --all'
 482
 483test_expect_success 'merge c0 with c1 (no-ff)' '
 484        git reset --hard c0 &&
 485        test_tick &&
 486        git merge --no-ff c1 &&
 487        verify_merge file result.1 &&
 488        verify_parents $c0 $c1
 489'
 490
 491test_debug 'git log --graph --decorate --oneline --all'
 492
 493test_expect_success 'merge c0 with c1 (merge.ff=false)' '
 494        git reset --hard c0 &&
 495        test_config merge.ff "false" &&
 496        test_tick &&
 497        git merge c1 &&
 498        verify_merge file result.1 &&
 499        verify_parents $c0 $c1
 500'
 501test_debug 'git log --graph --decorate --oneline --all'
 502
 503test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
 504        git reset --hard c0 &&
 505        test_config branch.master.mergeoptions "--ff" &&
 506        test_config merge.ff "false" &&
 507        test_tick &&
 508        git merge c1 &&
 509        verify_merge file result.1 &&
 510        verify_parents "$c0"
 511'
 512
 513test_expect_success 'tolerate unknown values for merge.ff' '
 514        git reset --hard c0 &&
 515        test_config merge.ff "something-new" &&
 516        test_tick &&
 517        git merge c1 2>message &&
 518        verify_head "$c1" &&
 519        test_must_be_empty message
 520'
 521
 522test_expect_success 'combining --squash and --no-ff is refused' '
 523        git reset --hard c0 &&
 524        test_must_fail git merge --squash --no-ff c1 &&
 525        test_must_fail git merge --no-ff --squash c1
 526'
 527
 528test_expect_success 'option --ff-only overwrites --no-ff' '
 529        git merge --no-ff --ff-only c1 &&
 530        test_must_fail git merge --no-ff --ff-only c2
 531'
 532
 533test_expect_success 'option --no-ff overrides merge.ff=only config' '
 534        git reset --hard c0 &&
 535        test_config merge.ff only &&
 536        git merge --no-ff c1
 537'
 538
 539test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
 540        git reset --hard c0 &&
 541        test_config branch.master.mergeoptions "--no-ff" &&
 542        git merge --ff c1 &&
 543        verify_merge file result.1 &&
 544        verify_head $c1
 545'
 546
 547test_expect_success 'merge log message' '
 548        git reset --hard c0 &&
 549        git merge --no-log c2 &&
 550        git show -s --pretty=format:%b HEAD >msg.act &&
 551        test_must_be_empty msg.act &&
 552
 553        git reset --hard c0 &&
 554        test_config branch.master.mergeoptions "--no-ff" &&
 555        git merge --no-log c2 &&
 556        git show -s --pretty=format:%b HEAD >msg.act &&
 557        test_must_be_empty msg.act &&
 558
 559        git merge --log c3 &&
 560        git show -s --pretty=format:%b HEAD >msg.act &&
 561        test_cmp msg.log msg.act &&
 562
 563        git reset --hard HEAD^ &&
 564        test_config merge.log "yes" &&
 565        git merge c3 &&
 566        git show -s --pretty=format:%b HEAD >msg.act &&
 567        test_cmp msg.log msg.act
 568'
 569
 570test_debug 'git log --graph --decorate --oneline --all'
 571
 572test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 573       git reset --hard c1 &&
 574       test_tick &&
 575       git merge c0 c2 c0 c1 &&
 576       verify_merge file result.1-5 &&
 577       verify_parents $c1 $c2
 578'
 579
 580test_debug 'git log --graph --decorate --oneline --all'
 581
 582test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 583       git reset --hard c1 &&
 584       test_tick &&
 585       git merge c0 c2 c0 c1 &&
 586       verify_merge file result.1-5 &&
 587       verify_parents $c1 $c2
 588'
 589
 590test_debug 'git log --graph --decorate --oneline --all'
 591
 592test_expect_success 'merge c1 with c1 and c2' '
 593       git reset --hard c1 &&
 594       test_tick &&
 595       git merge c1 c2 &&
 596       verify_merge file result.1-5 &&
 597       verify_parents $c1 $c2
 598'
 599
 600test_debug 'git log --graph --decorate --oneline --all'
 601
 602test_expect_success 'merge fast-forward in a dirty tree' '
 603       git reset --hard c0 &&
 604       mv file file1 &&
 605       cat file1 >file &&
 606       rm -f file1 &&
 607       git merge c2
 608'
 609
 610test_debug 'git log --graph --decorate --oneline --all'
 611
 612test_expect_success 'in-index merge' '
 613        git reset --hard c0 &&
 614        git merge --no-ff -s resolve c1 >out &&
 615        test_i18ngrep "Wonderful." out &&
 616        verify_parents $c0 $c1
 617'
 618
 619test_debug 'git log --graph --decorate --oneline --all'
 620
 621test_expect_success 'refresh the index before merging' '
 622        git reset --hard c1 &&
 623        cp file file.n && mv -f file.n file &&
 624        git merge c3
 625'
 626
 627cat >expected.branch <<\EOF
 628Merge branch 'c5-branch' (early part)
 629EOF
 630cat >expected.tag <<\EOF
 631Merge commit 'c5~1'
 632EOF
 633
 634test_expect_success 'merge early part of c2' '
 635        git reset --hard c3 &&
 636        echo c4 >c4.c &&
 637        git add c4.c &&
 638        git commit -m c4 &&
 639        git tag c4 &&
 640        echo c5 >c5.c &&
 641        git add c5.c &&
 642        git commit -m c5 &&
 643        git tag c5 &&
 644        git reset --hard c3 &&
 645        echo c6 >c6.c &&
 646        git add c6.c &&
 647        git commit -m c6 &&
 648        git tag c6 &&
 649        git branch -f c5-branch c5 &&
 650        git merge c5-branch~1 &&
 651        git show -s --pretty=tformat:%s HEAD >actual.branch &&
 652        git reset --keep HEAD^ &&
 653        git merge c5~1 &&
 654        git show -s --pretty=tformat:%s HEAD >actual.tag &&
 655        test_cmp expected.branch actual.branch &&
 656        test_cmp expected.tag actual.tag
 657'
 658
 659test_debug 'git log --graph --decorate --oneline --all'
 660
 661test_expect_success 'merge --no-ff --no-commit && commit' '
 662        git reset --hard c0 &&
 663        git merge --no-ff --no-commit c1 &&
 664        EDITOR=: git commit &&
 665        verify_parents $c0 $c1
 666'
 667
 668test_debug 'git log --graph --decorate --oneline --all'
 669
 670test_expect_success 'amending no-ff merge commit' '
 671        EDITOR=: git commit --amend &&
 672        verify_parents $c0 $c1
 673'
 674
 675test_debug 'git log --graph --decorate --oneline --all'
 676
 677cat >editor <<\EOF
 678#!/bin/sh
 679# Add a new message string that was not in the template
 680(
 681        echo "Merge work done on the side branch c1"
 682        echo
 683        cat <"$1"
 684) >"$1.tmp" && mv "$1.tmp" "$1"
 685# strip comments and blank lines from end of message
 686sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected
 687EOF
 688chmod 755 editor
 689
 690test_expect_success 'merge --no-ff --edit' '
 691        git reset --hard c0 &&
 692        EDITOR=./editor git merge --no-ff --edit c1 &&
 693        verify_parents $c0 $c1 &&
 694        git cat-file commit HEAD >raw &&
 695        grep "work done on the side branch" raw &&
 696        sed "1,/^$/d" >actual raw &&
 697        test_cmp expected actual
 698'
 699
 700test_expect_success 'merge annotated/signed tag w/o tracking' '
 701        test_when_finished "rm -rf dst; git tag -d anno1" &&
 702        git tag -a -m "anno c1" anno1 c1 &&
 703        git init dst &&
 704        git rev-parse c1 >dst/expect &&
 705        (
 706                # c0 fast-forwards to c1 but because this repository
 707                # is not a "downstream" whose refs/tags follows along
 708                # tag from the "upstream", this pull defaults to --no-ff
 709                cd dst &&
 710                git pull .. c0 &&
 711                git pull .. anno1 &&
 712                git rev-parse HEAD^2 >actual &&
 713                test_cmp expect actual
 714        )
 715'
 716
 717test_expect_success 'merge annotated/signed tag w/ tracking' '
 718        test_when_finished "rm -rf dst; git tag -d anno1" &&
 719        git tag -a -m "anno c1" anno1 c1 &&
 720        git init dst &&
 721        git rev-parse c1 >dst/expect &&
 722        (
 723                # c0 fast-forwards to c1 and because this repository
 724                # is a "downstream" whose refs/tags follows along
 725                # tag from the "upstream", this pull defaults to --ff
 726                cd dst &&
 727                git remote add origin .. &&
 728                git pull origin c0 &&
 729                git fetch origin &&
 730                git merge anno1 &&
 731                git rev-parse HEAD >actual &&
 732                test_cmp expect actual
 733        )
 734'
 735
 736test_expect_success GPG 'merge --ff-only tag' '
 737        git reset --hard c0 &&
 738        git commit --allow-empty -m "A newer commit" &&
 739        git tag -s -m "A newer commit" signed &&
 740        git reset --hard c0 &&
 741
 742        git merge --ff-only signed &&
 743        git rev-parse signed^0 >expect &&
 744        git rev-parse HEAD >actual &&
 745        test_cmp expect actual
 746'
 747
 748test_expect_success GPG 'merge --no-edit tag should skip editor' '
 749        git reset --hard c0 &&
 750        git commit --allow-empty -m "A newer commit" &&
 751        git tag -f -s -m "A newer commit" signed &&
 752        git reset --hard c0 &&
 753
 754        EDITOR=false git merge --no-edit --no-ff signed &&
 755        git rev-parse signed^0 >expect &&
 756        git rev-parse HEAD^2 >actual &&
 757        test_cmp expect actual
 758'
 759
 760test_expect_success 'set up mod-256 conflict scenario' '
 761        # 256 near-identical stanzas...
 762        for i in $(test_seq 1 256); do
 763                for j in 1 2 3 4 5; do
 764                        echo $i-$j
 765                done
 766        done >file &&
 767        git add file &&
 768        git commit -m base &&
 769
 770        # one side changes the first line of each to "master"
 771        sed s/-1/-master/ <file >tmp &&
 772        mv tmp file &&
 773        git commit -am master &&
 774
 775        # and the other to "side"; merging the two will
 776        # yield 256 separate conflicts
 777        git checkout -b side HEAD^ &&
 778        sed s/-1/-side/ <file >tmp &&
 779        mv tmp file &&
 780        git commit -am side
 781'
 782
 783test_expect_success 'merge detects mod-256 conflicts (recursive)' '
 784        git reset --hard &&
 785        test_must_fail git merge -s recursive master
 786'
 787
 788test_expect_success 'merge detects mod-256 conflicts (resolve)' '
 789        git reset --hard &&
 790        test_must_fail git merge -s resolve master
 791'
 792
 793test_expect_success 'merge nothing into void' '
 794        git init void &&
 795        (
 796                cd void &&
 797                git remote add up .. &&
 798                git fetch up &&
 799                test_must_fail git merge FETCH_HEAD
 800        )
 801'
 802
 803test_expect_success 'merge can be completed with --continue' '
 804        git reset --hard c0 &&
 805        git merge --no-ff --no-commit c1 &&
 806        git merge --continue &&
 807        verify_parents $c0 $c1
 808'
 809
 810write_script .git/FAKE_EDITOR <<EOF
 811# kill -TERM command added below.
 812EOF
 813
 814test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
 815        git reset --hard c0 &&
 816        ! "$SHELL_PATH" -c '\''
 817          echo kill -TERM $$ >> .git/FAKE_EDITOR
 818          GIT_EDITOR=.git/FAKE_EDITOR
 819          export GIT_EDITOR
 820          exec git merge --no-ff --edit c1'\'' &&
 821        git merge --continue &&
 822        verify_parents $c0 $c1
 823'
 824
 825test_done