]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7610-mergetool.sh
Merge branch 'js/mingw-spawn-with-spaces-in-path'
[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 echo "master updated" >expect &&
142 test_cmp expect file1 &&
143 echo "master new" >expect &&
144 test_cmp expect file2 &&
145 echo "master new sub" >expect &&
146 test_cmp expect subdir/file3 &&
147 echo "branch1 submodule" >expect &&
148 test_cmp expect submod/bar &&
149 git commit -m "branch1 resolved with mergetool"
150 '
151
152 test_expect_success 'gui mergetool' '
153 test_config merge.guitool myguitool &&
154 test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
155 test_config mergetool.myguitool.trustExitCode true &&
156 test_when_finished "git reset --hard" &&
157 git checkout -b test$test_count branch1 &&
158 git submodule update -N &&
159 test_must_fail git merge master &&
160 yes "" | git mergetool --gui both &&
161 yes "" | git mergetool -g file1 file1 &&
162 yes "" | git mergetool --gui file2 "spaced name" &&
163 yes "" | git mergetool --gui subdir/file3 &&
164 yes "d" | git mergetool --gui file11 &&
165 yes "d" | git mergetool --gui file12 &&
166 yes "l" | git mergetool --gui submod &&
167 echo "gui master updated" >expect &&
168 test_cmp expect file1 &&
169 echo "gui master new" >expect &&
170 test_cmp expect file2 &&
171 echo "gui master new sub" >expect &&
172 test_cmp expect subdir/file3 &&
173 echo "branch1 submodule" >expect &&
174 test_cmp expect submod/bar &&
175 git commit -m "branch1 resolved with mergetool"
176 '
177
178 test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' '
179 test_when_finished "git reset --hard" &&
180 git checkout -b test$test_count branch1 &&
181 git submodule update -N &&
182 test_must_fail git merge master &&
183 yes "" | git mergetool --gui both &&
184 yes "" | git mergetool -g file1 file1 &&
185 yes "" | git mergetool --gui file2 "spaced name" &&
186 yes "" | git mergetool --gui subdir/file3 &&
187 yes "d" | git mergetool --gui file11 &&
188 yes "d" | git mergetool --gui file12 &&
189 yes "l" | git mergetool --gui submod &&
190 echo "master updated" >expect &&
191 test_cmp expect file1 &&
192 echo "master new" >expect &&
193 test_cmp expect file2 &&
194 echo "master new sub" >expect &&
195 test_cmp expect subdir/file3 &&
196 echo "branch1 submodule" >expect &&
197 test_cmp expect submod/bar &&
198 git commit -m "branch1 resolved with mergetool"
199 '
200
201 test_expect_success 'mergetool crlf' '
202 test_when_finished "git reset --hard" &&
203 # This test_config line must go after the above reset line so that
204 # core.autocrlf is unconfigured before reset runs. (The
205 # test_config command uses test_when_finished internally and
206 # test_when_finished is LIFO.)
207 test_config core.autocrlf true &&
208 git checkout -b test$test_count branch1 &&
209 test_must_fail git merge master &&
210 yes "" | git mergetool file1 &&
211 yes "" | git mergetool file2 &&
212 yes "" | git mergetool "spaced name" &&
213 yes "" | git mergetool both &&
214 yes "" | git mergetool subdir/file3 &&
215 yes "d" | git mergetool file11 &&
216 yes "d" | git mergetool file12 &&
217 yes "r" | git mergetool submod &&
218 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
219 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
220 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
221 git submodule update -N &&
222 echo "master submodule" >expect &&
223 test_cmp expect submod/bar &&
224 git commit -m "branch1 resolved with mergetool - autocrlf"
225 '
226
227 test_expect_success 'mergetool in subdir' '
228 test_when_finished "git reset --hard" &&
229 git checkout -b test$test_count branch1 &&
230 git submodule update -N &&
231 (
232 cd subdir &&
233 test_must_fail git merge master &&
234 yes "" | git mergetool file3 &&
235 echo "master new sub" >expect &&
236 test_cmp expect file3
237 )
238 '
239
240 test_expect_success 'mergetool on file in parent dir' '
241 test_when_finished "git reset --hard" &&
242 git checkout -b test$test_count branch1 &&
243 git submodule update -N &&
244 (
245 cd subdir &&
246 test_must_fail git merge master &&
247 yes "" | git mergetool file3 &&
248 yes "" | git mergetool ../file1 &&
249 yes "" | git mergetool ../file2 ../spaced\ name &&
250 yes "" | git mergetool ../both &&
251 yes "d" | git mergetool ../file11 &&
252 yes "d" | git mergetool ../file12 &&
253 yes "l" | git mergetool ../submod &&
254 echo "master updated" >expect &&
255 test_cmp expect ../file1 &&
256 echo "master new" >expect &&
257 test_cmp expect ../file2 &&
258 echo "branch1 submodule" >expect &&
259 test_cmp expect ../submod/bar &&
260 git commit -m "branch1 resolved with mergetool - subdir"
261 )
262 '
263
264 test_expect_success 'mergetool skips autoresolved' '
265 test_when_finished "git reset --hard" &&
266 git checkout -b test$test_count branch1 &&
267 git submodule update -N &&
268 test_must_fail git merge master &&
269 test -n "$(git ls-files -u)" &&
270 yes "d" | git mergetool file11 &&
271 yes "d" | git mergetool file12 &&
272 yes "l" | git mergetool submod &&
273 output="$(git mergetool --no-prompt)" &&
274 test "$output" = "No files need merging"
275 '
276
277 test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
278 test_when_finished "git reset --hard" &&
279 git checkout -b test$test_count branch1 &&
280 test_config rerere.enabled false &&
281 (
282 cd subdir &&
283 test_must_fail git merge master &&
284 yes "r" | git mergetool ../submod &&
285 yes "d" "d" | git mergetool --no-prompt &&
286 echo "master updated" >expect &&
287 test_cmp expect ../file1 &&
288 echo "master new" >expect &&
289 test_cmp expect ../file2 &&
290 echo "master new sub" >expect &&
291 test_cmp expect file3 &&
292 ( cd .. && git submodule update -N ) &&
293 echo "master submodule" >expect &&
294 test_cmp expect ../submod/bar &&
295 git commit -m "branch2 resolved by mergetool from subdir"
296 )
297 '
298
299 test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
300 test_when_finished "git reset --hard" &&
301 git checkout -b test$test_count branch1 &&
302 test_config rerere.enabled true &&
303 rm -rf .git/rr-cache &&
304 (
305 cd subdir &&
306 test_must_fail git merge master &&
307 yes "r" | git mergetool ../submod &&
308 yes "d" "d" | git mergetool --no-prompt &&
309 echo "master updated" >expect &&
310 test_cmp expect ../file1 &&
311 echo "master new" >expect &&
312 test_cmp expect ../file2 &&
313 echo "master new sub" >expect &&
314 test_cmp expect file3 &&
315 ( cd .. && git submodule update -N ) &&
316 echo "master submodule" >expect &&
317 test_cmp expect ../submod/bar &&
318 git commit -m "branch2 resolved by mergetool from subdir"
319 )
320 '
321
322 test_expect_success 'mergetool skips resolved paths when rerere is active' '
323 test_when_finished "git reset --hard" &&
324 test_config rerere.enabled true &&
325 rm -rf .git/rr-cache &&
326 git checkout -b test$test_count branch1 &&
327 git submodule update -N &&
328 test_must_fail git merge master &&
329 yes "l" | git mergetool --no-prompt submod &&
330 yes "d" "d" | git mergetool --no-prompt &&
331 git submodule update -N &&
332 output="$(yes "n" | git mergetool --no-prompt)" &&
333 test "$output" = "No files need merging"
334 '
335
336 test_expect_success 'conflicted stash sets up rerere' '
337 test_when_finished "git reset --hard" &&
338 test_config rerere.enabled true &&
339 git checkout stash1 &&
340 echo "Conflicting stash content" >file11 &&
341 git stash &&
342
343 git checkout --detach stash2 &&
344 test_must_fail git stash apply &&
345
346 test -n "$(git ls-files -u)" &&
347 conflicts="$(git rerere remaining)" &&
348 test "$conflicts" = "file11" &&
349 output="$(git mergetool --no-prompt)" &&
350 test "$output" != "No files need merging" &&
351
352 git commit -am "save the stash resolution" &&
353
354 git reset --hard stash2 &&
355 test_must_fail git stash apply &&
356
357 test -n "$(git ls-files -u)" &&
358 conflicts="$(git rerere remaining)" &&
359 test -z "$conflicts" &&
360 output="$(git mergetool --no-prompt)" &&
361 test "$output" = "No files need merging"
362 '
363
364 test_expect_success 'mergetool takes partial path' '
365 test_when_finished "git reset --hard" &&
366 test_config rerere.enabled false &&
367 git checkout -b test$test_count branch1 &&
368 git submodule update -N &&
369 test_must_fail git merge master &&
370
371 yes "" | git mergetool subdir &&
372
373 echo "master new sub" >expect &&
374 test_cmp expect subdir/file3
375 '
376
377 test_expect_success 'mergetool delete/delete conflict' '
378 test_when_finished "git reset --hard" &&
379 git checkout -b test$test_count move-to-c &&
380 test_must_fail git merge move-to-b &&
381 echo d | git mergetool a/a/file.txt &&
382 ! test -f a/a/file.txt &&
383 git reset --hard &&
384 test_must_fail git merge move-to-b &&
385 echo m | git mergetool a/a/file.txt &&
386 test -f b/b/file.txt &&
387 git reset --hard &&
388 test_must_fail git merge move-to-b &&
389 ! echo a | git mergetool a/a/file.txt &&
390 ! test -f a/a/file.txt
391 '
392
393 test_expect_success 'mergetool produces no errors when keepBackup is used' '
394 test_when_finished "git reset --hard" &&
395 git checkout -b test$test_count move-to-c &&
396 test_config mergetool.keepBackup true &&
397 test_must_fail git merge move-to-b &&
398 echo d | git mergetool a/a/file.txt 2>actual &&
399 test_must_be_empty actual &&
400 ! test -d a
401 '
402
403 test_expect_success 'mergetool honors tempfile config for deleted files' '
404 test_when_finished "git reset --hard" &&
405 git checkout -b test$test_count move-to-c &&
406 test_config mergetool.keepTemporaries false &&
407 test_must_fail git merge move-to-b &&
408 echo d | git mergetool a/a/file.txt &&
409 ! test -d a
410 '
411
412 test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
413 test_when_finished "git reset --hard" &&
414 test_when_finished "git clean -fdx" &&
415 git checkout -b test$test_count move-to-c &&
416 test_config mergetool.keepTemporaries true &&
417 test_must_fail git merge move-to-b &&
418 ! test_write_lines a n | git mergetool a/a/file.txt &&
419 test -d a/a &&
420 cat >expect <<-\EOF &&
421 file_BASE_.txt
422 file_LOCAL_.txt
423 file_REMOTE_.txt
424 EOF
425 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
426 test_cmp expect actual
427 '
428
429 test_expect_success 'deleted vs modified submodule' '
430 test_when_finished "git reset --hard" &&
431 git checkout -b test$test_count branch1 &&
432 git submodule update -N &&
433 mv submod submod-movedaside &&
434 git rm --cached submod &&
435 git commit -m "Submodule deleted from branch" &&
436 git checkout -b test$test_count.a test$test_count &&
437 test_must_fail git merge master &&
438 test -n "$(git ls-files -u)" &&
439 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
440 yes "" | git mergetool both &&
441 yes "d" | git mergetool file11 file12 &&
442 yes "r" | git mergetool submod &&
443 rmdir submod && mv submod-movedaside submod &&
444 echo "branch1 submodule" >expect &&
445 test_cmp expect submod/bar &&
446 git submodule update -N &&
447 echo "master submodule" >expect &&
448 test_cmp expect submod/bar &&
449 output="$(git mergetool --no-prompt)" &&
450 test "$output" = "No files need merging" &&
451 git commit -m "Merge resolved by keeping module" &&
452
453 mv submod submod-movedaside &&
454 git checkout -b test$test_count.b test$test_count &&
455 git submodule update -N &&
456 test_must_fail git merge master &&
457 test -n "$(git ls-files -u)" &&
458 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
459 yes "" | git mergetool both &&
460 yes "d" | git mergetool file11 file12 &&
461 yes "l" | git mergetool submod &&
462 test ! -e submod &&
463 output="$(git mergetool --no-prompt)" &&
464 test "$output" = "No files need merging" &&
465 git commit -m "Merge resolved by deleting module" &&
466
467 mv submod-movedaside submod &&
468 git checkout -b test$test_count.c master &&
469 git submodule update -N &&
470 test_must_fail git merge test$test_count &&
471 test -n "$(git ls-files -u)" &&
472 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
473 yes "" | git mergetool both &&
474 yes "d" | git mergetool file11 file12 &&
475 yes "r" | git mergetool submod &&
476 test ! -e submod &&
477 test -d submod.orig &&
478 git submodule update -N &&
479 output="$(git mergetool --no-prompt)" &&
480 test "$output" = "No files need merging" &&
481 git commit -m "Merge resolved by deleting module" &&
482 mv submod.orig submod &&
483
484 git checkout -b test$test_count.d master &&
485 git submodule update -N &&
486 test_must_fail git merge test$test_count &&
487 test -n "$(git ls-files -u)" &&
488 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
489 yes "" | git mergetool both &&
490 yes "d" | git mergetool file11 file12 &&
491 yes "l" | git mergetool submod &&
492 echo "master submodule" >expect &&
493 test_cmp expect submod/bar &&
494 git submodule update -N &&
495 echo "master submodule" >expect &&
496 test_cmp expect submod/bar &&
497 output="$(git mergetool --no-prompt)" &&
498 test "$output" = "No files need merging" &&
499 git commit -m "Merge resolved by keeping module"
500 '
501
502 test_expect_success 'file vs modified submodule' '
503 test_when_finished "git reset --hard" &&
504 git checkout -b test$test_count branch1 &&
505 git submodule update -N &&
506 mv submod submod-movedaside &&
507 git rm --cached submod &&
508 echo not a submodule >submod &&
509 git add submod &&
510 git commit -m "Submodule path becomes file" &&
511 git checkout -b test$test_count.a branch1 &&
512 test_must_fail git merge master &&
513 test -n "$(git ls-files -u)" &&
514 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
515 yes "" | git mergetool both &&
516 yes "d" | git mergetool file11 file12 &&
517 yes "r" | git mergetool submod &&
518 rmdir submod && mv submod-movedaside submod &&
519 echo "branch1 submodule" >expect &&
520 test_cmp expect submod/bar &&
521 git submodule update -N &&
522 echo "master submodule" >expect &&
523 test_cmp expect submod/bar &&
524 output="$(git mergetool --no-prompt)" &&
525 test "$output" = "No files need merging" &&
526 git commit -m "Merge resolved by keeping module" &&
527
528 mv submod submod-movedaside &&
529 git checkout -b test$test_count.b test$test_count &&
530 test_must_fail git merge master &&
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 git submodule update -N &&
537 echo "not a submodule" >expect &&
538 test_cmp expect submod &&
539 output="$(git mergetool --no-prompt)" &&
540 test "$output" = "No files need merging" &&
541 git commit -m "Merge resolved by keeping file" &&
542
543 git checkout -b test$test_count.c master &&
544 rmdir submod && mv submod-movedaside submod &&
545 test ! -e submod.orig &&
546 git submodule update -N &&
547 test_must_fail git merge test$test_count &&
548 test -n "$(git ls-files -u)" &&
549 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
550 yes "" | git mergetool both &&
551 yes "d" | git mergetool file11 file12 &&
552 yes "r" | git mergetool submod &&
553 test -d submod.orig &&
554 git submodule update -N &&
555 echo "not a submodule" >expect &&
556 test_cmp expect submod &&
557 output="$(git mergetool --no-prompt)" &&
558 test "$output" = "No files need merging" &&
559 git commit -m "Merge resolved by keeping file" &&
560
561 git checkout -b test$test_count.d master &&
562 rmdir submod && mv submod.orig submod &&
563 git submodule update -N &&
564 test_must_fail git merge test$test_count &&
565 test -n "$(git ls-files -u)" &&
566 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
567 yes "" | git mergetool both &&
568 yes "d" | git mergetool file11 file12 &&
569 yes "l" | git mergetool submod &&
570 echo "master submodule" >expect &&
571 test_cmp expect submod/bar &&
572 git submodule update -N &&
573 echo "master submodule" >expect &&
574 test_cmp expect submod/bar &&
575 output="$(git mergetool --no-prompt)" &&
576 test "$output" = "No files need merging" &&
577 git commit -m "Merge resolved by keeping module"
578 '
579
580 test_expect_success 'submodule in subdirectory' '
581 test_when_finished "git reset --hard" &&
582 git checkout -b test$test_count branch1 &&
583 git submodule update -N &&
584 (
585 cd subdir &&
586 test_create_repo subdir_module &&
587 (
588 cd subdir_module &&
589 : >file15 &&
590 git add file15 &&
591 git commit -m "add initial versions"
592 )
593 ) &&
594 test_when_finished "rm -rf subdir/subdir_module" &&
595 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
596 git add subdir/subdir_module &&
597 git commit -m "add submodule in subdirectory" &&
598
599 git checkout -b test$test_count.a test$test_count &&
600 git submodule update -N &&
601 (
602 cd subdir/subdir_module &&
603 git checkout -b super10.a &&
604 echo test$test_count.a >file15 &&
605 git add file15 &&
606 git commit -m "on branch 10.a"
607 ) &&
608 git add subdir/subdir_module &&
609 git commit -m "change submodule in subdirectory on test$test_count.a" &&
610
611 git checkout -b test$test_count.b test$test_count &&
612 git submodule update -N &&
613 (
614 cd subdir/subdir_module &&
615 git checkout -b super10.b &&
616 echo test$test_count.b >file15 &&
617 git add file15 &&
618 git commit -m "on branch 10.b"
619 ) &&
620 git add subdir/subdir_module &&
621 git commit -m "change submodule in subdirectory on test$test_count.b" &&
622
623 test_must_fail git merge test$test_count.a &&
624 (
625 cd subdir &&
626 yes "l" | git mergetool subdir_module
627 ) &&
628 echo "test$test_count.b" >expect &&
629 test_cmp expect subdir/subdir_module/file15 &&
630 git submodule update -N &&
631 echo "test$test_count.b" >expect &&
632 test_cmp expect subdir/subdir_module/file15 &&
633 git reset --hard &&
634 git submodule update -N &&
635
636 test_must_fail git merge test$test_count.a &&
637 yes "r" | git mergetool subdir/subdir_module &&
638 echo "test$test_count.b" >expect &&
639 test_cmp expect subdir/subdir_module/file15 &&
640 git submodule update -N &&
641 echo "test$test_count.a" >expect &&
642 test_cmp expect subdir/subdir_module/file15 &&
643 git commit -m "branch1 resolved with mergetool"
644 '
645
646 test_expect_success 'directory vs modified submodule' '
647 test_when_finished "git reset --hard" &&
648 git checkout -b test$test_count branch1 &&
649 mv submod submod-movedaside &&
650 git rm --cached submod &&
651 mkdir submod &&
652 echo not a submodule >submod/file16 &&
653 git add submod/file16 &&
654 git commit -m "Submodule path becomes directory" &&
655
656 test_must_fail git merge master &&
657 test -n "$(git ls-files -u)" &&
658 yes "l" | git mergetool submod &&
659 echo "not a submodule" >expect &&
660 test_cmp expect submod/file16 &&
661 rm -rf submod.orig &&
662
663 git reset --hard &&
664 test_must_fail git merge master &&
665 test -n "$(git ls-files -u)" &&
666 test ! -e submod.orig &&
667 yes "r" | git mergetool submod &&
668 test -d submod.orig &&
669 echo "not a submodule" >expect &&
670 test_cmp expect submod.orig/file16 &&
671 rm -r submod.orig &&
672 mv submod-movedaside/.git submod &&
673 ( cd submod && git clean -f && git reset --hard ) &&
674 git submodule update -N &&
675 echo "master submodule" >expect &&
676 test_cmp expect submod/bar &&
677 git reset --hard &&
678 rm -rf submod-movedaside &&
679
680 git checkout -b test$test_count.c master &&
681 git submodule update -N &&
682 test_must_fail git merge test$test_count &&
683 test -n "$(git ls-files -u)" &&
684 yes "l" | git mergetool submod &&
685 git submodule update -N &&
686 echo "master submodule" >expect &&
687 test_cmp expect submod/bar &&
688
689 git reset --hard &&
690 git submodule update -N &&
691 test_must_fail git merge test$test_count &&
692 test -n "$(git ls-files -u)" &&
693 test ! -e submod.orig &&
694 yes "r" | git mergetool submod &&
695 echo "not a submodule" >expect &&
696 test_cmp expect submod/file16 &&
697
698 git reset --hard master &&
699 ( cd submod && git clean -f && git reset --hard ) &&
700 git submodule update -N
701 '
702
703 test_expect_success 'file with no base' '
704 test_when_finished "git reset --hard" &&
705 git checkout -b test$test_count branch1 &&
706 test_must_fail git merge master &&
707 git mergetool --no-prompt --tool mybase -- both &&
708 test_must_be_empty both
709 '
710
711 test_expect_success 'custom commands override built-ins' '
712 test_when_finished "git reset --hard" &&
713 git checkout -b test$test_count branch1 &&
714 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
715 test_config mergetool.defaults.trustExitCode true &&
716 test_must_fail git merge master &&
717 git mergetool --no-prompt --tool defaults -- both &&
718 echo master both added >expected &&
719 test_cmp expected both
720 '
721
722 test_expect_success 'filenames seen by tools start with ./' '
723 test_when_finished "git reset --hard" &&
724 git checkout -b test$test_count branch1 &&
725 test_config mergetool.writeToTemp false &&
726 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
727 test_config mergetool.myecho.trustExitCode true &&
728 test_must_fail git merge master &&
729 git mergetool --no-prompt --tool myecho -- both >actual &&
730 grep ^\./both_LOCAL_ actual
731 '
732
733 test_lazy_prereq MKTEMP '
734 tempdir=$(mktemp -d -t foo.XXXXXX) &&
735 test -d "$tempdir" &&
736 rmdir "$tempdir"
737 '
738
739 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
740 test_when_finished "git reset --hard" &&
741 git checkout -b test$test_count branch1 &&
742 test_config mergetool.writeToTemp true &&
743 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
744 test_config mergetool.myecho.trustExitCode true &&
745 test_must_fail git merge master &&
746 git mergetool --no-prompt --tool myecho -- both >actual &&
747 ! grep ^\./both_LOCAL_ actual &&
748 grep /both_LOCAL_ actual
749 '
750
751 test_expect_success 'diff.orderFile configuration is honored' '
752 test_when_finished "git reset --hard" &&
753 git checkout -b test$test_count order-file-side2 &&
754 test_config diff.orderFile order-file &&
755 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
756 test_config mergetool.myecho.trustExitCode true &&
757 echo b >order-file &&
758 echo a >>order-file &&
759 test_must_fail git merge order-file-side1 &&
760 cat >expect <<-\EOF &&
761 Merging:
762 b
763 a
764 EOF
765
766 # make sure "order-file" that is ambiguous between
767 # rev and path is understood correctly.
768 git branch order-file HEAD &&
769
770 git mergetool --no-prompt --tool myecho >output &&
771 git grep --no-index -h -A2 Merging: output >actual &&
772 test_cmp expect actual
773 '
774 test_expect_success 'mergetool -Oorder-file is honored' '
775 test_when_finished "git reset --hard" &&
776 git checkout -b test$test_count order-file-side2 &&
777 test_config diff.orderFile order-file &&
778 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
779 test_config mergetool.myecho.trustExitCode true &&
780 echo b >order-file &&
781 echo a >>order-file &&
782 test_must_fail git merge order-file-side1 &&
783 cat >expect <<-\EOF &&
784 Merging:
785 a
786 b
787 EOF
788 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
789 git grep --no-index -h -A2 Merging: output >actual &&
790 test_cmp expect actual &&
791 git reset --hard &&
792
793 git config --unset diff.orderFile &&
794 test_must_fail git merge order-file-side1 &&
795 cat >expect <<-\EOF &&
796 Merging:
797 b
798 a
799 EOF
800 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
801 git grep --no-index -h -A2 Merging: output >actual &&
802 test_cmp expect actual
803 '
804
805 test_done