t / t7600-merge.shon commit merge: refuse --commit with --squash (1d14d0c)
   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 'combining --squash and --commit is refused' '
 529        git reset --hard c0 &&
 530        test_must_fail git merge --squash --commit c1 &&
 531        test_must_fail git merge --commit --squash c1
 532'
 533
 534test_expect_success 'option --ff-only overwrites --no-ff' '
 535        git merge --no-ff --ff-only c1 &&
 536        test_must_fail git merge --no-ff --ff-only c2
 537'
 538
 539test_expect_success 'option --no-ff overrides merge.ff=only config' '
 540        git reset --hard c0 &&
 541        test_config merge.ff only &&
 542        git merge --no-ff c1
 543'
 544
 545test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
 546        git reset --hard c0 &&
 547        test_config branch.master.mergeoptions "--no-ff" &&
 548        git merge --ff c1 &&
 549        verify_merge file result.1 &&
 550        verify_head $c1
 551'
 552
 553test_expect_success 'merge log message' '
 554        git reset --hard c0 &&
 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 reset --hard c0 &&
 560        test_config branch.master.mergeoptions "--no-ff" &&
 561        git merge --no-log c2 &&
 562        git show -s --pretty=format:%b HEAD >msg.act &&
 563        test_must_be_empty msg.act &&
 564
 565        git merge --log c3 &&
 566        git show -s --pretty=format:%b HEAD >msg.act &&
 567        test_cmp msg.log msg.act &&
 568
 569        git reset --hard HEAD^ &&
 570        test_config merge.log "yes" &&
 571        git merge c3 &&
 572        git show -s --pretty=format:%b HEAD >msg.act &&
 573        test_cmp msg.log msg.act
 574'
 575
 576test_debug 'git log --graph --decorate --oneline --all'
 577
 578test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 579       git reset --hard c1 &&
 580       test_tick &&
 581       git merge c0 c2 c0 c1 &&
 582       verify_merge file result.1-5 &&
 583       verify_parents $c1 $c2
 584'
 585
 586test_debug 'git log --graph --decorate --oneline --all'
 587
 588test_expect_success 'merge c1 with c0, c2, c0, and c1' '
 589       git reset --hard c1 &&
 590       test_tick &&
 591       git merge c0 c2 c0 c1 &&
 592       verify_merge file result.1-5 &&
 593       verify_parents $c1 $c2
 594'
 595
 596test_debug 'git log --graph --decorate --oneline --all'
 597
 598test_expect_success 'merge c1 with c1 and c2' '
 599       git reset --hard c1 &&
 600       test_tick &&
 601       git merge c1 c2 &&
 602       verify_merge file result.1-5 &&
 603       verify_parents $c1 $c2
 604'
 605
 606test_debug 'git log --graph --decorate --oneline --all'
 607
 608test_expect_success 'merge fast-forward in a dirty tree' '
 609       git reset --hard c0 &&
 610       mv file file1 &&
 611       cat file1 >file &&
 612       rm -f file1 &&
 613       git merge c2
 614'
 615
 616test_debug 'git log --graph --decorate --oneline --all'
 617
 618test_expect_success 'in-index merge' '
 619        git reset --hard c0 &&
 620        git merge --no-ff -s resolve c1 >out &&
 621        test_i18ngrep "Wonderful." out &&
 622        verify_parents $c0 $c1
 623'
 624
 625test_debug 'git log --graph --decorate --oneline --all'
 626
 627test_expect_success 'refresh the index before merging' '
 628        git reset --hard c1 &&
 629        cp file file.n && mv -f file.n file &&
 630        git merge c3
 631'
 632
 633cat >expected.branch <<\EOF
 634Merge branch 'c5-branch' (early part)
 635EOF
 636cat >expected.tag <<\EOF
 637Merge commit 'c5~1'
 638EOF
 639
 640test_expect_success 'merge early part of c2' '
 641        git reset --hard c3 &&
 642        echo c4 >c4.c &&
 643        git add c4.c &&
 644        git commit -m c4 &&
 645        git tag c4 &&
 646        echo c5 >c5.c &&
 647        git add c5.c &&
 648        git commit -m c5 &&
 649        git tag c5 &&
 650        git reset --hard c3 &&
 651        echo c6 >c6.c &&
 652        git add c6.c &&
 653        git commit -m c6 &&
 654        git tag c6 &&
 655        git branch -f c5-branch c5 &&
 656        git merge c5-branch~1 &&
 657        git show -s --pretty=tformat:%s HEAD >actual.branch &&
 658        git reset --keep HEAD^ &&
 659        git merge c5~1 &&
 660        git show -s --pretty=tformat:%s HEAD >actual.tag &&
 661        test_cmp expected.branch actual.branch &&
 662        test_cmp expected.tag actual.tag
 663'
 664
 665test_debug 'git log --graph --decorate --oneline --all'
 666
 667test_expect_success 'merge --no-ff --no-commit && commit' '
 668        git reset --hard c0 &&
 669        git merge --no-ff --no-commit c1 &&
 670        EDITOR=: git commit &&
 671        verify_parents $c0 $c1
 672'
 673
 674test_debug 'git log --graph --decorate --oneline --all'
 675
 676test_expect_success 'amending no-ff merge commit' '
 677        EDITOR=: git commit --amend &&
 678        verify_parents $c0 $c1
 679'
 680
 681test_debug 'git log --graph --decorate --oneline --all'
 682
 683cat >editor <<\EOF
 684#!/bin/sh
 685# Add a new message string that was not in the template
 686(
 687        echo "Merge work done on the side branch c1"
 688        echo
 689        cat <"$1"
 690) >"$1.tmp" && mv "$1.tmp" "$1"
 691# strip comments and blank lines from end of message
 692sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected
 693EOF
 694chmod 755 editor
 695
 696test_expect_success 'merge --no-ff --edit' '
 697        git reset --hard c0 &&
 698        EDITOR=./editor git merge --no-ff --edit c1 &&
 699        verify_parents $c0 $c1 &&
 700        git cat-file commit HEAD >raw &&
 701        grep "work done on the side branch" raw &&
 702        sed "1,/^$/d" >actual raw &&
 703        test_cmp expected actual
 704'
 705
 706test_expect_success 'merge annotated/signed tag w/o tracking' '
 707        test_when_finished "rm -rf dst; git tag -d anno1" &&
 708        git tag -a -m "anno c1" anno1 c1 &&
 709        git init dst &&
 710        git rev-parse c1 >dst/expect &&
 711        (
 712                # c0 fast-forwards to c1 but because this repository
 713                # is not a "downstream" whose refs/tags follows along
 714                # tag from the "upstream", this pull defaults to --no-ff
 715                cd dst &&
 716                git pull .. c0 &&
 717                git pull .. anno1 &&
 718                git rev-parse HEAD^2 >actual &&
 719                test_cmp expect actual
 720        )
 721'
 722
 723test_expect_success 'merge annotated/signed tag w/ tracking' '
 724        test_when_finished "rm -rf dst; git tag -d anno1" &&
 725        git tag -a -m "anno c1" anno1 c1 &&
 726        git init dst &&
 727        git rev-parse c1 >dst/expect &&
 728        (
 729                # c0 fast-forwards to c1 and because this repository
 730                # is a "downstream" whose refs/tags follows along
 731                # tag from the "upstream", this pull defaults to --ff
 732                cd dst &&
 733                git remote add origin .. &&
 734                git pull origin c0 &&
 735                git fetch origin &&
 736                git merge anno1 &&
 737                git rev-parse HEAD >actual &&
 738                test_cmp expect actual
 739        )
 740'
 741
 742test_expect_success GPG 'merge --ff-only tag' '
 743        git reset --hard c0 &&
 744        git commit --allow-empty -m "A newer commit" &&
 745        git tag -s -m "A newer commit" signed &&
 746        git reset --hard c0 &&
 747
 748        git merge --ff-only signed &&
 749        git rev-parse signed^0 >expect &&
 750        git rev-parse HEAD >actual &&
 751        test_cmp expect actual
 752'
 753
 754test_expect_success GPG 'merge --no-edit tag should skip editor' '
 755        git reset --hard c0 &&
 756        git commit --allow-empty -m "A newer commit" &&
 757        git tag -f -s -m "A newer commit" signed &&
 758        git reset --hard c0 &&
 759
 760        EDITOR=false git merge --no-edit --no-ff signed &&
 761        git rev-parse signed^0 >expect &&
 762        git rev-parse HEAD^2 >actual &&
 763        test_cmp expect actual
 764'
 765
 766test_expect_success 'set up mod-256 conflict scenario' '
 767        # 256 near-identical stanzas...
 768        for i in $(test_seq 1 256); do
 769                for j in 1 2 3 4 5; do
 770                        echo $i-$j
 771                done
 772        done >file &&
 773        git add file &&
 774        git commit -m base &&
 775
 776        # one side changes the first line of each to "master"
 777        sed s/-1/-master/ <file >tmp &&
 778        mv tmp file &&
 779        git commit -am master &&
 780
 781        # and the other to "side"; merging the two will
 782        # yield 256 separate conflicts
 783        git checkout -b side HEAD^ &&
 784        sed s/-1/-side/ <file >tmp &&
 785        mv tmp file &&
 786        git commit -am side
 787'
 788
 789test_expect_success 'merge detects mod-256 conflicts (recursive)' '
 790        git reset --hard &&
 791        test_must_fail git merge -s recursive master
 792'
 793
 794test_expect_success 'merge detects mod-256 conflicts (resolve)' '
 795        git reset --hard &&
 796        test_must_fail git merge -s resolve master
 797'
 798
 799test_expect_success 'merge nothing into void' '
 800        git init void &&
 801        (
 802                cd void &&
 803                git remote add up .. &&
 804                git fetch up &&
 805                test_must_fail git merge FETCH_HEAD
 806        )
 807'
 808
 809test_expect_success 'merge can be completed with --continue' '
 810        git reset --hard c0 &&
 811        git merge --no-ff --no-commit c1 &&
 812        git merge --continue &&
 813        verify_parents $c0 $c1
 814'
 815
 816write_script .git/FAKE_EDITOR <<EOF
 817# kill -TERM command added below.
 818EOF
 819
 820test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
 821        git reset --hard c0 &&
 822        ! "$SHELL_PATH" -c '\''
 823          echo kill -TERM $$ >> .git/FAKE_EDITOR
 824          GIT_EDITOR=.git/FAKE_EDITOR
 825          export GIT_EDITOR
 826          exec git merge --no-ff --edit c1'\'' &&
 827        git merge --continue &&
 828        verify_parents $c0 $c1
 829'
 830
 831test_done