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