3 # Copyright (c) 2008 Charles Bailey
6 test_description='git mergetool
8 Testing basic merge tool invocation'
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
16 test_expect_success 'setup' '
17 test_config rerere.enabled true &&
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 &&
25 echo master sub >subdir/file3 &&
26 test_create_repo submod &&
31 git commit -m "Add foo"
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 &&
48 echo branch1 submodule >bar &&
50 git commit -m "Add bar on branch1" &&
51 git checkout -b submod-branch1
53 git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
56 git commit -m "branch1 changes" &&
58 git checkout -b delete-base branch1 &&
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 &&
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 &&
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" &&
74 git checkout -b stash1 master &&
75 echo stash1 change file11 >file11 &&
77 git commit -m "stash1 changes" &&
79 git checkout -b stash2 master &&
80 echo stash2 change file11 >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 &&
95 echo master submodule >bar &&
97 git commit -m "Add bar on master" &&
98 git checkout -b submod-master
100 git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
103 git commit -m "master updates" &&
106 git checkout -b order-file-start master &&
110 git commit -m start &&
111 git checkout -b order-file-side1 order-file-start &&
115 git commit -m side1 &&
116 git checkout -b order-file-side2 order-file-start &&
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 &&
134 ( yes "" | git mergetool both ) &&
135 ( yes "" | git mergetool file1 file1 ) &&
136 ( yes "" | git mergetool file2 "spaced name" ) &&
137 ( yes "" | git mergetool subdir/file3 ) &&
138 ( yes "d" | git mergetool file11 ) &&
139 ( yes "d" | git mergetool file12 ) &&
140 ( yes "l" | git mergetool submod ) &&
141 test "$(cat file1)" = "master updated" &&
142 test "$(cat file2)" = "master new" &&
143 test "$(cat subdir/file3)" = "master new sub" &&
144 test "$(cat submod/bar)" = "branch1 submodule" &&
145 git commit -m "branch1 resolved with mergetool"
148 test_expect_success 'gui mergetool' '
149 test_config merge.guitool myguitool &&
150 test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
151 test_config mergetool.myguitool.trustExitCode true &&
152 test_when_finished "git reset --hard" &&
153 git checkout -b test$test_count branch1 &&
154 git submodule update -N &&
155 test_must_fail git merge master &&
156 ( yes "" | git mergetool --gui both ) &&
157 ( yes "" | git mergetool -g file1 file1 ) &&
158 ( yes "" | git mergetool --gui file2 "spaced name" ) &&
159 ( yes "" | git mergetool --gui subdir/file3 ) &&
160 ( yes "d" | git mergetool --gui file11 ) &&
161 ( yes "d" | git mergetool --gui file12 ) &&
162 ( yes "l" | git mergetool --gui submod ) &&
163 test "$(cat file1)" = "gui master updated" &&
164 test "$(cat file2)" = "gui master new" &&
165 test "$(cat subdir/file3)" = "gui master new sub" &&
166 test "$(cat submod/bar)" = "branch1 submodule" &&
167 git commit -m "branch1 resolved with mergetool"
170 test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' '
171 test_when_finished "git reset --hard" &&
172 git checkout -b test$test_count branch1 &&
173 git submodule update -N &&
174 test_must_fail git merge master &&
175 ( yes "" | git mergetool --gui both ) &&
176 ( yes "" | git mergetool -g file1 file1 ) &&
177 ( yes "" | git mergetool --gui file2 "spaced name" ) &&
178 ( yes "" | git mergetool --gui subdir/file3 ) &&
179 ( yes "d" | git mergetool --gui file11 ) &&
180 ( yes "d" | git mergetool --gui file12 ) &&
181 ( yes "l" | git mergetool --gui submod ) &&
182 test "$(cat file1)" = "master updated" &&
183 test "$(cat file2)" = "master new" &&
184 test "$(cat subdir/file3)" = "master new sub" &&
185 test "$(cat submod/bar)" = "branch1 submodule" &&
186 git commit -m "branch1 resolved with mergetool"
189 test_expect_success 'mergetool crlf' '
190 test_when_finished "git reset --hard" &&
191 # This test_config line must go after the above reset line so that
192 # core.autocrlf is unconfigured before reset runs. (The
193 # test_config command uses test_when_finished internally and
194 # test_when_finished is LIFO.)
195 test_config core.autocrlf true &&
196 git checkout -b test$test_count branch1 &&
197 test_must_fail git merge master &&
198 ( yes "" | git mergetool file1 ) &&
199 ( yes "" | git mergetool file2 ) &&
200 ( yes "" | git mergetool "spaced name" ) &&
201 ( yes "" | git mergetool both ) &&
202 ( yes "" | git mergetool subdir/file3 ) &&
203 ( yes "d" | git mergetool file11 ) &&
204 ( yes "d" | git mergetool file12 ) &&
205 ( yes "r" | git mergetool submod ) &&
206 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
207 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
208 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
209 git submodule update -N &&
210 test "$(cat submod/bar)" = "master submodule" &&
211 git commit -m "branch1 resolved with mergetool - autocrlf"
214 test_expect_success 'mergetool in subdir' '
215 test_when_finished "git reset --hard" &&
216 git checkout -b test$test_count branch1 &&
217 git submodule update -N &&
220 test_must_fail git merge master &&
221 ( yes "" | git mergetool file3 ) &&
222 test "$(cat file3)" = "master new sub"
226 test_expect_success 'mergetool on file in parent dir' '
227 test_when_finished "git reset --hard" &&
228 git checkout -b test$test_count branch1 &&
229 git submodule update -N &&
232 test_must_fail git merge master &&
233 ( yes "" | git mergetool file3 ) &&
234 ( yes "" | git mergetool ../file1 ) &&
235 ( yes "" | git mergetool ../file2 ../spaced\ name ) &&
236 ( yes "" | git mergetool ../both ) &&
237 ( yes "d" | git mergetool ../file11 ) &&
238 ( yes "d" | git mergetool ../file12 ) &&
239 ( yes "l" | git mergetool ../submod ) &&
240 test "$(cat ../file1)" = "master updated" &&
241 test "$(cat ../file2)" = "master new" &&
242 test "$(cat ../submod/bar)" = "branch1 submodule" &&
243 git commit -m "branch1 resolved with mergetool - subdir"
247 test_expect_success 'mergetool skips autoresolved' '
248 test_when_finished "git reset --hard" &&
249 git checkout -b test$test_count branch1 &&
250 git submodule update -N &&
251 test_must_fail git merge master &&
252 test -n "$(git ls-files -u)" &&
253 ( yes "d" | git mergetool file11 ) &&
254 ( yes "d" | git mergetool file12 ) &&
255 ( yes "l" | git mergetool submod ) &&
256 output="$(git mergetool --no-prompt)" &&
257 test "$output" = "No files need merging"
260 test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
261 test_when_finished "git reset --hard" &&
262 git checkout -b test$test_count branch1 &&
263 test_config rerere.enabled false &&
266 test_must_fail git merge master &&
267 ( yes "r" | git mergetool ../submod ) &&
268 ( yes "d" "d" | git mergetool --no-prompt ) &&
269 test "$(cat ../file1)" = "master updated" &&
270 test "$(cat ../file2)" = "master new" &&
271 test "$(cat file3)" = "master new sub" &&
272 ( cd .. && git submodule update -N ) &&
273 test "$(cat ../submod/bar)" = "master submodule" &&
274 git commit -m "branch2 resolved by mergetool from subdir"
278 test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
279 test_when_finished "git reset --hard" &&
280 git checkout -b test$test_count branch1 &&
281 test_config rerere.enabled true &&
282 rm -rf .git/rr-cache &&
285 test_must_fail git merge master &&
286 ( yes "r" | git mergetool ../submod ) &&
287 ( yes "d" "d" | git mergetool --no-prompt ) &&
288 test "$(cat ../file1)" = "master updated" &&
289 test "$(cat ../file2)" = "master new" &&
290 test "$(cat file3)" = "master new sub" &&
291 ( cd .. && git submodule update -N ) &&
292 test "$(cat ../submod/bar)" = "master submodule" &&
293 git commit -m "branch2 resolved by mergetool from subdir"
297 test_expect_success 'mergetool skips resolved paths when rerere is active' '
298 test_when_finished "git reset --hard" &&
299 test_config rerere.enabled true &&
300 rm -rf .git/rr-cache &&
301 git checkout -b test$test_count branch1 &&
302 git submodule update -N &&
303 test_must_fail git merge master &&
304 ( yes "l" | git mergetool --no-prompt submod ) &&
305 ( yes "d" "d" | git mergetool --no-prompt ) &&
306 git submodule update -N &&
307 output="$(yes "n" | git mergetool --no-prompt)" &&
308 test "$output" = "No files need merging"
311 test_expect_success 'conflicted stash sets up rerere' '
312 test_when_finished "git reset --hard" &&
313 test_config rerere.enabled true &&
314 git checkout stash1 &&
315 echo "Conflicting stash content" >file11 &&
318 git checkout --detach stash2 &&
319 test_must_fail git stash apply &&
321 test -n "$(git ls-files -u)" &&
322 conflicts="$(git rerere remaining)" &&
323 test "$conflicts" = "file11" &&
324 output="$(git mergetool --no-prompt)" &&
325 test "$output" != "No files need merging" &&
327 git commit -am "save the stash resolution" &&
329 git reset --hard stash2 &&
330 test_must_fail git stash apply &&
332 test -n "$(git ls-files -u)" &&
333 conflicts="$(git rerere remaining)" &&
334 test -z "$conflicts" &&
335 output="$(git mergetool --no-prompt)" &&
336 test "$output" = "No files need merging"
339 test_expect_success 'mergetool takes partial path' '
340 test_when_finished "git reset --hard" &&
341 test_config rerere.enabled false &&
342 git checkout -b test$test_count branch1 &&
343 git submodule update -N &&
344 test_must_fail git merge master &&
346 ( yes "" | git mergetool subdir ) &&
348 test "$(cat subdir/file3)" = "master new sub"
351 test_expect_success 'mergetool delete/delete conflict' '
352 test_when_finished "git reset --hard" &&
353 git checkout -b test$test_count move-to-c &&
354 test_must_fail git merge move-to-b &&
355 echo d | git mergetool a/a/file.txt &&
356 ! test -f a/a/file.txt &&
358 test_must_fail git merge move-to-b &&
359 echo m | git mergetool a/a/file.txt &&
360 test -f b/b/file.txt &&
362 test_must_fail git merge move-to-b &&
363 ! echo a | git mergetool a/a/file.txt &&
364 ! test -f a/a/file.txt
367 test_expect_success 'mergetool produces no errors when keepBackup is used' '
368 test_when_finished "git reset --hard" &&
369 git checkout -b test$test_count move-to-c &&
370 test_config mergetool.keepBackup true &&
371 test_must_fail git merge move-to-b &&
372 echo d | git mergetool a/a/file.txt 2>actual &&
373 test_must_be_empty actual &&
377 test_expect_success 'mergetool honors tempfile config for deleted files' '
378 test_when_finished "git reset --hard" &&
379 git checkout -b test$test_count move-to-c &&
380 test_config mergetool.keepTemporaries false &&
381 test_must_fail git merge move-to-b &&
382 echo d | git mergetool a/a/file.txt &&
386 test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
387 test_when_finished "git reset --hard" &&
388 test_when_finished "git clean -fdx" &&
389 git checkout -b test$test_count move-to-c &&
390 test_config mergetool.keepTemporaries true &&
391 test_must_fail git merge move-to-b &&
392 ! test_write_lines a n | git mergetool a/a/file.txt &&
394 cat >expect <<-\EOF &&
399 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
400 test_cmp expect actual
403 test_expect_success 'deleted vs modified submodule' '
404 test_when_finished "git reset --hard" &&
405 git checkout -b test$test_count branch1 &&
406 git submodule update -N &&
407 mv submod submod-movedaside &&
408 git rm --cached submod &&
409 git commit -m "Submodule deleted from branch" &&
410 git checkout -b test$test_count.a test$test_count &&
411 test_must_fail git merge master &&
412 test -n "$(git ls-files -u)" &&
413 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
414 ( yes "" | git mergetool both ) &&
415 ( yes "d" | git mergetool file11 file12 ) &&
416 ( yes "r" | git mergetool submod ) &&
417 rmdir submod && mv submod-movedaside submod &&
418 test "$(cat submod/bar)" = "branch1 submodule" &&
419 git submodule update -N &&
420 test "$(cat submod/bar)" = "master submodule" &&
421 output="$(git mergetool --no-prompt)" &&
422 test "$output" = "No files need merging" &&
423 git commit -m "Merge resolved by keeping module" &&
425 mv submod submod-movedaside &&
426 git checkout -b test$test_count.b test$test_count &&
427 git submodule update -N &&
428 test_must_fail git merge master &&
429 test -n "$(git ls-files -u)" &&
430 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
431 ( yes "" | git mergetool both ) &&
432 ( yes "d" | git mergetool file11 file12 ) &&
433 ( yes "l" | git mergetool submod ) &&
435 output="$(git mergetool --no-prompt)" &&
436 test "$output" = "No files need merging" &&
437 git commit -m "Merge resolved by deleting module" &&
439 mv submod-movedaside submod &&
440 git checkout -b test$test_count.c master &&
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 ) &&
445 ( yes "" | git mergetool both ) &&
446 ( yes "d" | git mergetool file11 file12 ) &&
447 ( yes "r" | git mergetool submod ) &&
449 test -d submod.orig &&
450 git submodule update -N &&
451 output="$(git mergetool --no-prompt)" &&
452 test "$output" = "No files need merging" &&
453 git commit -m "Merge resolved by deleting module" &&
454 mv submod.orig submod &&
456 git checkout -b test$test_count.d master &&
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 ) &&
461 ( yes "" | git mergetool both ) &&
462 ( yes "d" | git mergetool file11 file12 ) &&
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"
472 test_expect_success 'file vs modified submodule' '
473 test_when_finished "git reset --hard" &&
474 git checkout -b test$test_count branch1 &&
475 git submodule update -N &&
476 mv submod submod-movedaside &&
477 git rm --cached submod &&
478 echo not a submodule >submod &&
480 git commit -m "Submodule path becomes file" &&
481 git checkout -b test$test_count.a branch1 &&
482 test_must_fail git merge master &&
483 test -n "$(git ls-files -u)" &&
484 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
485 ( yes "" | git mergetool both ) &&
486 ( yes "d" | git mergetool file11 file12 ) &&
487 ( yes "r" | git mergetool submod ) &&
488 rmdir submod && mv submod-movedaside submod &&
489 test "$(cat submod/bar)" = "branch1 submodule" &&
490 git submodule update -N &&
491 test "$(cat submod/bar)" = "master submodule" &&
492 output="$(git mergetool --no-prompt)" &&
493 test "$output" = "No files need merging" &&
494 git commit -m "Merge resolved by keeping module" &&
496 mv submod submod-movedaside &&
497 git checkout -b test$test_count.b test$test_count &&
498 test_must_fail git merge master &&
499 test -n "$(git ls-files -u)" &&
500 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
501 ( yes "" | git mergetool both ) &&
502 ( yes "d" | git mergetool file11 file12 ) &&
503 ( yes "l" | git mergetool submod ) &&
504 git submodule update -N &&
505 test "$(cat submod)" = "not a submodule" &&
506 output="$(git mergetool --no-prompt)" &&
507 test "$output" = "No files need merging" &&
508 git commit -m "Merge resolved by keeping file" &&
510 git checkout -b test$test_count.c master &&
511 rmdir submod && mv submod-movedaside submod &&
512 test ! -e submod.orig &&
513 git submodule update -N &&
514 test_must_fail git merge test$test_count &&
515 test -n "$(git ls-files -u)" &&
516 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
517 ( yes "" | git mergetool both ) &&
518 ( yes "d" | git mergetool file11 file12 ) &&
519 ( yes "r" | git mergetool submod ) &&
520 test -d submod.orig &&
521 git submodule update -N &&
522 test "$(cat submod)" = "not a submodule" &&
523 output="$(git mergetool --no-prompt)" &&
524 test "$output" = "No files need merging" &&
525 git commit -m "Merge resolved by keeping file" &&
527 git checkout -b test$test_count.d master &&
528 rmdir submod && mv submod.orig submod &&
529 git submodule update -N &&
530 test_must_fail git merge test$test_count &&
531 test -n "$(git ls-files -u)" &&
532 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
533 ( yes "" | git mergetool both ) &&
534 ( yes "d" | git mergetool file11 file12 ) &&
535 ( yes "l" | git mergetool submod ) &&
536 test "$(cat submod/bar)" = "master submodule" &&
537 git submodule update -N &&
538 test "$(cat submod/bar)" = "master submodule" &&
539 output="$(git mergetool --no-prompt)" &&
540 test "$output" = "No files need merging" &&
541 git commit -m "Merge resolved by keeping module"
544 test_expect_success 'submodule in subdirectory' '
545 test_when_finished "git reset --hard" &&
546 git checkout -b test$test_count branch1 &&
547 git submodule update -N &&
550 test_create_repo subdir_module &&
555 git commit -m "add initial versions"
558 test_when_finished "rm -rf subdir/subdir_module" &&
559 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
560 git add subdir/subdir_module &&
561 git commit -m "add submodule in subdirectory" &&
563 git checkout -b test$test_count.a test$test_count &&
564 git submodule update -N &&
566 cd subdir/subdir_module &&
567 git checkout -b super10.a &&
568 echo test$test_count.a >file15 &&
570 git commit -m "on branch 10.a"
572 git add subdir/subdir_module &&
573 git commit -m "change submodule in subdirectory on test$test_count.a" &&
575 git checkout -b test$test_count.b test$test_count &&
576 git submodule update -N &&
578 cd subdir/subdir_module &&
579 git checkout -b super10.b &&
580 echo test$test_count.b >file15 &&
582 git commit -m "on branch 10.b"
584 git add subdir/subdir_module &&
585 git commit -m "change submodule in subdirectory on test$test_count.b" &&
587 test_must_fail git merge test$test_count.a &&
590 ( yes "l" | git mergetool subdir_module )
592 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
593 git submodule update -N &&
594 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
596 git submodule update -N &&
598 test_must_fail git merge test$test_count.a &&
599 ( yes "r" | git mergetool subdir/subdir_module ) &&
600 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
601 git submodule update -N &&
602 test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
603 git commit -m "branch1 resolved with mergetool"
606 test_expect_success 'directory vs modified submodule' '
607 test_when_finished "git reset --hard" &&
608 git checkout -b test$test_count branch1 &&
609 mv submod submod-movedaside &&
610 git rm --cached submod &&
612 echo not a submodule >submod/file16 &&
613 git add submod/file16 &&
614 git commit -m "Submodule path becomes directory" &&
616 test_must_fail git merge master &&
617 test -n "$(git ls-files -u)" &&
618 ( yes "l" | git mergetool submod ) &&
619 test "$(cat submod/file16)" = "not a submodule" &&
620 rm -rf submod.orig &&
623 test_must_fail git merge master &&
624 test -n "$(git ls-files -u)" &&
625 test ! -e submod.orig &&
626 ( yes "r" | git mergetool submod ) &&
627 test -d submod.orig &&
628 test "$(cat submod.orig/file16)" = "not a submodule" &&
630 mv submod-movedaside/.git submod &&
631 ( cd submod && git clean -f && git reset --hard ) &&
632 git submodule update -N &&
633 test "$(cat submod/bar)" = "master submodule" &&
635 rm -rf submod-movedaside &&
637 git checkout -b test$test_count.c master &&
638 git submodule update -N &&
639 test_must_fail git merge test$test_count &&
640 test -n "$(git ls-files -u)" &&
641 ( yes "l" | git mergetool submod ) &&
642 git submodule update -N &&
643 test "$(cat submod/bar)" = "master submodule" &&
646 git submodule update -N &&
647 test_must_fail git merge test$test_count &&
648 test -n "$(git ls-files -u)" &&
649 test ! -e submod.orig &&
650 ( yes "r" | git mergetool submod ) &&
651 test "$(cat submod/file16)" = "not a submodule" &&
653 git reset --hard master &&
654 ( cd submod && git clean -f && git reset --hard ) &&
655 git submodule update -N
658 test_expect_success 'file with no base' '
659 test_when_finished "git reset --hard" &&
660 git checkout -b test$test_count branch1 &&
661 test_must_fail git merge master &&
662 git mergetool --no-prompt --tool mybase -- both &&
663 test_must_be_empty both
666 test_expect_success 'custom commands override built-ins' '
667 test_when_finished "git reset --hard" &&
668 git checkout -b test$test_count branch1 &&
669 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
670 test_config mergetool.defaults.trustExitCode true &&
671 test_must_fail git merge master &&
672 git mergetool --no-prompt --tool defaults -- both &&
673 echo master both added >expected &&
674 test_cmp expected both
677 test_expect_success 'filenames seen by tools start with ./' '
678 test_when_finished "git reset --hard" &&
679 git checkout -b test$test_count branch1 &&
680 test_config mergetool.writeToTemp false &&
681 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
682 test_config mergetool.myecho.trustExitCode true &&
683 test_must_fail git merge master &&
684 git mergetool --no-prompt --tool myecho -- both >actual &&
685 grep ^\./both_LOCAL_ actual
688 test_lazy_prereq MKTEMP '
689 tempdir=$(mktemp -d -t foo.XXXXXX) &&
690 test -d "$tempdir" &&
694 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
695 test_when_finished "git reset --hard" &&
696 git checkout -b test$test_count branch1 &&
697 test_config mergetool.writeToTemp true &&
698 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
699 test_config mergetool.myecho.trustExitCode true &&
700 test_must_fail git merge master &&
701 git mergetool --no-prompt --tool myecho -- both >actual &&
702 ! grep ^\./both_LOCAL_ actual &&
703 grep /both_LOCAL_ actual
706 test_expect_success 'diff.orderFile configuration is honored' '
707 test_when_finished "git reset --hard" &&
708 git checkout -b test$test_count order-file-side2 &&
709 test_config diff.orderFile order-file &&
710 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
711 test_config mergetool.myecho.trustExitCode true &&
712 echo b >order-file &&
713 echo a >>order-file &&
714 test_must_fail git merge order-file-side1 &&
715 cat >expect <<-\EOF &&
721 # make sure "order-file" that is ambiguous between
722 # rev and path is understood correctly.
723 git branch order-file HEAD &&
725 git mergetool --no-prompt --tool myecho >output &&
726 git grep --no-index -h -A2 Merging: output >actual &&
727 test_cmp expect actual
729 test_expect_success 'mergetool -Oorder-file is honored' '
730 test_when_finished "git reset --hard" &&
731 git checkout -b test$test_count order-file-side2 &&
732 test_config diff.orderFile order-file &&
733 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
734 test_config mergetool.myecho.trustExitCode true &&
735 echo b >order-file &&
736 echo a >>order-file &&
737 test_must_fail git merge order-file-side1 &&
738 cat >expect <<-\EOF &&
743 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
744 git grep --no-index -h -A2 Merging: output >actual &&
745 test_cmp expect actual &&
748 git config --unset diff.orderFile &&
749 test_must_fail git merge order-file-side1 &&
750 cat >expect <<-\EOF &&
755 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
756 git grep --no-index -h -A2 Merging: output >actual &&
757 test_cmp expect actual