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