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