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