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