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