]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7610-mergetool.sh
Merge branch 'mo/clang-format-for-each-update' into maint
[thirdparty/git.git] / t / t7610-mergetool.sh
CommitLineData
05e934bb
CB
1#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
47a528ad 6test_description='git mergetool
05e934bb
CB
7
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
b9b5078e
CB
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
05e934bb 16test_expect_success 'setup' '
f9e43085 17 test_config rerere.enabled true &&
74578618
DA
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
157acfcf
RH
58 git checkout -b delete-base branch1 &&
59 mkdir -p a/a &&
0590ff26 60 test_write_lines one two 3 4 >a/a/file.txt &&
157acfcf
RH
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 &&
0590ff26 66 test_write_lines one two 4 >b/b/file.txt &&
157acfcf
RH
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 &&
0590ff26 71 test_write_lines one two 3 >c/c/file.txt &&
157acfcf
RH
72 git commit -a -m"move to c" &&
73
74578618
DA
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
157acfcf
RH
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
74578618
DA
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
b9b5078e
CB
127'
128
129test_expect_success 'custom mergetool' '
c3ad3126 130 test_when_finished "git reset --hard" &&
ecfdf0bd 131 git checkout -b test$test_count branch1 &&
74578618 132 git submodule update -N &&
e9d309e2
DL
133 test_must_fail git merge master &&
134 ( yes "" | git mergetool both ) &&
74578618 135 ( yes "" | git mergetool file1 file1 ) &&
e9d309e2
DL
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 ) &&
74578618
DA
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"
57d93c1d
DL
146'
147
148test_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"
60aced3d
DL
168'
169
170test_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"
0ec7b6c2
CB
187'
188
189test_expect_success 'mergetool crlf' '
614eb27f
RH
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.)
f9e43085 195 test_config core.autocrlf true &&
ecfdf0bd 196 git checkout -b test$test_count branch1 &&
e9d309e2
DL
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 ) &&
74578618
DA
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" &&
614eb27f 211 git commit -m "branch1 resolved with mergetool - autocrlf"
b9b5078e
CB
212'
213
ff4a1855 214test_expect_success 'mergetool in subdir' '
c3ad3126 215 test_when_finished "git reset --hard" &&
ecfdf0bd 216 git checkout -b test$test_count branch1 &&
74578618
DA
217 git submodule update -N &&
218 (
219 cd subdir &&
e9d309e2
DL
220 test_must_fail git merge master &&
221 ( yes "" | git mergetool file3 ) &&
74578618
DA
222 test "$(cat file3)" = "master new sub"
223 )
05e934bb
CB
224'
225
bb0a484e 226test_expect_success 'mergetool on file in parent dir' '
c3ad3126 227 test_when_finished "git reset --hard" &&
fef6c06d 228 git checkout -b test$test_count branch1 &&
b696ac9a 229 git submodule update -N &&
74578618
DA
230 (
231 cd subdir &&
e9d309e2
DL
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 ) &&
74578618
DA
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 )
bb0a484e
DA
245'
246
247test_expect_success 'mergetool skips autoresolved' '
614eb27f 248 test_when_finished "git reset --hard" &&
ecfdf0bd 249 git checkout -b test$test_count branch1 &&
74578618
DA
250 git submodule update -N &&
251 test_must_fail git merge master &&
252 test -n "$(git ls-files -u)" &&
e9d309e2
DL
253 ( yes "d" | git mergetool file11 ) &&
254 ( yes "d" | git mergetool file12 ) &&
255 ( yes "l" | git mergetool submod ) &&
74578618 256 output="$(git mergetool --no-prompt)" &&
614eb27f 257 test "$output" = "No files need merging"
bb0a484e
DA
258'
259
b9ebb659 260test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
c3ad3126 261 test_when_finished "git reset --hard" &&
fef6c06d 262 git checkout -b test$test_count branch1 &&
1a9a23e3 263 test_config rerere.enabled false &&
74578618
DA
264 (
265 cd subdir &&
74578618
DA
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 )
bb0a484e 276'
b9b5078e 277
d0e0cfe7 278test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
b9ebb659
RH
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 &&
74578618
DA
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 )
bb0a484e 295'
b9b5078e 296
2f59c947 297test_expect_success 'mergetool skips resolved paths when rerere is active' '
614eb27f 298 test_when_finished "git reset --hard" &&
f9e43085 299 test_config rerere.enabled true &&
74578618 300 rm -rf .git/rr-cache &&
ecfdf0bd 301 git checkout -b test$test_count branch1 &&
74578618 302 git submodule update -N &&
e9d309e2
DL
303 test_must_fail git merge master &&
304 ( yes "l" | git mergetool --no-prompt submod ) &&
305 ( yes "d" "d" | git mergetool --no-prompt ) &&
74578618
DA
306 git submodule update -N &&
307 output="$(yes "n" | git mergetool --no-prompt)" &&
614eb27f 308 test "$output" = "No files need merging"
2f59c947
MZ
309'
310
743bf6d8 311test_expect_success 'conflicted stash sets up rerere' '
c3ad3126 312 test_when_finished "git reset --hard" &&
f9e43085 313 test_config rerere.enabled true &&
74578618
DA
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"
79dc2d0b
PH
337'
338
3e8e691a 339test_expect_success 'mergetool takes partial path' '
614eb27f 340 test_when_finished "git reset --hard" &&
f9e43085 341 test_config rerere.enabled false &&
ecfdf0bd 342 git checkout -b test$test_count branch1 &&
74578618
DA
343 git submodule update -N &&
344 test_must_fail git merge master &&
345
74578618
DA
346 ( yes "" | git mergetool subdir ) &&
347
614eb27f 348 test "$(cat subdir/file3)" = "master new sub"
3e8e691a
JM
349'
350
faaab8d5 351test_expect_success 'mergetool delete/delete conflict' '
bd9714f2 352 test_when_finished "git reset --hard" &&
61b76d2d 353 git checkout -b test$test_count move-to-c &&
faaab8d5
DA
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 &&
bd9714f2 357 git reset --hard &&
faaab8d5
DA
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 &&
bd9714f2 361 git reset --hard &&
faaab8d5
DA
362 test_must_fail git merge move-to-b &&
363 ! echo a | git mergetool a/a/file.txt &&
614eb27f 364 ! test -f a/a/file.txt
faaab8d5
DA
365'
366
367test_expect_success 'mergetool produces no errors when keepBackup is used' '
bd9714f2 368 test_when_finished "git reset --hard" &&
fef6c06d 369 git checkout -b test$test_count move-to-c &&
faaab8d5
DA
370 test_config mergetool.keepBackup true &&
371 test_must_fail git merge move-to-b &&
faaab8d5 372 echo d | git mergetool a/a/file.txt 2>actual &&
1c5e94f4 373 test_must_be_empty actual &&
614eb27f 374 ! test -d a
a2986045
DA
375'
376
377test_expect_success 'mergetool honors tempfile config for deleted files' '
bd9714f2 378 test_when_finished "git reset --hard" &&
fef6c06d 379 git checkout -b test$test_count move-to-c &&
a2986045
DA
380 test_config mergetool.keepTemporaries false &&
381 test_must_fail git merge move-to-b &&
382 echo d | git mergetool a/a/file.txt &&
614eb27f 383 ! test -d a
a2986045
DA
384'
385
386test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
bd9714f2 387 test_when_finished "git reset --hard" &&
614eb27f 388 test_when_finished "git clean -fdx" &&
fef6c06d 389 git checkout -b test$test_count move-to-c &&
a2986045
DA
390 test_config mergetool.keepTemporaries true &&
391 test_must_fail git merge move-to-b &&
0590ff26 392 ! test_write_lines a n | git mergetool a/a/file.txt &&
a2986045
DA
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 &&
614eb27f 400 test_cmp expect actual
faaab8d5
DA
401'
402
ff7f089e 403test_expect_success 'deleted vs modified submodule' '
bd9714f2 404 test_when_finished "git reset --hard" &&
ecfdf0bd 405 git checkout -b test$test_count branch1 &&
74578618
DA
406 git submodule update -N &&
407 mv submod submod-movedaside &&
408 git rm --cached submod &&
409 git commit -m "Submodule deleted from branch" &&
ecfdf0bd 410 git checkout -b test$test_count.a test$test_count &&
74578618
DA
411 test_must_fail git merge master &&
412 test -n "$(git ls-files -u)" &&
e9d309e2
DL
413 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
414 ( yes "" | git mergetool both ) &&
415 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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 &&
ecfdf0bd 426 git checkout -b test$test_count.b test$test_count &&
74578618
DA
427 git submodule update -N &&
428 test_must_fail git merge master &&
429 test -n "$(git ls-files -u)" &&
e9d309e2
DL
430 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
431 ( yes "" | git mergetool both ) &&
432 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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 &&
ecfdf0bd 440 git checkout -b test$test_count.c master &&
74578618 441 git submodule update -N &&
ecfdf0bd 442 test_must_fail git merge test$test_count &&
74578618 443 test -n "$(git ls-files -u)" &&
e9d309e2
DL
444 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
445 ( yes "" | git mergetool both ) &&
446 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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
ecfdf0bd 456 git checkout -b test$test_count.d master &&
74578618 457 git submodule update -N &&
ecfdf0bd 458 test_must_fail git merge test$test_count &&
74578618 459 test -n "$(git ls-files -u)" &&
e9d309e2
DL
460 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
461 ( yes "" | git mergetool both ) &&
462 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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" &&
614eb27f 469 git commit -m "Merge resolved by keeping module"
ff7f089e
JM
470'
471
472test_expect_success 'file vs modified submodule' '
c3ad3126 473 test_when_finished "git reset --hard" &&
ecfdf0bd 474 git checkout -b test$test_count branch1 &&
74578618
DA
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" &&
ecfdf0bd 481 git checkout -b test$test_count.a branch1 &&
74578618
DA
482 test_must_fail git merge master &&
483 test -n "$(git ls-files -u)" &&
e9d309e2
DL
484 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
485 ( yes "" | git mergetool both ) &&
486 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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 &&
ecfdf0bd 497 git checkout -b test$test_count.b test$test_count &&
74578618
DA
498 test_must_fail git merge master &&
499 test -n "$(git ls-files -u)" &&
e9d309e2
DL
500 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
501 ( yes "" | git mergetool both ) &&
502 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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
ecfdf0bd 510 git checkout -b test$test_count.c master &&
74578618
DA
511 rmdir submod && mv submod-movedaside submod &&
512 test ! -e submod.orig &&
513 git submodule update -N &&
ecfdf0bd 514 test_must_fail git merge test$test_count &&
74578618 515 test -n "$(git ls-files -u)" &&
e9d309e2
DL
516 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
517 ( yes "" | git mergetool both ) &&
518 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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
ecfdf0bd 527 git checkout -b test$test_count.d master &&
74578618
DA
528 rmdir submod && mv submod.orig submod &&
529 git submodule update -N &&
ecfdf0bd 530 test_must_fail git merge test$test_count &&
74578618 531 test -n "$(git ls-files -u)" &&
e9d309e2
DL
532 ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 ) &&
533 ( yes "" | git mergetool both ) &&
534 ( yes "d" | git mergetool file11 file12 ) &&
74578618
DA
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"
ff7f089e
JM
542'
543
544test_expect_success 'submodule in subdirectory' '
c3ad3126 545 test_when_finished "git reset --hard" &&
ecfdf0bd 546 git checkout -b test$test_count branch1 &&
74578618
DA
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 ) &&
614eb27f 558 test_when_finished "rm -rf subdir/subdir_module" &&
74578618
DA
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
ecfdf0bd 563 git checkout -b test$test_count.a test$test_count &&
74578618 564 git submodule update -N &&
ff7f089e 565 (
ff7f089e 566 cd subdir/subdir_module &&
74578618 567 git checkout -b super10.a &&
ecfdf0bd 568 echo test$test_count.a >file15 &&
74578618
DA
569 git add file15 &&
570 git commit -m "on branch 10.a"
571 ) &&
572 git add subdir/subdir_module &&
ecfdf0bd 573 git commit -m "change submodule in subdirectory on test$test_count.a" &&
74578618 574
ecfdf0bd 575 git checkout -b test$test_count.b test$test_count &&
74578618
DA
576 git submodule update -N &&
577 (
578 cd subdir/subdir_module &&
579 git checkout -b super10.b &&
ecfdf0bd 580 echo test$test_count.b >file15 &&
74578618
DA
581 git add file15 &&
582 git commit -m "on branch 10.b"
583 ) &&
584 git add subdir/subdir_module &&
ecfdf0bd 585 git commit -m "change submodule in subdirectory on test$test_count.b" &&
74578618 586
e9d309e2 587 test_must_fail git merge test$test_count.a &&
74578618
DA
588 (
589 cd subdir &&
590 ( yes "l" | git mergetool subdir_module )
591 ) &&
ecfdf0bd 592 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
74578618 593 git submodule update -N &&
ecfdf0bd 594 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
74578618
DA
595 git reset --hard &&
596 git submodule update -N &&
597
e9d309e2 598 test_must_fail git merge test$test_count.a &&
74578618 599 ( yes "r" | git mergetool subdir/subdir_module ) &&
ecfdf0bd 600 test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
74578618 601 git submodule update -N &&
ecfdf0bd 602 test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
614eb27f 603 git commit -m "branch1 resolved with mergetool"
ff7f089e
JM
604'
605
606test_expect_success 'directory vs modified submodule' '
c3ad3126 607 test_when_finished "git reset --hard" &&
ecfdf0bd 608 git checkout -b test$test_count branch1 &&
74578618
DA
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
bd9714f2 622 git reset --hard &&
74578618
DA
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" &&
bd9714f2
RH
634 git reset --hard &&
635 rm -rf submod-movedaside &&
74578618 636
ecfdf0bd 637 git checkout -b test$test_count.c master &&
74578618 638 git submodule update -N &&
ecfdf0bd 639 test_must_fail git merge test$test_count &&
74578618
DA
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
bd9714f2 645 git reset --hard &&
74578618 646 git submodule update -N &&
ecfdf0bd 647 test_must_fail git merge test$test_count &&
74578618
DA
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
bd9714f2 653 git reset --hard master &&
74578618
DA
654 ( cd submod && git clean -f && git reset --hard ) &&
655 git submodule update -N
ff7f089e
JM
656'
657
ec245ba0 658test_expect_success 'file with no base' '
bd9714f2 659 test_when_finished "git reset --hard" &&
ecfdf0bd 660 git checkout -b test$test_count branch1 &&
74578618
DA
661 test_must_fail git merge master &&
662 git mergetool --no-prompt --tool mybase -- both &&
d3c6751b 663 test_must_be_empty both
ec245ba0
DA
664'
665
a427ef7a 666test_expect_success 'custom commands override built-ins' '
bd9714f2 667 test_when_finished "git reset --hard" &&
ecfdf0bd 668 git checkout -b test$test_count branch1 &&
f9e43085
DA
669 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
670 test_config mergetool.defaults.trustExitCode true &&
74578618
DA
671 test_must_fail git merge master &&
672 git mergetool --no-prompt --tool defaults -- both &&
673 echo master both added >expected &&
9c5b2fab 674 test_cmp expected both
a427ef7a
DA
675'
676
688684eb 677test_expect_success 'filenames seen by tools start with ./' '
bd9714f2 678 test_when_finished "git reset --hard" &&
ecfdf0bd 679 git checkout -b test$test_count branch1 &&
688684eb
DA
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 &&
e9d309e2 685 grep ^\./both_LOCAL_ actual
688684eb
DA
686'
687
c578a09b
AK
688test_lazy_prereq MKTEMP '
689 tempdir=$(mktemp -d -t foo.XXXXXX) &&
fa3142c9
JK
690 test -d "$tempdir" &&
691 rmdir "$tempdir"
c578a09b
AK
692'
693
694test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
bd9714f2 695 test_when_finished "git reset --hard" &&
ecfdf0bd 696 git checkout -b test$test_count branch1 &&
688684eb
DA
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 &&
e9d309e2
DL
702 ! grep ^\./both_LOCAL_ actual &&
703 grep /both_LOCAL_ actual
688684eb
DA
704'
705
57937f70 706test_expect_success 'diff.orderFile configuration is honored' '
bd9714f2 707 test_when_finished "git reset --hard" &&
61b76d2d 708 git checkout -b test$test_count order-file-side2 &&
57937f70
DA
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 &&
57937f70
DA
714 test_must_fail git merge order-file-side1 &&
715 cat >expect <<-\EOF &&
716 Merging:
717 b
718 a
719 EOF
d0e0cfe7
RH
720
721 # make sure "order-file" that is ambiguous between
722 # rev and path is understood correctly.
723 git branch order-file HEAD &&
724
57937f70
DA
725 git mergetool --no-prompt --tool myecho >output &&
726 git grep --no-index -h -A2 Merging: output >actual &&
614eb27f 727 test_cmp expect actual
57937f70 728'
654311bf 729test_expect_success 'mergetool -Oorder-file is honored' '
bd9714f2 730 test_when_finished "git reset --hard" &&
fef6c06d 731 git checkout -b test$test_count order-file-side2 &&
654311bf
DA
732 test_config diff.orderFile order-file &&
733 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
734 test_config mergetool.myecho.trustExitCode true &&
b696ac9a
RH
735 echo b >order-file &&
736 echo a >>order-file &&
654311bf
DA
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 &&
bd9714f2 746 git reset --hard &&
654311bf
DA
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 &&
614eb27f 757 test_cmp expect actual
654311bf 758'
57937f70 759
05e934bb 760test_done