t / t7610-mergetool.shon commit t7610: don't rely on state from previous test (b696ac9)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Charles Bailey
   4#
   5
   6test_description='git mergetool
   7
   8Testing basic merge tool invocation'
   9
  10. ./test-lib.sh
  11
  12# All the mergetool test work by checking out a temporary branch based
  13# off 'branch1' and then merging in master and checking the results of
  14# running mergetool
  15
  16test_expect_success 'setup' '
  17        test_config rerere.enabled true &&
  18        echo master >file1 &&
  19        echo master spaced >"spaced name" &&
  20        echo master file11 >file11 &&
  21        echo master file12 >file12 &&
  22        echo master file13 >file13 &&
  23        echo master file14 >file14 &&
  24        mkdir subdir &&
  25        echo master sub >subdir/file3 &&
  26        test_create_repo submod &&
  27        (
  28                cd submod &&
  29                : >foo &&
  30                git add foo &&
  31                git commit -m "Add foo"
  32        ) &&
  33        git submodule add git://example.com/submod submod &&
  34        git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
  35        git commit -m "add initial versions" &&
  36
  37        git checkout -b branch1 master &&
  38        git submodule update -N &&
  39        echo branch1 change >file1 &&
  40        echo branch1 newfile >file2 &&
  41        echo branch1 spaced >"spaced name" &&
  42        echo branch1 both added >both &&
  43        echo branch1 change file11 >file11 &&
  44        echo branch1 change file13 >file13 &&
  45        echo branch1 sub >subdir/file3 &&
  46        (
  47                cd submod &&
  48                echo branch1 submodule >bar &&
  49                git add bar &&
  50                git commit -m "Add bar on branch1" &&
  51                git checkout -b submod-branch1
  52        ) &&
  53        git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
  54        git add both &&
  55        git rm file12 &&
  56        git commit -m "branch1 changes" &&
  57
  58        git checkout -b delete-base branch1 &&
  59        mkdir -p a/a &&
  60        (echo one; echo two; echo 3; echo 4) >a/a/file.txt &&
  61        git add a/a/file.txt &&
  62        git commit -m"base file" &&
  63        git checkout -b move-to-b delete-base &&
  64        mkdir -p b/b &&
  65        git mv a/a/file.txt b/b/file.txt &&
  66        (echo one; echo two; echo 4) >b/b/file.txt &&
  67        git commit -a -m"move to b" &&
  68        git checkout -b move-to-c delete-base &&
  69        mkdir -p c/c &&
  70        git mv a/a/file.txt c/c/file.txt &&
  71        (echo one; echo two; echo 3) >c/c/file.txt &&
  72        git commit -a -m"move to c" &&
  73
  74        git checkout -b stash1 master &&
  75        echo stash1 change file11 >file11 &&
  76        git add file11 &&
  77        git commit -m "stash1 changes" &&
  78
  79        git checkout -b stash2 master &&
  80        echo stash2 change file11 >file11 &&
  81        git add file11 &&
  82        git commit -m "stash2 changes" &&
  83
  84        git checkout master &&
  85        git submodule update -N &&
  86        echo master updated >file1 &&
  87        echo master new >file2 &&
  88        echo master updated spaced >"spaced name" &&
  89        echo master both added >both &&
  90        echo master updated file12 >file12 &&
  91        echo master updated file14 >file14 &&
  92        echo master new sub >subdir/file3 &&
  93        (
  94                cd submod &&
  95                echo master submodule >bar &&
  96                git add bar &&
  97                git commit -m "Add bar on master" &&
  98                git checkout -b submod-master
  99        ) &&
 100        git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
 101        git add both &&
 102        git rm file11 &&
 103        git commit -m "master updates" &&
 104
 105        git clean -fdx &&
 106        git checkout -b order-file-start master &&
 107        echo start >a &&
 108        echo start >b &&
 109        git add a b &&
 110        git commit -m start &&
 111        git checkout -b order-file-side1 order-file-start &&
 112        echo side1 >a &&
 113        echo side1 >b &&
 114        git add a b &&
 115        git commit -m side1 &&
 116        git checkout -b order-file-side2 order-file-start &&
 117        echo side2 >a &&
 118        echo side2 >b &&
 119        git add a b &&
 120        git commit -m side2 &&
 121
 122        git config merge.tool mytool &&
 123        git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
 124        git config mergetool.mytool.trustExitCode true &&
 125        git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
 126        git config mergetool.mybase.trustExitCode true
 127'
 128
 129test_expect_success 'custom mergetool' '
 130        git checkout -b test$test_count branch1 &&
 131        git submodule update -N &&
 132        test_must_fail git merge master >/dev/null 2>&1 &&
 133        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 134        ( yes "" | git mergetool file1 file1 ) &&
 135        ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
 136        ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
 137        ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
 138        ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
 139        ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
 140        test "$(cat file1)" = "master updated" &&
 141        test "$(cat file2)" = "master new" &&
 142        test "$(cat subdir/file3)" = "master new sub" &&
 143        test "$(cat submod/bar)" = "branch1 submodule" &&
 144        git commit -m "branch1 resolved with mergetool"
 145'
 146
 147test_expect_success 'mergetool crlf' '
 148        test_when_finished "git reset --hard" &&
 149        # This test_config line must go after the above reset line so that
 150        # core.autocrlf is unconfigured before reset runs.  (The
 151        # test_config command uses test_when_finished internally and
 152        # test_when_finished is LIFO.)
 153        test_config core.autocrlf true &&
 154        git checkout -b test$test_count branch1 &&
 155        test_must_fail git merge master >/dev/null 2>&1 &&
 156        ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
 157        ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
 158        ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) &&
 159        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 160        ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
 161        ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
 162        ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
 163        ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
 164        test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
 165        test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
 166        test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
 167        git submodule update -N &&
 168        test "$(cat submod/bar)" = "master submodule" &&
 169        git commit -m "branch1 resolved with mergetool - autocrlf"
 170'
 171
 172test_expect_success 'mergetool in subdir' '
 173        git checkout -b test$test_count branch1 &&
 174        git submodule update -N &&
 175        (
 176                cd subdir &&
 177                test_must_fail git merge master >/dev/null 2>&1 &&
 178                ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
 179                test "$(cat file3)" = "master new sub"
 180        )
 181'
 182
 183test_expect_success 'mergetool on file in parent dir' '
 184        git reset --hard &&
 185        git submodule update -N &&
 186        (
 187                cd subdir &&
 188                test_must_fail git merge master >/dev/null 2>&1 &&
 189                ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
 190                ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
 191                ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
 192                ( yes "" | git mergetool ../both >/dev/null 2>&1 ) &&
 193                ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
 194                ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
 195                ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
 196                test "$(cat ../file1)" = "master updated" &&
 197                test "$(cat ../file2)" = "master new" &&
 198                test "$(cat ../submod/bar)" = "branch1 submodule" &&
 199                git commit -m "branch1 resolved with mergetool - subdir"
 200        )
 201'
 202
 203test_expect_success 'mergetool skips autoresolved' '
 204        test_when_finished "git reset --hard" &&
 205        git checkout -b test$test_count branch1 &&
 206        git submodule update -N &&
 207        test_must_fail git merge master &&
 208        test -n "$(git ls-files -u)" &&
 209        ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
 210        ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
 211        ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
 212        output="$(git mergetool --no-prompt)" &&
 213        test "$output" = "No files need merging"
 214'
 215
 216test_expect_success 'mergetool merges all from subdir' '
 217        test_config rerere.enabled false &&
 218        (
 219                cd subdir &&
 220                test_must_fail git merge master &&
 221                ( yes "r" | git mergetool ../submod ) &&
 222                ( yes "d" "d" | git mergetool --no-prompt ) &&
 223                test "$(cat ../file1)" = "master updated" &&
 224                test "$(cat ../file2)" = "master new" &&
 225                test "$(cat file3)" = "master new sub" &&
 226                ( cd .. && git submodule update -N ) &&
 227                test "$(cat ../submod/bar)" = "master submodule" &&
 228                git commit -m "branch2 resolved by mergetool from subdir"
 229        )
 230'
 231
 232test_expect_success 'mergetool skips resolved paths when rerere is active' '
 233        test_when_finished "git reset --hard" &&
 234        test_config rerere.enabled true &&
 235        rm -rf .git/rr-cache &&
 236        git checkout -b test$test_count branch1 &&
 237        git submodule update -N &&
 238        test_must_fail git merge master >/dev/null 2>&1 &&
 239        ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) &&
 240        ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
 241        git submodule update -N &&
 242        output="$(yes "n" | git mergetool --no-prompt)" &&
 243        test "$output" = "No files need merging"
 244'
 245
 246test_expect_success 'conflicted stash sets up rerere'  '
 247        test_config rerere.enabled true &&
 248        git checkout stash1 &&
 249        echo "Conflicting stash content" >file11 &&
 250        git stash &&
 251
 252        git checkout --detach stash2 &&
 253        test_must_fail git stash apply &&
 254
 255        test -n "$(git ls-files -u)" &&
 256        conflicts="$(git rerere remaining)" &&
 257        test "$conflicts" = "file11" &&
 258        output="$(git mergetool --no-prompt)" &&
 259        test "$output" != "No files need merging" &&
 260
 261        git commit -am "save the stash resolution" &&
 262
 263        git reset --hard stash2 &&
 264        test_must_fail git stash apply &&
 265
 266        test -n "$(git ls-files -u)" &&
 267        conflicts="$(git rerere remaining)" &&
 268        test -z "$conflicts" &&
 269        output="$(git mergetool --no-prompt)" &&
 270        test "$output" = "No files need merging"
 271'
 272
 273test_expect_success 'mergetool takes partial path' '
 274        test_when_finished "git reset --hard" &&
 275        git reset --hard &&
 276        test_config rerere.enabled false &&
 277        git checkout -b test$test_count branch1 &&
 278        git submodule update -N &&
 279        test_must_fail git merge master &&
 280
 281        ( yes "" | git mergetool subdir ) &&
 282
 283        test "$(cat subdir/file3)" = "master new sub"
 284'
 285
 286test_expect_success 'mergetool delete/delete conflict' '
 287        test_when_finished "git reset --hard HEAD" &&
 288        git checkout move-to-c &&
 289        test_must_fail git merge move-to-b &&
 290        echo d | git mergetool a/a/file.txt &&
 291        ! test -f a/a/file.txt &&
 292        git reset --hard HEAD &&
 293        test_must_fail git merge move-to-b &&
 294        echo m | git mergetool a/a/file.txt &&
 295        test -f b/b/file.txt &&
 296        git reset --hard HEAD &&
 297        test_must_fail git merge move-to-b &&
 298        ! echo a | git mergetool a/a/file.txt &&
 299        ! test -f a/a/file.txt
 300'
 301
 302test_expect_success 'mergetool produces no errors when keepBackup is used' '
 303        test_when_finished "git reset --hard HEAD" &&
 304        test_config mergetool.keepBackup true &&
 305        test_must_fail git merge move-to-b &&
 306        : >expect &&
 307        echo d | git mergetool a/a/file.txt 2>actual &&
 308        test_cmp expect actual &&
 309        ! test -d a
 310'
 311
 312test_expect_success 'mergetool honors tempfile config for deleted files' '
 313        test_when_finished "git reset --hard HEAD" &&
 314        test_config mergetool.keepTemporaries false &&
 315        test_must_fail git merge move-to-b &&
 316        echo d | git mergetool a/a/file.txt &&
 317        ! test -d a
 318'
 319
 320test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
 321        test_when_finished "git reset --hard HEAD" &&
 322        test_when_finished "git clean -fdx" &&
 323        test_config mergetool.keepTemporaries true &&
 324        test_must_fail git merge move-to-b &&
 325        ! (echo a; echo n) | git mergetool a/a/file.txt &&
 326        test -d a/a &&
 327        cat >expect <<-\EOF &&
 328        file_BASE_.txt
 329        file_LOCAL_.txt
 330        file_REMOTE_.txt
 331        EOF
 332        ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
 333        test_cmp expect actual
 334'
 335
 336test_expect_success 'deleted vs modified submodule' '
 337        test_when_finished "git reset --hard HEAD" &&
 338        git checkout -b test$test_count branch1 &&
 339        git submodule update -N &&
 340        mv submod submod-movedaside &&
 341        git rm --cached submod &&
 342        git commit -m "Submodule deleted from branch" &&
 343        git checkout -b test$test_count.a test$test_count &&
 344        test_must_fail git merge master &&
 345        test -n "$(git ls-files -u)" &&
 346        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 347        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 348        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 349        ( yes "r" | git mergetool submod ) &&
 350        rmdir submod && mv submod-movedaside submod &&
 351        test "$(cat submod/bar)" = "branch1 submodule" &&
 352        git submodule update -N &&
 353        test "$(cat submod/bar)" = "master submodule" &&
 354        output="$(git mergetool --no-prompt)" &&
 355        test "$output" = "No files need merging" &&
 356        git commit -m "Merge resolved by keeping module" &&
 357
 358        mv submod submod-movedaside &&
 359        git checkout -b test$test_count.b test$test_count &&
 360        git submodule update -N &&
 361        test_must_fail git merge master &&
 362        test -n "$(git ls-files -u)" &&
 363        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 364        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 365        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 366        ( yes "l" | git mergetool submod ) &&
 367        test ! -e submod &&
 368        output="$(git mergetool --no-prompt)" &&
 369        test "$output" = "No files need merging" &&
 370        git commit -m "Merge resolved by deleting module" &&
 371
 372        mv submod-movedaside submod &&
 373        git checkout -b test$test_count.c master &&
 374        git submodule update -N &&
 375        test_must_fail git merge test$test_count &&
 376        test -n "$(git ls-files -u)" &&
 377        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 378        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 379        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 380        ( yes "r" | git mergetool submod ) &&
 381        test ! -e submod &&
 382        test -d submod.orig &&
 383        git submodule update -N &&
 384        output="$(git mergetool --no-prompt)" &&
 385        test "$output" = "No files need merging" &&
 386        git commit -m "Merge resolved by deleting module" &&
 387        mv submod.orig submod &&
 388
 389        git checkout -b test$test_count.d master &&
 390        git submodule update -N &&
 391        test_must_fail git merge test$test_count &&
 392        test -n "$(git ls-files -u)" &&
 393        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 394        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 395        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 396        ( yes "l" | git mergetool submod ) &&
 397        test "$(cat submod/bar)" = "master submodule" &&
 398        git submodule update -N &&
 399        test "$(cat submod/bar)" = "master submodule" &&
 400        output="$(git mergetool --no-prompt)" &&
 401        test "$output" = "No files need merging" &&
 402        git commit -m "Merge resolved by keeping module"
 403'
 404
 405test_expect_success 'file vs modified submodule' '
 406        git checkout -b test$test_count branch1 &&
 407        git submodule update -N &&
 408        mv submod submod-movedaside &&
 409        git rm --cached submod &&
 410        echo not a submodule >submod &&
 411        git add submod &&
 412        git commit -m "Submodule path becomes file" &&
 413        git checkout -b test$test_count.a branch1 &&
 414        test_must_fail git merge master &&
 415        test -n "$(git ls-files -u)" &&
 416        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 417        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 418        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 419        ( yes "r" | git mergetool submod ) &&
 420        rmdir submod && mv submod-movedaside submod &&
 421        test "$(cat submod/bar)" = "branch1 submodule" &&
 422        git submodule update -N &&
 423        test "$(cat submod/bar)" = "master submodule" &&
 424        output="$(git mergetool --no-prompt)" &&
 425        test "$output" = "No files need merging" &&
 426        git commit -m "Merge resolved by keeping module" &&
 427
 428        mv submod submod-movedaside &&
 429        git checkout -b test$test_count.b test$test_count &&
 430        test_must_fail git merge master &&
 431        test -n "$(git ls-files -u)" &&
 432        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 433        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 434        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 435        ( yes "l" | git mergetool submod ) &&
 436        git submodule update -N &&
 437        test "$(cat submod)" = "not a submodule" &&
 438        output="$(git mergetool --no-prompt)" &&
 439        test "$output" = "No files need merging" &&
 440        git commit -m "Merge resolved by keeping file" &&
 441
 442        git checkout -b test$test_count.c master &&
 443        rmdir submod && mv submod-movedaside submod &&
 444        test ! -e submod.orig &&
 445        git submodule update -N &&
 446        test_must_fail git merge test$test_count &&
 447        test -n "$(git ls-files -u)" &&
 448        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 449        ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
 450        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 451        ( yes "r" | git mergetool submod ) &&
 452        test -d submod.orig &&
 453        git submodule update -N &&
 454        test "$(cat submod)" = "not a submodule" &&
 455        output="$(git mergetool --no-prompt)" &&
 456        test "$output" = "No files need merging" &&
 457        git commit -m "Merge resolved by keeping file" &&
 458
 459        git checkout -b test$test_count.d master &&
 460        rmdir submod && mv submod.orig submod &&
 461        git submodule update -N &&
 462        test_must_fail git merge test$test_count &&
 463        test -n "$(git ls-files -u)" &&
 464        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
 465        ( yes "" | git mergetool both>/dev/null 2>&1 ) &&
 466        ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
 467        ( yes "l" | git mergetool submod ) &&
 468        test "$(cat submod/bar)" = "master submodule" &&
 469        git submodule update -N &&
 470        test "$(cat submod/bar)" = "master submodule" &&
 471        output="$(git mergetool --no-prompt)" &&
 472        test "$output" = "No files need merging" &&
 473        git commit -m "Merge resolved by keeping module"
 474'
 475
 476test_expect_success 'submodule in subdirectory' '
 477        git checkout -b test$test_count branch1 &&
 478        git submodule update -N &&
 479        (
 480                cd subdir &&
 481                test_create_repo subdir_module &&
 482                (
 483                cd subdir_module &&
 484                : >file15 &&
 485                git add file15 &&
 486                git commit -m "add initial versions"
 487                )
 488        ) &&
 489        test_when_finished "rm -rf subdir/subdir_module" &&
 490        git submodule add git://example.com/subsubmodule subdir/subdir_module &&
 491        git add subdir/subdir_module &&
 492        git commit -m "add submodule in subdirectory" &&
 493
 494        git checkout -b test$test_count.a test$test_count &&
 495        git submodule update -N &&
 496        (
 497        cd subdir/subdir_module &&
 498                git checkout -b super10.a &&
 499                echo test$test_count.a >file15 &&
 500                git add file15 &&
 501                git commit -m "on branch 10.a"
 502        ) &&
 503        git add subdir/subdir_module &&
 504        git commit -m "change submodule in subdirectory on test$test_count.a" &&
 505
 506        git checkout -b test$test_count.b test$test_count &&
 507        git submodule update -N &&
 508        (
 509                cd subdir/subdir_module &&
 510                git checkout -b super10.b &&
 511                echo test$test_count.b >file15 &&
 512                git add file15 &&
 513                git commit -m "on branch 10.b"
 514        ) &&
 515        git add subdir/subdir_module &&
 516        git commit -m "change submodule in subdirectory on test$test_count.b" &&
 517
 518        test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
 519        (
 520                cd subdir &&
 521                ( yes "l" | git mergetool subdir_module )
 522        ) &&
 523        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 524        git submodule update -N &&
 525        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 526        git reset --hard &&
 527        git submodule update -N &&
 528
 529        test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
 530        ( yes "r" | git mergetool subdir/subdir_module ) &&
 531        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 532        git submodule update -N &&
 533        test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
 534        git commit -m "branch1 resolved with mergetool"
 535'
 536
 537test_expect_success 'directory vs modified submodule' '
 538        git checkout -b test$test_count branch1 &&
 539        mv submod submod-movedaside &&
 540        git rm --cached submod &&
 541        mkdir submod &&
 542        echo not a submodule >submod/file16 &&
 543        git add submod/file16 &&
 544        git commit -m "Submodule path becomes directory" &&
 545
 546        test_must_fail git merge master &&
 547        test -n "$(git ls-files -u)" &&
 548        ( yes "l" | git mergetool submod ) &&
 549        test "$(cat submod/file16)" = "not a submodule" &&
 550        rm -rf submod.orig &&
 551
 552        git reset --hard >/dev/null 2>&1 &&
 553        test_must_fail git merge master &&
 554        test -n "$(git ls-files -u)" &&
 555        test ! -e submod.orig &&
 556        ( yes "r" | git mergetool submod ) &&
 557        test -d submod.orig &&
 558        test "$(cat submod.orig/file16)" = "not a submodule" &&
 559        rm -r submod.orig &&
 560        mv submod-movedaside/.git submod &&
 561        ( cd submod && git clean -f && git reset --hard ) &&
 562        git submodule update -N &&
 563        test "$(cat submod/bar)" = "master submodule" &&
 564        git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside &&
 565
 566        git checkout -b test$test_count.c master &&
 567        git submodule update -N &&
 568        test_must_fail git merge test$test_count &&
 569        test -n "$(git ls-files -u)" &&
 570        ( yes "l" | git mergetool submod ) &&
 571        git submodule update -N &&
 572        test "$(cat submod/bar)" = "master submodule" &&
 573
 574        git reset --hard >/dev/null 2>&1 &&
 575        git submodule update -N &&
 576        test_must_fail git merge test$test_count &&
 577        test -n "$(git ls-files -u)" &&
 578        test ! -e submod.orig &&
 579        ( yes "r" | git mergetool submod ) &&
 580        test "$(cat submod/file16)" = "not a submodule" &&
 581
 582        git reset --hard master >/dev/null 2>&1 &&
 583        ( cd submod && git clean -f && git reset --hard ) &&
 584        git submodule update -N
 585'
 586
 587test_expect_success 'file with no base' '
 588        test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 589        git checkout -b test$test_count branch1 &&
 590        test_must_fail git merge master &&
 591        git mergetool --no-prompt --tool mybase -- both &&
 592        >expected &&
 593        test_cmp both expected
 594'
 595
 596test_expect_success 'custom commands override built-ins' '
 597        test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 598        git checkout -b test$test_count branch1 &&
 599        test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
 600        test_config mergetool.defaults.trustExitCode true &&
 601        test_must_fail git merge master &&
 602        git mergetool --no-prompt --tool defaults -- both &&
 603        echo master both added >expected &&
 604        test_cmp both expected
 605'
 606
 607test_expect_success 'filenames seen by tools start with ./' '
 608        test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 609        git checkout -b test$test_count branch1 &&
 610        test_config mergetool.writeToTemp false &&
 611        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 612        test_config mergetool.myecho.trustExitCode true &&
 613        test_must_fail git merge master &&
 614        git mergetool --no-prompt --tool myecho -- both >actual &&
 615        grep ^\./both_LOCAL_ actual >/dev/null
 616'
 617
 618test_lazy_prereq MKTEMP '
 619        tempdir=$(mktemp -d -t foo.XXXXXX) &&
 620        test -d "$tempdir" &&
 621        rmdir "$tempdir"
 622'
 623
 624test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
 625        test_when_finished "git reset --hard master >/dev/null 2>&1" &&
 626        git checkout -b test$test_count branch1 &&
 627        test_config mergetool.writeToTemp true &&
 628        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 629        test_config mergetool.myecho.trustExitCode true &&
 630        test_must_fail git merge master &&
 631        git mergetool --no-prompt --tool myecho -- both >actual &&
 632        test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
 633        grep /both_LOCAL_ actual >/dev/null
 634'
 635
 636test_expect_success 'diff.orderFile configuration is honored' '
 637        test_when_finished "git reset --hard >/dev/null" &&
 638        git checkout order-file-side2 &&
 639        test_config diff.orderFile order-file &&
 640        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 641        test_config mergetool.myecho.trustExitCode true &&
 642        echo b >order-file &&
 643        echo a >>order-file &&
 644        test_must_fail git merge order-file-side1 &&
 645        cat >expect <<-\EOF &&
 646                Merging:
 647                b
 648                a
 649        EOF
 650        git mergetool --no-prompt --tool myecho >output &&
 651        git grep --no-index -h -A2 Merging: output >actual &&
 652        test_cmp expect actual
 653'
 654test_expect_success 'mergetool -Oorder-file is honored' '
 655        test_when_finished "git reset --hard >/dev/null 2>&1" &&
 656        test_config diff.orderFile order-file &&
 657        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 658        test_config mergetool.myecho.trustExitCode true &&
 659        echo b >order-file &&
 660        echo a >>order-file &&
 661        test_must_fail git merge order-file-side1 &&
 662        cat >expect <<-\EOF &&
 663                Merging:
 664                a
 665                b
 666        EOF
 667        git mergetool -O/dev/null --no-prompt --tool myecho >output &&
 668        git grep --no-index -h -A2 Merging: output >actual &&
 669        test_cmp expect actual &&
 670        git reset --hard >/dev/null 2>&1 &&
 671
 672        git config --unset diff.orderFile &&
 673        test_must_fail git merge order-file-side1 &&
 674        cat >expect <<-\EOF &&
 675                Merging:
 676                b
 677                a
 678        EOF
 679        git mergetool -Oorder-file --no-prompt --tool myecho >output &&
 680        git grep --no-index -h -A2 Merging: output >actual &&
 681        test_cmp expect actual
 682'
 683
 684test_done