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