1#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
6test_description='git mergetool
7
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
12# All the mergetool test work by checking out a temporary branch based
13# off 'branch1' and then merging in master and checking the results of
14# running mergetool
15
16test_expect_success 'setup' '
17 test_config rerere.enabled true &&
18 echo master >file1 &&
19 echo master spaced >"spaced name" &&
20 echo master file11 >file11 &&
21 echo master file12 >file12 &&
22 echo master file13 >file13 &&
23 echo master file14 >file14 &&
24 mkdir subdir &&
25 echo master sub >subdir/file3 &&
26 test_create_repo submod &&
27 (
28 cd submod &&
29 : >foo &&
30 git add foo &&
31 git commit -m "Add foo"
32 ) &&
33 git submodule add git://example.com/submod submod &&
34 git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
35 git commit -m "add initial versions" &&
36
37 git checkout -b branch1 master &&
38 git submodule update -N &&
39 echo branch1 change >file1 &&
40 echo branch1 newfile >file2 &&
41 echo branch1 spaced >"spaced name" &&
42 echo branch1 both added >both &&
43 echo branch1 change file11 >file11 &&
44 echo branch1 change file13 >file13 &&
45 echo branch1 sub >subdir/file3 &&
46 (
47 cd submod &&
48 echo branch1 submodule >bar &&
49 git add bar &&
50 git commit -m "Add bar on branch1" &&
51 git checkout -b submod-branch1
52 ) &&
53 git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
54 git add both &&
55 git rm file12 &&
56 git commit -m "branch1 changes" &&
57
58 git checkout -b delete-base branch1 &&
59 mkdir -p a/a &&
60 (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" &&
73
74 git checkout -b stash1 master &&
75 echo stash1 change file11 >file11 &&
76 git add file11 &&
77 git commit -m "stash1 changes" &&
78
79 git checkout -b stash2 master &&
80 echo stash2 change file11 >file11 &&
81 git add file11 &&
82 git commit -m "stash2 changes" &&
83
84 git checkout master &&
85 git submodule update -N &&
86 echo master updated >file1 &&
87 echo master new >file2 &&
88 echo master updated spaced >"spaced name" &&
89 echo master both added >both &&
90 echo master updated file12 >file12 &&
91 echo master updated file14 >file14 &&
92 echo master new sub >subdir/file3 &&
93 (
94 cd submod &&
95 echo master submodule >bar &&
96 git add bar &&
97 git commit -m "Add bar on master" &&
98 git checkout -b submod-master
99 ) &&
100 git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
101 git add both &&
102 git rm file11 &&
103 git commit -m "master updates" &&
104
105 git clean -fdx &&
106 git checkout -b order-file-start master &&
107 echo start >a &&
108 echo start >b &&
109 git add a b &&
110 git commit -m start &&
111 git checkout -b order-file-side1 order-file-start &&
112 echo side1 >a &&
113 echo side1 >b &&
114 git add a b &&
115 git commit -m side1 &&
116 git checkout -b order-file-side2 order-file-start &&
117 echo side2 >a &&
118 echo side2 >b &&
119 git add a b &&
120 git commit -m side2 &&
121
122 git config merge.tool mytool &&
123 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
124 git config mergetool.mytool.trustExitCode true &&
125 git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
126 git config mergetool.mybase.trustExitCode true
127'
128
129test_expect_success 'custom mergetool' '
130 test_when_finished "git reset --hard" &&
131 git checkout -b test$test_count branch1 &&
132 git submodule update -N &&
133 test_must_fail git merge master >/dev/null 2>&1 &&
134 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
135 ( yes "" | git mergetool file1 file1 ) &&
136 ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
137 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
138 ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
139 ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
140 ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
141 test "$(cat file1)" = "master updated" &&
142 test "$(cat file2)" = "master new" &&
143 test "$(cat subdir/file3)" = "master new sub" &&
144 test "$(cat submod/bar)" = "branch1 submodule" &&
145 git commit -m "branch1 resolved with mergetool"
146'
147
148test_expect_success 'mergetool crlf' '
149 test_when_finished "git reset --hard" &&
150 # This test_config line must go after the above reset line so that
151 # core.autocrlf is unconfigured before reset runs. (The
152 # test_config command uses test_when_finished internally and
153 # test_when_finished is LIFO.)
154 test_config core.autocrlf true &&
155 git checkout -b test$test_count branch1 &&
156 test_must_fail git merge master >/dev/null 2>&1 &&
157 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
158 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
159 ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) &&
160 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
161 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
162 ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
163 ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
164 ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
165 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
166 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
167 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
168 git submodule update -N &&
169 test "$(cat submod/bar)" = "master submodule" &&
170 git commit -m "branch1 resolved with mergetool - autocrlf"
171'
172
173test_expect_success 'mergetool in subdir' '
174 test_when_finished "git reset --hard" &&
175 git checkout -b test$test_count branch1 &&
176 git submodule update -N &&
177 (
178 cd subdir &&
179 test_must_fail git merge master >/dev/null 2>&1 &&
180 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
181 test "$(cat file3)" = "master new sub"
182 )
183'
184
185test_expect_success 'mergetool on file in parent dir' '
186 test_when_finished "git reset --hard" &&
187 git reset --hard &&
188 git submodule update -N &&
189 (
190 cd subdir &&
191 test_must_fail git merge master >/dev/null 2>&1 &&
192 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
193 ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
194 ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
195 ( yes "" | git mergetool ../both >/dev/null 2>&1 ) &&
196 ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
197 ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
198 ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
199 test "$(cat ../file1)" = "master updated" &&
200 test "$(cat ../file2)" = "master new" &&
201 test "$(cat ../submod/bar)" = "branch1 submodule" &&
202 git commit -m "branch1 resolved with mergetool - subdir"
203 )
204'
205
206test_expect_success 'mergetool skips autoresolved' '
207 test_when_finished "git reset --hard" &&
208 git checkout -b test$test_count branch1 &&
209 git submodule update -N &&
210 test_must_fail git merge master &&
211 test -n "$(git ls-files -u)" &&
212 ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
213 ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
214 ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
215 output="$(git mergetool --no-prompt)" &&
216 test "$output" = "No files need merging"
217'
218
219test_expect_success 'mergetool merges all from subdir' '
220 test_when_finished "git reset --hard" &&
221 test_config rerere.enabled false &&
222 (
223 cd subdir &&
224 test_must_fail git merge master &&
225 ( yes "r" | git mergetool ../submod ) &&
226 ( yes "d" "d" | git mergetool --no-prompt ) &&
227 test "$(cat ../file1)" = "master updated" &&
228 test "$(cat ../file2)" = "master new" &&
229 test "$(cat file3)" = "master new sub" &&
230 ( cd .. && git submodule update -N ) &&
231 test "$(cat ../submod/bar)" = "master submodule" &&
232 git commit -m "branch2 resolved by mergetool from subdir"
233 )
234'
235
236test_expect_success 'mergetool skips resolved paths when rerere is active' '
237 test_when_finished "git reset --hard" &&
238 test_config rerere.enabled true &&
239 rm -rf .git/rr-cache &&
240 git checkout -b test$test_count branch1 &&
241 git submodule update -N &&
242 test_must_fail git merge master >/dev/null 2>&1 &&
243 ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) &&
244 ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
245 git submodule update -N &&
246 output="$(yes "n" | git mergetool --no-prompt)" &&
247 test "$output" = "No files need merging"
248'
249
250test_expect_success 'conflicted stash sets up rerere' '
251 test_when_finished "git reset --hard" &&
252 test_config rerere.enabled true &&
253 git checkout stash1 &&
254 echo "Conflicting stash content" >file11 &&
255 git stash &&
256
257 git checkout --detach stash2 &&
258 test_must_fail git stash apply &&
259
260 test -n "$(git ls-files -u)" &&
261 conflicts="$(git rerere remaining)" &&
262 test "$conflicts" = "file11" &&
263 output="$(git mergetool --no-prompt)" &&
264 test "$output" != "No files need merging" &&
265
266 git commit -am "save the stash resolution" &&
267
268 git reset --hard stash2 &&
269 test_must_fail git stash apply &&
270
271 test -n "$(git ls-files -u)" &&
272 conflicts="$(git rerere remaining)" &&
273 test -z "$conflicts" &&
274 output="$(git mergetool --no-prompt)" &&
275 test "$output" = "No files need merging"
276'
277
278test_expect_success 'mergetool takes partial path' '
279 test_when_finished "git reset --hard" &&
280 git reset --hard &&
281 test_config rerere.enabled false &&
282 git checkout -b test$test_count branch1 &&
283 git submodule update -N &&
284 test_must_fail git merge master &&
285
286 ( yes "" | git mergetool subdir ) &&
287
288 test "$(cat subdir/file3)" = "master new sub"
289'
290
291test_expect_success 'mergetool delete/delete conflict' '
292 test_when_finished "git reset --hard HEAD" &&
293 git checkout move-to-c &&
294 test_must_fail git merge move-to-b &&
295 echo d | git mergetool a/a/file.txt &&
296 ! test -f a/a/file.txt &&
297 git reset --hard HEAD &&
298 test_must_fail git merge move-to-b &&
299 echo m | git mergetool a/a/file.txt &&
300 test -f b/b/file.txt &&
301 git reset --hard HEAD &&
302 test_must_fail git merge move-to-b &&
303 ! echo a | git mergetool a/a/file.txt &&
304 ! test -f a/a/file.txt
305'
306
307test_expect_success 'mergetool produces no errors when keepBackup is used' '
308 test_when_finished "git reset --hard HEAD" &&
309 test_config mergetool.keepBackup true &&
310 test_must_fail git merge move-to-b &&
311 : >expect &&
312 echo d | git mergetool a/a/file.txt 2>actual &&
313 test_cmp expect actual &&
314 ! test -d a
315'
316
317test_expect_success 'mergetool honors tempfile config for deleted files' '
318 test_when_finished "git reset --hard HEAD" &&
319 test_config mergetool.keepTemporaries false &&
320 test_must_fail git merge move-to-b &&
321 echo d | git mergetool a/a/file.txt &&
322 ! test -d a
323'
324
325test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
326 test_when_finished "git reset --hard HEAD" &&
327 test_when_finished "git clean -fdx" &&
328 test_config mergetool.keepTemporaries true &&
329 test_must_fail git merge move-to-b &&
330 ! (echo a; echo n) | git mergetool a/a/file.txt &&
331 test -d a/a &&
332 cat >expect <<-\EOF &&
333 file_BASE_.txt
334 file_LOCAL_.txt
335 file_REMOTE_.txt
336 EOF
337 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
338 test_cmp expect actual
339'
340
341test_expect_success 'deleted vs modified submodule' '
342 test_when_finished "git reset --hard HEAD" &&
343 git checkout -b test$test_count branch1 &&
344 git submodule update -N &&
345 mv submod submod-movedaside &&
346 git rm --cached submod &&
347 git commit -m "Submodule deleted from branch" &&
348 git checkout -b test$test_count.a test$test_count &&
349 test_must_fail git merge master &&
350 test -n "$(git ls-files -u)" &&
351 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
352 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
353 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
354 ( yes "r" | git mergetool submod ) &&
355 rmdir submod && mv submod-movedaside submod &&
356 test "$(cat submod/bar)" = "branch1 submodule" &&
357 git submodule update -N &&
358 test "$(cat submod/bar)" = "master submodule" &&
359 output="$(git mergetool --no-prompt)" &&
360 test "$output" = "No files need merging" &&
361 git commit -m "Merge resolved by keeping module" &&
362
363 mv submod submod-movedaside &&
364 git checkout -b test$test_count.b test$test_count &&
365 git submodule update -N &&
366 test_must_fail git merge master &&
367 test -n "$(git ls-files -u)" &&
368 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
369 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
370 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
371 ( yes "l" | git mergetool submod ) &&
372 test ! -e submod &&
373 output="$(git mergetool --no-prompt)" &&
374 test "$output" = "No files need merging" &&
375 git commit -m "Merge resolved by deleting module" &&
376
377 mv submod-movedaside submod &&
378 git checkout -b test$test_count.c master &&
379 git submodule update -N &&
380 test_must_fail git merge test$test_count &&
381 test -n "$(git ls-files -u)" &&
382 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
383 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
384 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
385 ( yes "r" | git mergetool submod ) &&
386 test ! -e submod &&
387 test -d submod.orig &&
388 git submodule update -N &&
389 output="$(git mergetool --no-prompt)" &&
390 test "$output" = "No files need merging" &&
391 git commit -m "Merge resolved by deleting module" &&
392 mv submod.orig submod &&
393
394 git checkout -b test$test_count.d master &&
395 git submodule update -N &&
396 test_must_fail git merge test$test_count &&
397 test -n "$(git ls-files -u)" &&
398 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
399 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
400 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
401 ( yes "l" | git mergetool submod ) &&
402 test "$(cat submod/bar)" = "master submodule" &&
403 git submodule update -N &&
404 test "$(cat submod/bar)" = "master submodule" &&
405 output="$(git mergetool --no-prompt)" &&
406 test "$output" = "No files need merging" &&
407 git commit -m "Merge resolved by keeping module"
408'
409
410test_expect_success 'file vs modified submodule' '
411 test_when_finished "git reset --hard" &&
412 git checkout -b test$test_count branch1 &&
413 git submodule update -N &&
414 mv submod submod-movedaside &&
415 git rm --cached submod &&
416 echo not a submodule >submod &&
417 git add submod &&
418 git commit -m "Submodule path becomes file" &&
419 git checkout -b test$test_count.a branch1 &&
420 test_must_fail git merge master &&
421 test -n "$(git ls-files -u)" &&
422 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
423 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
424 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
425 ( yes "r" | git mergetool submod ) &&
426 rmdir submod && mv submod-movedaside submod &&
427 test "$(cat submod/bar)" = "branch1 submodule" &&
428 git submodule update -N &&
429 test "$(cat submod/bar)" = "master submodule" &&
430 output="$(git mergetool --no-prompt)" &&
431 test "$output" = "No files need merging" &&
432 git commit -m "Merge resolved by keeping module" &&
433
434 mv submod submod-movedaside &&
435 git checkout -b test$test_count.b test$test_count &&
436 test_must_fail git merge master &&
437 test -n "$(git ls-files -u)" &&
438 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
439 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
440 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
441 ( yes "l" | git mergetool submod ) &&
442 git submodule update -N &&
443 test "$(cat submod)" = "not a submodule" &&
444 output="$(git mergetool --no-prompt)" &&
445 test "$output" = "No files need merging" &&
446 git commit -m "Merge resolved by keeping file" &&
447
448 git checkout -b test$test_count.c master &&
449 rmdir submod && mv submod-movedaside submod &&
450 test ! -e submod.orig &&
451 git submodule update -N &&
452 test_must_fail git merge test$test_count &&
453 test -n "$(git ls-files -u)" &&
454 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
455 ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
456 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
457 ( yes "r" | git mergetool submod ) &&
458 test -d submod.orig &&
459 git submodule update -N &&
460 test "$(cat submod)" = "not a submodule" &&
461 output="$(git mergetool --no-prompt)" &&
462 test "$output" = "No files need merging" &&
463 git commit -m "Merge resolved by keeping file" &&
464
465 git checkout -b test$test_count.d master &&
466 rmdir submod && mv submod.orig submod &&
467 git submodule update -N &&
468 test_must_fail git merge test$test_count &&
469 test -n "$(git ls-files -u)" &&
470 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
471 ( yes "" | git mergetool both>/dev/null 2>&1 ) &&
472 ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
473 ( yes "l" | git mergetool submod ) &&
474 test "$(cat submod/bar)" = "master submodule" &&
475 git submodule update -N &&
476 test "$(cat submod/bar)" = "master submodule" &&
477 output="$(git mergetool --no-prompt)" &&
478 test "$output" = "No files need merging" &&
479 git commit -m "Merge resolved by keeping module"
480'
481
482test_expect_success 'submodule in subdirectory' '
483 test_when_finished "git reset --hard" &&
484 git checkout -b test$test_count branch1 &&
485 git submodule update -N &&
486 (
487 cd subdir &&
488 test_create_repo subdir_module &&
489 (
490 cd subdir_module &&
491 : >file15 &&
492 git add file15 &&
493 git commit -m "add initial versions"
494 )
495 ) &&
496 test_when_finished "rm -rf subdir/subdir_module" &&
497 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
498 git add subdir/subdir_module &&
499 git commit -m "add submodule in subdirectory" &&
500
501 git checkout -b test$test_count.a test$test_count &&
502 git submodule update -N &&
503 (
504 cd subdir/subdir_module &&
505 git checkout -b super10.a &&
506 echo test$test_count.a >file15 &&
507 git add file15 &&
508 git commit -m "on branch 10.a"
509 ) &&
510 git add subdir/subdir_module &&
511 git commit -m "change submodule in subdirectory on test$test_count.a" &&
512
513 git checkout -b test$test_count.b test$test_count &&
514 git submodule update -N &&
515 (
516 cd subdir/subdir_module &&
517 git checkout -b super10.b &&
518 echo test$test_count.b >file15 &&
519 git add file15 &&
520 git commit -m "on branch 10.b"
521 ) &&
522 git add subdir/subdir_module &&
523 git commit -m "change submodule in subdirectory on test$test_count.b" &&
524
525 test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
526 (
527 cd subdir &&
528 ( yes "l" | git mergetool subdir_module )
529 ) &&
530 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
531 git submodule update -N &&
532 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
533 git reset --hard &&
534 git submodule update -N &&
535
536 test_must_fail git merge test$test_count.a >/dev/null 2>&1 &&
537 ( yes "r" | git mergetool subdir/subdir_module ) &&
538 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
539 git submodule update -N &&
540 test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
541 git commit -m "branch1 resolved with mergetool"
542'
543
544test_expect_success 'directory vs modified submodule' '
545 test_when_finished "git reset --hard" &&
546 git checkout -b test$test_count branch1 &&
547 mv submod submod-movedaside &&
548 git rm --cached submod &&
549 mkdir submod &&
550 echo not a submodule >submod/file16 &&
551 git add submod/file16 &&
552 git commit -m "Submodule path becomes directory" &&
553
554 test_must_fail git merge master &&
555 test -n "$(git ls-files -u)" &&
556 ( yes "l" | git mergetool submod ) &&
557 test "$(cat submod/file16)" = "not a submodule" &&
558 rm -rf submod.orig &&
559
560 git reset --hard >/dev/null 2>&1 &&
561 test_must_fail git merge master &&
562 test -n "$(git ls-files -u)" &&
563 test ! -e submod.orig &&
564 ( yes "r" | git mergetool submod ) &&
565 test -d submod.orig &&
566 test "$(cat submod.orig/file16)" = "not a submodule" &&
567 rm -r submod.orig &&
568 mv submod-movedaside/.git submod &&
569 ( cd submod && git clean -f && git reset --hard ) &&
570 git submodule update -N &&
571 test "$(cat submod/bar)" = "master submodule" &&
572 git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside &&
573
574 git checkout -b test$test_count.c master &&
575 git submodule update -N &&
576 test_must_fail git merge test$test_count &&
577 test -n "$(git ls-files -u)" &&
578 ( yes "l" | git mergetool submod ) &&
579 git submodule update -N &&
580 test "$(cat submod/bar)" = "master submodule" &&
581
582 git reset --hard >/dev/null 2>&1 &&
583 git submodule update -N &&
584 test_must_fail git merge test$test_count &&
585 test -n "$(git ls-files -u)" &&
586 test ! -e submod.orig &&
587 ( yes "r" | git mergetool submod ) &&
588 test "$(cat submod/file16)" = "not a submodule" &&
589
590 git reset --hard master >/dev/null 2>&1 &&
591 ( cd submod && git clean -f && git reset --hard ) &&
592 git submodule update -N
593'
594
595test_expect_success 'file with no base' '
596 test_when_finished "git reset --hard master >/dev/null 2>&1" &&
597 git checkout -b test$test_count branch1 &&
598 test_must_fail git merge master &&
599 git mergetool --no-prompt --tool mybase -- both &&
600 >expected &&
601 test_cmp both expected
602'
603
604test_expect_success 'custom commands override built-ins' '
605 test_when_finished "git reset --hard master >/dev/null 2>&1" &&
606 git checkout -b test$test_count branch1 &&
607 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
608 test_config mergetool.defaults.trustExitCode true &&
609 test_must_fail git merge master &&
610 git mergetool --no-prompt --tool defaults -- both &&
611 echo master both added >expected &&
612 test_cmp both expected
613'
614
615test_expect_success 'filenames seen by tools start with ./' '
616 test_when_finished "git reset --hard master >/dev/null 2>&1" &&
617 git checkout -b test$test_count branch1 &&
618 test_config mergetool.writeToTemp false &&
619 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
620 test_config mergetool.myecho.trustExitCode true &&
621 test_must_fail git merge master &&
622 git mergetool --no-prompt --tool myecho -- both >actual &&
623 grep ^\./both_LOCAL_ actual >/dev/null
624'
625
626test_lazy_prereq MKTEMP '
627 tempdir=$(mktemp -d -t foo.XXXXXX) &&
628 test -d "$tempdir" &&
629 rmdir "$tempdir"
630'
631
632test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
633 test_when_finished "git reset --hard master >/dev/null 2>&1" &&
634 git checkout -b test$test_count branch1 &&
635 test_config mergetool.writeToTemp true &&
636 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
637 test_config mergetool.myecho.trustExitCode true &&
638 test_must_fail git merge master &&
639 git mergetool --no-prompt --tool myecho -- both >actual &&
640 test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
641 grep /both_LOCAL_ actual >/dev/null
642'
643
644test_expect_success 'diff.orderFile configuration is honored' '
645 test_when_finished "git reset --hard >/dev/null" &&
646 git checkout order-file-side2 &&
647 test_config diff.orderFile order-file &&
648 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
649 test_config mergetool.myecho.trustExitCode true &&
650 echo b >order-file &&
651 echo a >>order-file &&
652 test_must_fail git merge order-file-side1 &&
653 cat >expect <<-\EOF &&
654 Merging:
655 b
656 a
657 EOF
658 git mergetool --no-prompt --tool myecho >output &&
659 git grep --no-index -h -A2 Merging: output >actual &&
660 test_cmp expect actual
661'
662test_expect_success 'mergetool -Oorder-file is honored' '
663 test_when_finished "git reset --hard >/dev/null 2>&1" &&
664 test_config diff.orderFile order-file &&
665 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
666 test_config mergetool.myecho.trustExitCode true &&
667 echo b >order-file &&
668 echo a >>order-file &&
669 test_must_fail git merge order-file-side1 &&
670 cat >expect <<-\EOF &&
671 Merging:
672 a
673 b
674 EOF
675 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
676 git grep --no-index -h -A2 Merging: output >actual &&
677 test_cmp expect actual &&
678 git reset --hard >/dev/null 2>&1 &&
679
680 git config --unset diff.orderFile &&
681 test_must_fail git merge order-file-side1 &&
682 cat >expect <<-\EOF &&
683 Merging:
684 b
685 a
686 EOF
687 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
688 git grep --no-index -h -A2 Merging: output >actual &&
689 test_cmp expect actual
690'
691
692test_done