dad607e1864b472a2e2ed9bb3821b33ddc795d93
   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        test_write_lines one two 3 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        test_write_lines one two 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        test_write_lines one two 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        test_when_finished "git reset --hard" &&
 131        git checkout -b test$test_count branch1 &&
 132        git submodule update -N &&
 133        test_must_fail git merge master &&
 134        ( yes "" | git mergetool both ) &&
 135        ( yes "" | git mergetool file1 file1 ) &&
 136        ( yes "" | git mergetool file2 "spaced name" ) &&
 137        ( yes "" | git mergetool subdir/file3 ) &&
 138        ( yes "d" | git mergetool file11 ) &&
 139        ( yes "d" | git mergetool file12 ) &&
 140        ( yes "l" | git mergetool submod ) &&
 141        test "$(cat file1)" = "master updated" &&
 142        test "$(cat file2)" = "master new" &&
 143        test "$(cat subdir/file3)" = "master new sub" &&
 144        test "$(cat submod/bar)" = "branch1 submodule" &&
 145        git commit -m "branch1 resolved with mergetool"
 146'
 147
 148test_expect_success 'gui mergetool' '
 149        test_config merge.guitool myguitool &&
 150        test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
 151        test_config mergetool.myguitool.trustExitCode true &&
 152        test_when_finished "git reset --hard" &&
 153        git checkout -b test$test_count branch1 &&
 154        git submodule update -N &&
 155        test_must_fail git merge master &&
 156        ( yes "" | git mergetool --gui both ) &&
 157        ( yes "" | git mergetool -g file1 file1 ) &&
 158        ( yes "" | git mergetool --gui file2 "spaced name" ) &&
 159        ( yes "" | git mergetool --gui subdir/file3 ) &&
 160        ( yes "d" | git mergetool --gui file11 ) &&
 161        ( yes "d" | git mergetool --gui file12 ) &&
 162        ( yes "l" | git mergetool --gui submod ) &&
 163        test "$(cat file1)" = "gui master updated" &&
 164        test "$(cat file2)" = "gui master new" &&
 165        test "$(cat subdir/file3)" = "gui master new sub" &&
 166        test "$(cat submod/bar)" = "branch1 submodule" &&
 167        git commit -m "branch1 resolved with mergetool"
 168'
 169
 170test_expect_success 'mergetool crlf' '
 171        test_when_finished "git reset --hard" &&
 172        # This test_config line must go after the above reset line so that
 173        # core.autocrlf is unconfigured before reset runs.  (The
 174        # test_config command uses test_when_finished internally and
 175        # test_when_finished is LIFO.)
 176        test_config core.autocrlf true &&
 177        git checkout -b test$test_count branch1 &&
 178        test_must_fail git merge master &&
 179        ( yes "" | git mergetool file1 ) &&
 180        ( yes "" | git mergetool file2 ) &&
 181        ( yes "" | git mergetool "spaced name" ) &&
 182        ( yes "" | git mergetool both ) &&
 183        ( yes "" | git mergetool subdir/file3 ) &&
 184        ( yes "d" | git mergetool file11 ) &&
 185        ( yes "d" | git mergetool file12 ) &&
 186        ( yes "r" | git mergetool submod ) &&
 187        test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
 188        test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
 189        test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
 190        git submodule update -N &&
 191        test "$(cat submod/bar)" = "master submodule" &&
 192        git commit -m "branch1 resolved with mergetool - autocrlf"
 193'
 194
 195test_expect_success 'mergetool in subdir' '
 196        test_when_finished "git reset --hard" &&
 197        git checkout -b test$test_count branch1 &&
 198        git submodule update -N &&
 199        (
 200                cd subdir &&
 201                test_must_fail git merge master &&
 202                ( yes "" | git mergetool file3 ) &&
 203                test "$(cat file3)" = "master new sub"
 204        )
 205'
 206
 207test_expect_success 'mergetool on file in parent dir' '
 208        test_when_finished "git reset --hard" &&
 209        git checkout -b test$test_count branch1 &&
 210        git submodule update -N &&
 211        (
 212                cd subdir &&
 213                test_must_fail git merge master &&
 214                ( yes "" | git mergetool file3 ) &&
 215                ( yes "" | git mergetool ../file1 ) &&
 216                ( yes "" | git mergetool ../file2 ../spaced\ name ) &&
 217                ( yes "" | git mergetool ../both ) &&
 218                ( yes "d" | git mergetool ../file11 ) &&
 219                ( yes "d" | git mergetool ../file12 ) &&
 220                ( yes "l" | git mergetool ../submod ) &&
 221                test "$(cat ../file1)" = "master updated" &&
 222                test "$(cat ../file2)" = "master new" &&
 223                test "$(cat ../submod/bar)" = "branch1 submodule" &&
 224                git commit -m "branch1 resolved with mergetool - subdir"
 225        )
 226'
 227
 228test_expect_success 'mergetool skips autoresolved' '
 229        test_when_finished "git reset --hard" &&
 230        git checkout -b test$test_count branch1 &&
 231        git submodule update -N &&
 232        test_must_fail git merge master &&
 233        test -n "$(git ls-files -u)" &&
 234        ( yes "d" | git mergetool file11 ) &&
 235        ( yes "d" | git mergetool file12 ) &&
 236        ( yes "l" | git mergetool submod ) &&
 237        output="$(git mergetool --no-prompt)" &&
 238        test "$output" = "No files need merging"
 239'
 240
 241test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
 242        test_when_finished "git reset --hard" &&
 243        git checkout -b test$test_count branch1 &&
 244        test_config rerere.enabled false &&
 245        (
 246                cd subdir &&
 247                test_must_fail git merge master &&
 248                ( yes "r" | git mergetool ../submod ) &&
 249                ( yes "d" "d" | git mergetool --no-prompt ) &&
 250                test "$(cat ../file1)" = "master updated" &&
 251                test "$(cat ../file2)" = "master new" &&
 252                test "$(cat file3)" = "master new sub" &&
 253                ( cd .. && git submodule update -N ) &&
 254                test "$(cat ../submod/bar)" = "master submodule" &&
 255                git commit -m "branch2 resolved by mergetool from subdir"
 256        )
 257'
 258
 259test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
 260        test_when_finished "git reset --hard" &&
 261        git checkout -b test$test_count branch1 &&
 262        test_config rerere.enabled true &&
 263        rm -rf .git/rr-cache &&
 264        (
 265                cd subdir &&
 266                test_must_fail git merge master &&
 267                ( yes "r" | git mergetool ../submod ) &&
 268                ( yes "d" "d" | git mergetool --no-prompt ) &&
 269                test "$(cat ../file1)" = "master updated" &&
 270                test "$(cat ../file2)" = "master new" &&
 271                test "$(cat file3)" = "master new sub" &&
 272                ( cd .. && git submodule update -N ) &&
 273                test "$(cat ../submod/bar)" = "master submodule" &&
 274                git commit -m "branch2 resolved by mergetool from subdir"
 275        )
 276'
 277
 278test_expect_success 'mergetool skips resolved paths when rerere is active' '
 279        test_when_finished "git reset --hard" &&
 280        test_config rerere.enabled true &&
 281        rm -rf .git/rr-cache &&
 282        git checkout -b test$test_count branch1 &&
 283        git submodule update -N &&
 284        test_must_fail git merge master &&
 285        ( yes "l" | git mergetool --no-prompt submod ) &&
 286        ( yes "d" "d" | git mergetool --no-prompt ) &&
 287        git submodule update -N &&
 288        output="$(yes "n" | git mergetool --no-prompt)" &&
 289        test "$output" = "No files need merging"
 290'
 291
 292test_expect_success 'conflicted stash sets up rerere'  '
 293        test_when_finished "git reset --hard" &&
 294        test_config rerere.enabled true &&
 295        git checkout stash1 &&
 296        echo "Conflicting stash content" >file11 &&
 297        git stash &&
 298
 299        git checkout --detach stash2 &&
 300        test_must_fail git stash apply &&
 301
 302        test -n "$(git ls-files -u)" &&
 303        conflicts="$(git rerere remaining)" &&
 304        test "$conflicts" = "file11" &&
 305        output="$(git mergetool --no-prompt)" &&
 306        test "$output" != "No files need merging" &&
 307
 308        git commit -am "save the stash resolution" &&
 309
 310        git reset --hard stash2 &&
 311        test_must_fail git stash apply &&
 312
 313        test -n "$(git ls-files -u)" &&
 314        conflicts="$(git rerere remaining)" &&
 315        test -z "$conflicts" &&
 316        output="$(git mergetool --no-prompt)" &&
 317        test "$output" = "No files need merging"
 318'
 319
 320test_expect_success 'mergetool takes partial path' '
 321        test_when_finished "git reset --hard" &&
 322        test_config rerere.enabled false &&
 323        git checkout -b test$test_count branch1 &&
 324        git submodule update -N &&
 325        test_must_fail git merge master &&
 326
 327        ( yes "" | git mergetool subdir ) &&
 328
 329        test "$(cat subdir/file3)" = "master new sub"
 330'
 331
 332test_expect_success 'mergetool delete/delete conflict' '
 333        test_when_finished "git reset --hard" &&
 334        git checkout -b test$test_count move-to-c &&
 335        test_must_fail git merge move-to-b &&
 336        echo d | git mergetool a/a/file.txt &&
 337        ! test -f a/a/file.txt &&
 338        git reset --hard &&
 339        test_must_fail git merge move-to-b &&
 340        echo m | git mergetool a/a/file.txt &&
 341        test -f b/b/file.txt &&
 342        git reset --hard &&
 343        test_must_fail git merge move-to-b &&
 344        ! echo a | git mergetool a/a/file.txt &&
 345        ! test -f a/a/file.txt
 346'
 347
 348test_expect_success 'mergetool produces no errors when keepBackup is used' '
 349        test_when_finished "git reset --hard" &&
 350        git checkout -b test$test_count move-to-c &&
 351        test_config mergetool.keepBackup true &&
 352        test_must_fail git merge move-to-b &&
 353        echo d | git mergetool a/a/file.txt 2>actual &&
 354        test_must_be_empty actual &&
 355        ! test -d a
 356'
 357
 358test_expect_success 'mergetool honors tempfile config for deleted files' '
 359        test_when_finished "git reset --hard" &&
 360        git checkout -b test$test_count move-to-c &&
 361        test_config mergetool.keepTemporaries false &&
 362        test_must_fail git merge move-to-b &&
 363        echo d | git mergetool a/a/file.txt &&
 364        ! test -d a
 365'
 366
 367test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
 368        test_when_finished "git reset --hard" &&
 369        test_when_finished "git clean -fdx" &&
 370        git checkout -b test$test_count move-to-c &&
 371        test_config mergetool.keepTemporaries true &&
 372        test_must_fail git merge move-to-b &&
 373        ! test_write_lines a n | git mergetool a/a/file.txt &&
 374        test -d a/a &&
 375        cat >expect <<-\EOF &&
 376        file_BASE_.txt
 377        file_LOCAL_.txt
 378        file_REMOTE_.txt
 379        EOF
 380        ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
 381        test_cmp expect actual
 382'
 383
 384test_expect_success 'deleted vs modified submodule' '
 385        test_when_finished "git reset --hard" &&
 386        git checkout -b test$test_count branch1 &&
 387        git submodule update -N &&
 388        mv submod submod-movedaside &&
 389        git rm --cached submod &&
 390        git commit -m "Submodule deleted from branch" &&
 391        git checkout -b test$test_count.a test$test_count &&
 392        test_must_fail git merge master &&
 393        test -n "$(git ls-files -u)" &&
 394        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 395        ( yes "" | git mergetool both ) &&
 396        ( yes "d" | git mergetool file11 file12 ) &&
 397        ( yes "r" | git mergetool submod ) &&
 398        rmdir submod && mv submod-movedaside submod &&
 399        test "$(cat submod/bar)" = "branch1 submodule" &&
 400        git submodule update -N &&
 401        test "$(cat submod/bar)" = "master submodule" &&
 402        output="$(git mergetool --no-prompt)" &&
 403        test "$output" = "No files need merging" &&
 404        git commit -m "Merge resolved by keeping module" &&
 405
 406        mv submod submod-movedaside &&
 407        git checkout -b test$test_count.b test$test_count &&
 408        git submodule update -N &&
 409        test_must_fail git merge master &&
 410        test -n "$(git ls-files -u)" &&
 411        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 412        ( yes "" | git mergetool both ) &&
 413        ( yes "d" | git mergetool file11 file12 ) &&
 414        ( yes "l" | git mergetool submod ) &&
 415        test ! -e submod &&
 416        output="$(git mergetool --no-prompt)" &&
 417        test "$output" = "No files need merging" &&
 418        git commit -m "Merge resolved by deleting module" &&
 419
 420        mv submod-movedaside submod &&
 421        git checkout -b test$test_count.c master &&
 422        git submodule update -N &&
 423        test_must_fail git merge test$test_count &&
 424        test -n "$(git ls-files -u)" &&
 425        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 426        ( yes "" | git mergetool both ) &&
 427        ( yes "d" | git mergetool file11 file12 ) &&
 428        ( yes "r" | git mergetool submod ) &&
 429        test ! -e submod &&
 430        test -d submod.orig &&
 431        git submodule update -N &&
 432        output="$(git mergetool --no-prompt)" &&
 433        test "$output" = "No files need merging" &&
 434        git commit -m "Merge resolved by deleting module" &&
 435        mv submod.orig submod &&
 436
 437        git checkout -b test$test_count.d master &&
 438        git submodule update -N &&
 439        test_must_fail git merge test$test_count &&
 440        test -n "$(git ls-files -u)" &&
 441        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 442        ( yes "" | git mergetool both ) &&
 443        ( yes "d" | git mergetool file11 file12 ) &&
 444        ( yes "l" | git mergetool submod ) &&
 445        test "$(cat submod/bar)" = "master submodule" &&
 446        git submodule update -N &&
 447        test "$(cat submod/bar)" = "master submodule" &&
 448        output="$(git mergetool --no-prompt)" &&
 449        test "$output" = "No files need merging" &&
 450        git commit -m "Merge resolved by keeping module"
 451'
 452
 453test_expect_success 'file vs modified submodule' '
 454        test_when_finished "git reset --hard" &&
 455        git checkout -b test$test_count branch1 &&
 456        git submodule update -N &&
 457        mv submod submod-movedaside &&
 458        git rm --cached submod &&
 459        echo not a submodule >submod &&
 460        git add submod &&
 461        git commit -m "Submodule path becomes file" &&
 462        git checkout -b test$test_count.a branch1 &&
 463        test_must_fail git merge master &&
 464        test -n "$(git ls-files -u)" &&
 465        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 466        ( yes "" | git mergetool both ) &&
 467        ( yes "d" | git mergetool file11 file12 ) &&
 468        ( yes "r" | git mergetool submod ) &&
 469        rmdir submod && mv submod-movedaside submod &&
 470        test "$(cat submod/bar)" = "branch1 submodule" &&
 471        git submodule update -N &&
 472        test "$(cat submod/bar)" = "master submodule" &&
 473        output="$(git mergetool --no-prompt)" &&
 474        test "$output" = "No files need merging" &&
 475        git commit -m "Merge resolved by keeping module" &&
 476
 477        mv submod submod-movedaside &&
 478        git checkout -b test$test_count.b test$test_count &&
 479        test_must_fail git merge master &&
 480        test -n "$(git ls-files -u)" &&
 481        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 482        ( yes "" | git mergetool both ) &&
 483        ( yes "d" | git mergetool file11 file12 ) &&
 484        ( yes "l" | git mergetool submod ) &&
 485        git submodule update -N &&
 486        test "$(cat submod)" = "not a submodule" &&
 487        output="$(git mergetool --no-prompt)" &&
 488        test "$output" = "No files need merging" &&
 489        git commit -m "Merge resolved by keeping file" &&
 490
 491        git checkout -b test$test_count.c master &&
 492        rmdir submod && mv submod-movedaside submod &&
 493        test ! -e submod.orig &&
 494        git submodule update -N &&
 495        test_must_fail git merge test$test_count &&
 496        test -n "$(git ls-files -u)" &&
 497        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 498        ( yes "" | git mergetool both ) &&
 499        ( yes "d" | git mergetool file11 file12 ) &&
 500        ( yes "r" | git mergetool submod ) &&
 501        test -d submod.orig &&
 502        git submodule update -N &&
 503        test "$(cat submod)" = "not a submodule" &&
 504        output="$(git mergetool --no-prompt)" &&
 505        test "$output" = "No files need merging" &&
 506        git commit -m "Merge resolved by keeping file" &&
 507
 508        git checkout -b test$test_count.d master &&
 509        rmdir submod && mv submod.orig submod &&
 510        git submodule update -N &&
 511        test_must_fail git merge test$test_count &&
 512        test -n "$(git ls-files -u)" &&
 513        ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
 514        ( yes "" | git mergetool both ) &&
 515        ( yes "d" | git mergetool file11 file12 ) &&
 516        ( yes "l" | git mergetool submod ) &&
 517        test "$(cat submod/bar)" = "master submodule" &&
 518        git submodule update -N &&
 519        test "$(cat submod/bar)" = "master submodule" &&
 520        output="$(git mergetool --no-prompt)" &&
 521        test "$output" = "No files need merging" &&
 522        git commit -m "Merge resolved by keeping module"
 523'
 524
 525test_expect_success 'submodule in subdirectory' '
 526        test_when_finished "git reset --hard" &&
 527        git checkout -b test$test_count branch1 &&
 528        git submodule update -N &&
 529        (
 530                cd subdir &&
 531                test_create_repo subdir_module &&
 532                (
 533                cd subdir_module &&
 534                : >file15 &&
 535                git add file15 &&
 536                git commit -m "add initial versions"
 537                )
 538        ) &&
 539        test_when_finished "rm -rf subdir/subdir_module" &&
 540        git submodule add git://example.com/subsubmodule subdir/subdir_module &&
 541        git add subdir/subdir_module &&
 542        git commit -m "add submodule in subdirectory" &&
 543
 544        git checkout -b test$test_count.a test$test_count &&
 545        git submodule update -N &&
 546        (
 547        cd subdir/subdir_module &&
 548                git checkout -b super10.a &&
 549                echo test$test_count.a >file15 &&
 550                git add file15 &&
 551                git commit -m "on branch 10.a"
 552        ) &&
 553        git add subdir/subdir_module &&
 554        git commit -m "change submodule in subdirectory on test$test_count.a" &&
 555
 556        git checkout -b test$test_count.b test$test_count &&
 557        git submodule update -N &&
 558        (
 559                cd subdir/subdir_module &&
 560                git checkout -b super10.b &&
 561                echo test$test_count.b >file15 &&
 562                git add file15 &&
 563                git commit -m "on branch 10.b"
 564        ) &&
 565        git add subdir/subdir_module &&
 566        git commit -m "change submodule in subdirectory on test$test_count.b" &&
 567
 568        test_must_fail git merge test$test_count.a &&
 569        (
 570                cd subdir &&
 571                ( yes "l" | git mergetool subdir_module )
 572        ) &&
 573        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 574        git submodule update -N &&
 575        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 576        git reset --hard &&
 577        git submodule update -N &&
 578
 579        test_must_fail git merge test$test_count.a &&
 580        ( yes "r" | git mergetool subdir/subdir_module ) &&
 581        test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
 582        git submodule update -N &&
 583        test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
 584        git commit -m "branch1 resolved with mergetool"
 585'
 586
 587test_expect_success 'directory vs modified submodule' '
 588        test_when_finished "git reset --hard" &&
 589        git checkout -b test$test_count branch1 &&
 590        mv submod submod-movedaside &&
 591        git rm --cached submod &&
 592        mkdir submod &&
 593        echo not a submodule >submod/file16 &&
 594        git add submod/file16 &&
 595        git commit -m "Submodule path becomes directory" &&
 596
 597        test_must_fail git merge master &&
 598        test -n "$(git ls-files -u)" &&
 599        ( yes "l" | git mergetool submod ) &&
 600        test "$(cat submod/file16)" = "not a submodule" &&
 601        rm -rf submod.orig &&
 602
 603        git reset --hard &&
 604        test_must_fail git merge master &&
 605        test -n "$(git ls-files -u)" &&
 606        test ! -e submod.orig &&
 607        ( yes "r" | git mergetool submod ) &&
 608        test -d submod.orig &&
 609        test "$(cat submod.orig/file16)" = "not a submodule" &&
 610        rm -r submod.orig &&
 611        mv submod-movedaside/.git submod &&
 612        ( cd submod && git clean -f && git reset --hard ) &&
 613        git submodule update -N &&
 614        test "$(cat submod/bar)" = "master submodule" &&
 615        git reset --hard &&
 616        rm -rf submod-movedaside &&
 617
 618        git checkout -b test$test_count.c master &&
 619        git submodule update -N &&
 620        test_must_fail git merge test$test_count &&
 621        test -n "$(git ls-files -u)" &&
 622        ( yes "l" | git mergetool submod ) &&
 623        git submodule update -N &&
 624        test "$(cat submod/bar)" = "master submodule" &&
 625
 626        git reset --hard &&
 627        git submodule update -N &&
 628        test_must_fail git merge test$test_count &&
 629        test -n "$(git ls-files -u)" &&
 630        test ! -e submod.orig &&
 631        ( yes "r" | git mergetool submod ) &&
 632        test "$(cat submod/file16)" = "not a submodule" &&
 633
 634        git reset --hard master &&
 635        ( cd submod && git clean -f && git reset --hard ) &&
 636        git submodule update -N
 637'
 638
 639test_expect_success 'file with no base' '
 640        test_when_finished "git reset --hard" &&
 641        git checkout -b test$test_count branch1 &&
 642        test_must_fail git merge master &&
 643        git mergetool --no-prompt --tool mybase -- both &&
 644        test_must_be_empty both
 645'
 646
 647test_expect_success 'custom commands override built-ins' '
 648        test_when_finished "git reset --hard" &&
 649        git checkout -b test$test_count branch1 &&
 650        test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
 651        test_config mergetool.defaults.trustExitCode true &&
 652        test_must_fail git merge master &&
 653        git mergetool --no-prompt --tool defaults -- both &&
 654        echo master both added >expected &&
 655        test_cmp expected both
 656'
 657
 658test_expect_success 'filenames seen by tools start with ./' '
 659        test_when_finished "git reset --hard" &&
 660        git checkout -b test$test_count branch1 &&
 661        test_config mergetool.writeToTemp false &&
 662        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 663        test_config mergetool.myecho.trustExitCode true &&
 664        test_must_fail git merge master &&
 665        git mergetool --no-prompt --tool myecho -- both >actual &&
 666        grep ^\./both_LOCAL_ actual
 667'
 668
 669test_lazy_prereq MKTEMP '
 670        tempdir=$(mktemp -d -t foo.XXXXXX) &&
 671        test -d "$tempdir" &&
 672        rmdir "$tempdir"
 673'
 674
 675test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
 676        test_when_finished "git reset --hard" &&
 677        git checkout -b test$test_count branch1 &&
 678        test_config mergetool.writeToTemp true &&
 679        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 680        test_config mergetool.myecho.trustExitCode true &&
 681        test_must_fail git merge master &&
 682        git mergetool --no-prompt --tool myecho -- both >actual &&
 683        ! grep ^\./both_LOCAL_ actual &&
 684        grep /both_LOCAL_ actual
 685'
 686
 687test_expect_success 'diff.orderFile configuration is honored' '
 688        test_when_finished "git reset --hard" &&
 689        git checkout -b test$test_count order-file-side2 &&
 690        test_config diff.orderFile order-file &&
 691        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 692        test_config mergetool.myecho.trustExitCode true &&
 693        echo b >order-file &&
 694        echo a >>order-file &&
 695        test_must_fail git merge order-file-side1 &&
 696        cat >expect <<-\EOF &&
 697                Merging:
 698                b
 699                a
 700        EOF
 701
 702        # make sure "order-file" that is ambiguous between
 703        # rev and path is understood correctly.
 704        git branch order-file HEAD &&
 705
 706        git mergetool --no-prompt --tool myecho >output &&
 707        git grep --no-index -h -A2 Merging: output >actual &&
 708        test_cmp expect actual
 709'
 710test_expect_success 'mergetool -Oorder-file is honored' '
 711        test_when_finished "git reset --hard" &&
 712        git checkout -b test$test_count order-file-side2 &&
 713        test_config diff.orderFile order-file &&
 714        test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
 715        test_config mergetool.myecho.trustExitCode true &&
 716        echo b >order-file &&
 717        echo a >>order-file &&
 718        test_must_fail git merge order-file-side1 &&
 719        cat >expect <<-\EOF &&
 720                Merging:
 721                a
 722                b
 723        EOF
 724        git mergetool -O/dev/null --no-prompt --tool myecho >output &&
 725        git grep --no-index -h -A2 Merging: output >actual &&
 726        test_cmp expect actual &&
 727        git reset --hard &&
 728
 729        git config --unset diff.orderFile &&
 730        test_must_fail git merge order-file-side1 &&
 731        cat >expect <<-\EOF &&
 732                Merging:
 733                b
 734                a
 735        EOF
 736        git mergetool -Oorder-file --no-prompt --tool myecho >output &&
 737        git grep --no-index -h -A2 Merging: output >actual &&
 738        test_cmp expect actual
 739'
 740
 741test_done