]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7610-mergetool.sh
Merge branch 'js/unmap-before-ext-diff' into maint
[thirdparty/git.git] / t / t7610-mergetool.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Charles Bailey
4 #
5
6 test_description='git mergetool
7
8 Testing 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
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 &&
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
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"
146 '
147
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"
168 '
169
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"
187 '
188
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"
212 '
213
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 &&
218 (
219 cd subdir &&
220 test_must_fail git merge master &&
221 ( yes "" | git mergetool file3 ) &&
222 test "$(cat file3)" = "master new sub"
223 )
224 '
225
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 &&
230 (
231 cd subdir &&
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"
244 )
245 '
246
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"
258 '
259
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 &&
264 (
265 cd subdir &&
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"
275 )
276 '
277
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 &&
283 (
284 cd subdir &&
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"
294 )
295 '
296
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"
309 '
310
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 &&
316 git stash &&
317
318 git checkout --detach stash2 &&
319 test_must_fail git stash apply &&
320
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" &&
326
327 git commit -am "save the stash resolution" &&
328
329 git reset --hard stash2 &&
330 test_must_fail git stash apply &&
331
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"
337 '
338
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 &&
345
346 ( yes "" | git mergetool subdir ) &&
347
348 test "$(cat subdir/file3)" = "master new sub"
349 '
350
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 &&
357 git reset --hard &&
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 &&
361 git reset --hard &&
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
365 '
366
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 &&
374 ! test -d a
375 '
376
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 &&
383 ! test -d a
384 '
385
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 &&
393 test -d a/a &&
394 cat >expect <<-\EOF &&
395 file_BASE_.txt
396 file_LOCAL_.txt
397 file_REMOTE_.txt
398 EOF
399 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
400 test_cmp expect actual
401 '
402
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" &&
424
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 ) &&
434 test ! -e submod &&
435 output="$(git mergetool --no-prompt)" &&
436 test "$output" = "No files need merging" &&
437 git commit -m "Merge resolved by deleting module" &&
438
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 ) &&
448 test ! -e 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 &&
455
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"
470 '
471
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 &&
479 git add 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" &&
495
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" &&
509
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" &&
526
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"
542 '
543
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 &&
548 (
549 cd subdir &&
550 test_create_repo subdir_module &&
551 (
552 cd subdir_module &&
553 : >file15 &&
554 git add file15 &&
555 git commit -m "add initial versions"
556 )
557 ) &&
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" &&
562
563 git checkout -b test$test_count.a test$test_count &&
564 git submodule update -N &&
565 (
566 cd subdir/subdir_module &&
567 git checkout -b super10.a &&
568 echo test$test_count.a >file15 &&
569 git add file15 &&
570 git commit -m "on branch 10.a"
571 ) &&
572 git add subdir/subdir_module &&
573 git commit -m "change submodule in subdirectory on test$test_count.a" &&
574
575 git checkout -b test$test_count.b test$test_count &&
576 git submodule update -N &&
577 (
578 cd subdir/subdir_module &&
579 git checkout -b super10.b &&
580 echo test$test_count.b >file15 &&
581 git add file15 &&
582 git commit -m "on branch 10.b"
583 ) &&
584 git add subdir/subdir_module &&
585 git commit -m "change submodule in subdirectory on test$test_count.b" &&
586
587 test_must_fail git merge test$test_count.a &&
588 (
589 cd subdir &&
590 ( yes "l" | git mergetool subdir_module )
591 ) &&
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" &&
595 git reset --hard &&
596 git submodule update -N &&
597
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"
604 '
605
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 &&
611 mkdir submod &&
612 echo not a submodule >submod/file16 &&
613 git add submod/file16 &&
614 git commit -m "Submodule path becomes directory" &&
615
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 &&
621
622 git reset --hard &&
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" &&
629 rm -r submod.orig &&
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" &&
634 git reset --hard &&
635 rm -rf submod-movedaside &&
636
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" &&
644
645 git reset --hard &&
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" &&
652
653 git reset --hard master &&
654 ( cd submod && git clean -f && git reset --hard ) &&
655 git submodule update -N
656 '
657
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
664 '
665
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
675 '
676
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
686 '
687
688 test_lazy_prereq MKTEMP '
689 tempdir=$(mktemp -d -t foo.XXXXXX) &&
690 test -d "$tempdir" &&
691 rmdir "$tempdir"
692 '
693
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
704 '
705
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 &&
716 Merging:
717 b
718 a
719 EOF
720
721 # make sure "order-file" that is ambiguous between
722 # rev and path is understood correctly.
723 git branch order-file HEAD &&
724
725 git mergetool --no-prompt --tool myecho >output &&
726 git grep --no-index -h -A2 Merging: output >actual &&
727 test_cmp expect actual
728 '
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 &&
739 Merging:
740 a
741 b
742 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 &&
746 git reset --hard &&
747
748 git config --unset diff.orderFile &&
749 test_must_fail git merge order-file-side1 &&
750 cat >expect <<-\EOF &&
751 Merging:
752 b
753 a
754 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
758 '
759
760 test_done