t4015: prefer --color to -c color.diff=always
[git/debian.git] / t / t7610-mergetool.sh
blob381b7df452e44622c46c8c3471f181b4568be10a
1 #!/bin/sh
3 # Copyright (c) 2008 Charles Bailey
6 test_description='git mergetool
8 Testing basic merge tool invocation'
10 . ./test-lib.sh
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
16 test_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 &&
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" &&
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 &&
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" &&
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" &&
74 git checkout -b stash1 master &&
75 echo stash1 change file11 >file11 &&
76 git add file11 &&
77 git commit -m "stash1 changes" &&
79 git checkout -b stash2 master &&
80 echo stash2 change file11 >file11 &&
81 git add file11 &&
82 git commit -m "stash2 changes" &&
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 &&
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" &&
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 &&
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
129 test_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"
148 test_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"
173 test_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 &&
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"
185 test_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 &&
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"
206 test_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"
219 test_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 &&
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"
237 test_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 &&
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"
256 test_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"
270 test_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 &&
277 git checkout --detach stash2 &&
278 test_must_fail git stash apply &&
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" &&
286 git commit -am "save the stash resolution" &&
288 git reset --hard stash2 &&
289 test_must_fail git stash apply &&
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"
298 test_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 &&
305 ( yes "" | git mergetool subdir ) &&
307 test "$(cat subdir/file3)" = "master new sub"
310 test_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
326 test_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 : >expect &&
332 echo d | git mergetool a/a/file.txt 2>actual &&
333 test_cmp expect actual &&
334 ! test -d a
337 test_expect_success 'mergetool honors tempfile config for deleted files' '
338 test_when_finished "git reset --hard" &&
339 git checkout -b test$test_count move-to-c &&
340 test_config mergetool.keepTemporaries false &&
341 test_must_fail git merge move-to-b &&
342 echo d | git mergetool a/a/file.txt &&
343 ! test -d a
346 test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
347 test_when_finished "git reset --hard" &&
348 test_when_finished "git clean -fdx" &&
349 git checkout -b test$test_count move-to-c &&
350 test_config mergetool.keepTemporaries true &&
351 test_must_fail git merge move-to-b &&
352 ! (echo a; echo n) | git mergetool a/a/file.txt &&
353 test -d a/a &&
354 cat >expect <<-\EOF &&
355 file_BASE_.txt
356 file_LOCAL_.txt
357 file_REMOTE_.txt
359 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
360 test_cmp expect actual
363 test_expect_success 'deleted vs modified submodule' '
364 test_when_finished "git reset --hard" &&
365 git checkout -b test$test_count branch1 &&
366 git submodule update -N &&
367 mv submod submod-movedaside &&
368 git rm --cached submod &&
369 git commit -m "Submodule deleted from branch" &&
370 git checkout -b test$test_count.a test$test_count &&
371 test_must_fail git merge master &&
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 rmdir submod && mv submod-movedaside submod &&
378 test "$(cat submod/bar)" = "branch1 submodule" &&
379 git submodule update -N &&
380 test "$(cat submod/bar)" = "master submodule" &&
381 output="$(git mergetool --no-prompt)" &&
382 test "$output" = "No files need merging" &&
383 git commit -m "Merge resolved by keeping module" &&
385 mv submod submod-movedaside &&
386 git checkout -b test$test_count.b test$test_count &&
387 git submodule update -N &&
388 test_must_fail git merge master &&
389 test -n "$(git ls-files -u)" &&
390 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
391 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
392 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
393 ( yes "l" | git mergetool submod ) &&
394 test ! -e submod &&
395 output="$(git mergetool --no-prompt)" &&
396 test "$output" = "No files need merging" &&
397 git commit -m "Merge resolved by deleting module" &&
399 mv submod-movedaside submod &&
400 git checkout -b test$test_count.c master &&
401 git submodule update -N &&
402 test_must_fail git merge test$test_count &&
403 test -n "$(git ls-files -u)" &&
404 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
405 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
406 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
407 ( yes "r" | git mergetool submod ) &&
408 test ! -e submod &&
409 test -d submod.orig &&
410 git submodule update -N &&
411 output="$(git mergetool --no-prompt)" &&
412 test "$output" = "No files need merging" &&
413 git commit -m "Merge resolved by deleting module" &&
414 mv submod.orig submod &&
416 git checkout -b test$test_count.d master &&
417 git submodule update -N &&
418 test_must_fail git merge test$test_count &&
419 test -n "$(git ls-files -u)" &&
420 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
421 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
422 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
423 ( yes "l" | git mergetool submod ) &&
424 test "$(cat submod/bar)" = "master submodule" &&
425 git submodule update -N &&
426 test "$(cat submod/bar)" = "master submodule" &&
427 output="$(git mergetool --no-prompt)" &&
428 test "$output" = "No files need merging" &&
429 git commit -m "Merge resolved by keeping module"
432 test_expect_success 'file vs modified submodule' '
433 test_when_finished "git reset --hard" &&
434 git checkout -b test$test_count branch1 &&
435 git submodule update -N &&
436 mv submod submod-movedaside &&
437 git rm --cached submod &&
438 echo not a submodule >submod &&
439 git add submod &&
440 git commit -m "Submodule path becomes file" &&
441 git checkout -b test$test_count.a branch1 &&
442 test_must_fail git merge master &&
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 rmdir submod && mv submod-movedaside submod &&
449 test "$(cat submod/bar)" = "branch1 submodule" &&
450 git submodule update -N &&
451 test "$(cat submod/bar)" = "master submodule" &&
452 output="$(git mergetool --no-prompt)" &&
453 test "$output" = "No files need merging" &&
454 git commit -m "Merge resolved by keeping module" &&
456 mv submod submod-movedaside &&
457 git checkout -b test$test_count.b test$test_count &&
458 test_must_fail git merge master &&
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 git submodule update -N &&
465 test "$(cat submod)" = "not a submodule" &&
466 output="$(git mergetool --no-prompt)" &&
467 test "$output" = "No files need merging" &&
468 git commit -m "Merge resolved by keeping file" &&
470 git checkout -b test$test_count.c master &&
471 rmdir submod && mv submod-movedaside submod &&
472 test ! -e submod.orig &&
473 git submodule update -N &&
474 test_must_fail git merge test$test_count &&
475 test -n "$(git ls-files -u)" &&
476 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
477 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
478 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
479 ( yes "r" | git mergetool submod ) &&
480 test -d submod.orig &&
481 git submodule update -N &&
482 test "$(cat submod)" = "not a submodule" &&
483 output="$(git mergetool --no-prompt)" &&
484 test "$output" = "No files need merging" &&
485 git commit -m "Merge resolved by keeping file" &&
487 git checkout -b test$test_count.d master &&
488 rmdir submod && mv submod.orig submod &&
489 git submodule update -N &&
490 test_must_fail git merge test$test_count &&
491 test -n "$(git ls-files -u)" &&
492 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
493 ( yes "" | git mergetool both>/dev/null 2>&1 ) &&
494 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
495 ( yes "l" | git mergetool submod ) &&
496 test "$(cat submod/bar)" = "master submodule" &&
497 git submodule update -N &&
498 test "$(cat submod/bar)" = "master submodule" &&
499 output="$(git mergetool --no-prompt)" &&
500 test "$output" = "No files need merging" &&
501 git commit -m "Merge resolved by keeping module"
504 test_expect_success 'submodule in subdirectory' '
505 test_when_finished "git reset --hard" &&
506 git checkout -b test$test_count branch1 &&
507 git submodule update -N &&
509 cd subdir &&
510 test_create_repo subdir_module &&
512 cd subdir_module &&
513 : >file15 &&
514 git add file15 &&
515 git commit -m "add initial versions"
517 ) &&
518 test_when_finished "rm -rf subdir/subdir_module" &&
519 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
520 git add subdir/subdir_module &&
521 git commit -m "add submodule in subdirectory" &&
523 git checkout -b test$test_count.a test$test_count &&
524 git submodule update -N &&
526 cd subdir/subdir_module &&
527 git checkout -b super10.a &&
528 echo test$test_count.a >file15 &&
529 git add file15 &&
530 git commit -m "on branch 10.a"
531 ) &&
532 git add subdir/subdir_module &&
533 git commit -m "change submodule in subdirectory on test$test_count.a" &&
535 git checkout -b test$test_count.b test$test_count &&
536 git submodule update -N &&
538 cd subdir/subdir_module &&
539 git checkout -b super10.b &&
540 echo test$test_count.b >file15 &&
541 git add file15 &&
542 git commit -m "on branch 10.b"
543 ) &&
544 git add subdir/subdir_module &&
545 git commit -m "change submodule in subdirectory on test$test_count.b" &&
547 test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
549 cd subdir &&
550 ( yes "l" | git mergetool subdir_module )
551 ) &&
552 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
553 git submodule update -N &&
554 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
555 git reset --hard &&
556 git submodule update -N &&
558 test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
559 ( yes "r" | git mergetool subdir/subdir_module ) &&
560 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
561 git submodule update -N &&
562 test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
563 git commit -m "branch1 resolved with mergetool"
566 test_expect_success 'directory vs modified submodule' '
567 test_when_finished "git reset --hard" &&
568 git checkout -b test$test_count branch1 &&
569 mv submod submod-movedaside &&
570 git rm --cached submod &&
571 mkdir submod &&
572 echo not a submodule >submod/file16 &&
573 git add submod/file16 &&
574 git commit -m "Submodule path becomes directory" &&
576 test_must_fail git merge master &&
577 test -n "$(git ls-files -u)" &&
578 ( yes "l" | git mergetool submod ) &&
579 test "$(cat submod/file16)" = "not a submodule" &&
580 rm -rf submod.orig &&
582 git reset --hard &&
583 test_must_fail git merge master &&
584 test -n "$(git ls-files -u)" &&
585 test ! -e submod.orig &&
586 ( yes "r" | git mergetool submod ) &&
587 test -d submod.orig &&
588 test "$(cat submod.orig/file16)" = "not a submodule" &&
589 rm -r submod.orig &&
590 mv submod-movedaside/.git submod &&
591 ( cd submod && git clean -f && git reset --hard ) &&
592 git submodule update -N &&
593 test "$(cat submod/bar)" = "master submodule" &&
594 git reset --hard &&
595 rm -rf submod-movedaside &&
597 git checkout -b test$test_count.c master &&
598 git submodule update -N &&
599 test_must_fail git merge test$test_count &&
600 test -n "$(git ls-files -u)" &&
601 ( yes "l" | git mergetool submod ) &&
602 git submodule update -N &&
603 test "$(cat submod/bar)" = "master submodule" &&
605 git reset --hard &&
606 git submodule update -N &&
607 test_must_fail git merge test$test_count &&
608 test -n "$(git ls-files -u)" &&
609 test ! -e submod.orig &&
610 ( yes "r" | git mergetool submod ) &&
611 test "$(cat submod/file16)" = "not a submodule" &&
613 git reset --hard master &&
614 ( cd submod && git clean -f && git reset --hard ) &&
615 git submodule update -N
618 test_expect_success 'file with no base' '
619 test_when_finished "git reset --hard" &&
620 git checkout -b test$test_count branch1 &&
621 test_must_fail git merge master &&
622 git mergetool --no-prompt --tool mybase -- both &&
623 >expected &&
624 test_cmp both expected
627 test_expect_success 'custom commands override built-ins' '
628 test_when_finished "git reset --hard" &&
629 git checkout -b test$test_count branch1 &&
630 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
631 test_config mergetool.defaults.trustExitCode true &&
632 test_must_fail git merge master &&
633 git mergetool --no-prompt --tool defaults -- both &&
634 echo master both added >expected &&
635 test_cmp both expected
638 test_expect_success 'filenames seen by tools start with ./' '
639 test_when_finished "git reset --hard" &&
640 git checkout -b test$test_count branch1 &&
641 test_config mergetool.writeToTemp false &&
642 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
643 test_config mergetool.myecho.trustExitCode true &&
644 test_must_fail git merge master &&
645 git mergetool --no-prompt --tool myecho -- both >actual &&
646 grep ^\./both_LOCAL_ actual >/dev/null
649 test_lazy_prereq MKTEMP '
650 tempdir=$(mktemp -d -t foo.XXXXXX) &&
651 test -d "$tempdir" &&
652 rmdir "$tempdir"
655 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
656 test_when_finished "git reset --hard" &&
657 git checkout -b test$test_count branch1 &&
658 test_config mergetool.writeToTemp true &&
659 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
660 test_config mergetool.myecho.trustExitCode true &&
661 test_must_fail git merge master &&
662 git mergetool --no-prompt --tool myecho -- both >actual &&
663 ! grep ^\./both_LOCAL_ actual >/dev/null &&
664 grep /both_LOCAL_ actual >/dev/null
667 test_expect_success 'diff.orderFile configuration is honored' '
668 test_when_finished "git reset --hard" &&
669 git checkout -b test$test_count order-file-side2 &&
670 test_config diff.orderFile order-file &&
671 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
672 test_config mergetool.myecho.trustExitCode true &&
673 echo b >order-file &&
674 echo a >>order-file &&
675 test_must_fail git merge order-file-side1 &&
676 cat >expect <<-\EOF &&
677 Merging:
682 # make sure "order-file" that is ambiguous between
683 # rev and path is understood correctly.
684 git branch order-file HEAD &&
686 git mergetool --no-prompt --tool myecho >output &&
687 git grep --no-index -h -A2 Merging: output >actual &&
688 test_cmp expect actual
690 test_expect_success 'mergetool -Oorder-file is honored' '
691 test_when_finished "git reset --hard" &&
692 git checkout -b test$test_count order-file-side2 &&
693 test_config diff.orderFile order-file &&
694 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
695 test_config mergetool.myecho.trustExitCode true &&
696 echo b >order-file &&
697 echo a >>order-file &&
698 test_must_fail git merge order-file-side1 &&
699 cat >expect <<-\EOF &&
700 Merging:
704 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
705 git grep --no-index -h -A2 Merging: output >actual &&
706 test_cmp expect actual &&
707 git reset --hard &&
709 git config --unset diff.orderFile &&
710 test_must_fail git merge order-file-side1 &&
711 cat >expect <<-\EOF &&
712 Merging:
716 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
717 git grep --no-index -h -A2 Merging: output >actual &&
718 test_cmp expect actual
721 test_done