]>
Commit | Line | Data |
---|---|---|
05e934bb CB |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Charles Bailey | |
4 | # | |
5 | ||
47a528ad | 6 | test_description='git mergetool |
05e934bb CB |
7 | |
8 | Testing 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 | 16 | test_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 | ||
129 | test_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 | ||
152 | test_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 | ||
178 | test_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 | ||
201 | test_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 | 227 | test_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 | 240 | test_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 | ||
264 | test_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 | 277 | test_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 | 299 | test_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 | 322 | test_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 | 336 | test_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 | 364 | test_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 | 377 | test_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 | ||
393 | test_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 | ||
403 | test_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 | ||
412 | test_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 | 429 | test_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 | ||
502 | test_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 && | |
535 | yes "l" | git mergetool submod && | |
74578618 | 536 | git submodule update -N && |
e10dffd0 JS |
537 | echo "not a submodule" >expect && |
538 | test_cmp expect submod && | |
74578618 DA |
539 | output="$(git mergetool --no-prompt)" && |
540 | test "$output" = "No files need merging" && | |
541 | git commit -m "Merge resolved by keeping file" && | |
542 | ||
ecfdf0bd | 543 | git checkout -b test$test_count.c master && |
74578618 DA |
544 | rmdir submod && mv submod-movedaside submod && |
545 | test ! -e submod.orig && | |
546 | git submodule update -N && | |
ecfdf0bd | 547 | test_must_fail git merge test$test_count && |
74578618 | 548 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
549 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
550 | yes "" | git mergetool both && | |
551 | yes "d" | git mergetool file11 file12 && | |
552 | yes "r" | git mergetool submod && | |
74578618 DA |
553 | test -d submod.orig && |
554 | git submodule update -N && | |
e10dffd0 JS |
555 | echo "not a submodule" >expect && |
556 | test_cmp expect submod && | |
74578618 DA |
557 | output="$(git mergetool --no-prompt)" && |
558 | test "$output" = "No files need merging" && | |
559 | git commit -m "Merge resolved by keeping file" && | |
560 | ||
ecfdf0bd | 561 | git checkout -b test$test_count.d master && |
74578618 DA |
562 | rmdir submod && mv submod.orig submod && |
563 | git submodule update -N && | |
ecfdf0bd | 564 | test_must_fail git merge test$test_count && |
74578618 | 565 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
566 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
567 | yes "" | git mergetool both && | |
568 | yes "d" | git mergetool file11 file12 && | |
569 | yes "l" | git mergetool submod && | |
e10dffd0 JS |
570 | echo "master submodule" >expect && |
571 | test_cmp expect submod/bar && | |
74578618 | 572 | git submodule update -N && |
e10dffd0 JS |
573 | echo "master submodule" >expect && |
574 | test_cmp expect submod/bar && | |
74578618 DA |
575 | output="$(git mergetool --no-prompt)" && |
576 | test "$output" = "No files need merging" && | |
577 | git commit -m "Merge resolved by keeping module" | |
ff7f089e JM |
578 | ' |
579 | ||
580 | test_expect_success 'submodule in subdirectory' ' | |
c3ad3126 | 581 | test_when_finished "git reset --hard" && |
ecfdf0bd | 582 | git checkout -b test$test_count branch1 && |
74578618 DA |
583 | git submodule update -N && |
584 | ( | |
585 | cd subdir && | |
586 | test_create_repo subdir_module && | |
587 | ( | |
588 | cd subdir_module && | |
589 | : >file15 && | |
590 | git add file15 && | |
591 | git commit -m "add initial versions" | |
592 | ) | |
593 | ) && | |
614eb27f | 594 | test_when_finished "rm -rf subdir/subdir_module" && |
74578618 DA |
595 | git submodule add git://example.com/subsubmodule subdir/subdir_module && |
596 | git add subdir/subdir_module && | |
597 | git commit -m "add submodule in subdirectory" && | |
598 | ||
ecfdf0bd | 599 | git checkout -b test$test_count.a test$test_count && |
74578618 | 600 | git submodule update -N && |
ff7f089e | 601 | ( |
ff7f089e | 602 | cd subdir/subdir_module && |
74578618 | 603 | git checkout -b super10.a && |
ecfdf0bd | 604 | echo test$test_count.a >file15 && |
74578618 DA |
605 | git add file15 && |
606 | git commit -m "on branch 10.a" | |
607 | ) && | |
608 | git add subdir/subdir_module && | |
ecfdf0bd | 609 | git commit -m "change submodule in subdirectory on test$test_count.a" && |
74578618 | 610 | |
ecfdf0bd | 611 | git checkout -b test$test_count.b test$test_count && |
74578618 DA |
612 | git submodule update -N && |
613 | ( | |
614 | cd subdir/subdir_module && | |
615 | git checkout -b super10.b && | |
ecfdf0bd | 616 | echo test$test_count.b >file15 && |
74578618 DA |
617 | git add file15 && |
618 | git commit -m "on branch 10.b" | |
619 | ) && | |
620 | git add subdir/subdir_module && | |
ecfdf0bd | 621 | git commit -m "change submodule in subdirectory on test$test_count.b" && |
74578618 | 622 | |
e9d309e2 | 623 | test_must_fail git merge test$test_count.a && |
74578618 DA |
624 | ( |
625 | cd subdir && | |
b4a04c8f | 626 | yes "l" | git mergetool subdir_module |
74578618 | 627 | ) && |
e10dffd0 JS |
628 | echo "test$test_count.b" >expect && |
629 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 | 630 | git submodule update -N && |
e10dffd0 JS |
631 | echo "test$test_count.b" >expect && |
632 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 DA |
633 | git reset --hard && |
634 | git submodule update -N && | |
635 | ||
e9d309e2 | 636 | test_must_fail git merge test$test_count.a && |
b4a04c8f | 637 | yes "r" | git mergetool subdir/subdir_module && |
e10dffd0 JS |
638 | echo "test$test_count.b" >expect && |
639 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 | 640 | git submodule update -N && |
e10dffd0 JS |
641 | echo "test$test_count.a" >expect && |
642 | test_cmp expect subdir/subdir_module/file15 && | |
614eb27f | 643 | git commit -m "branch1 resolved with mergetool" |
ff7f089e JM |
644 | ' |
645 | ||
646 | test_expect_success 'directory vs modified submodule' ' | |
c3ad3126 | 647 | test_when_finished "git reset --hard" && |
ecfdf0bd | 648 | git checkout -b test$test_count branch1 && |
74578618 DA |
649 | mv submod submod-movedaside && |
650 | git rm --cached submod && | |
651 | mkdir submod && | |
652 | echo not a submodule >submod/file16 && | |
653 | git add submod/file16 && | |
654 | git commit -m "Submodule path becomes directory" && | |
655 | ||
656 | test_must_fail git merge master && | |
657 | test -n "$(git ls-files -u)" && | |
b4a04c8f | 658 | yes "l" | git mergetool submod && |
e10dffd0 JS |
659 | echo "not a submodule" >expect && |
660 | test_cmp expect submod/file16 && | |
74578618 DA |
661 | rm -rf submod.orig && |
662 | ||
bd9714f2 | 663 | git reset --hard && |
74578618 DA |
664 | test_must_fail git merge master && |
665 | test -n "$(git ls-files -u)" && | |
666 | test ! -e submod.orig && | |
b4a04c8f | 667 | yes "r" | git mergetool submod && |
74578618 | 668 | test -d submod.orig && |
e10dffd0 JS |
669 | echo "not a submodule" >expect && |
670 | test_cmp expect submod.orig/file16 && | |
74578618 DA |
671 | rm -r submod.orig && |
672 | mv submod-movedaside/.git submod && | |
673 | ( cd submod && git clean -f && git reset --hard ) && | |
674 | git submodule update -N && | |
e10dffd0 JS |
675 | echo "master submodule" >expect && |
676 | test_cmp expect submod/bar && | |
bd9714f2 RH |
677 | git reset --hard && |
678 | rm -rf submod-movedaside && | |
74578618 | 679 | |
ecfdf0bd | 680 | git checkout -b test$test_count.c master && |
74578618 | 681 | git submodule update -N && |
ecfdf0bd | 682 | test_must_fail git merge test$test_count && |
74578618 | 683 | test -n "$(git ls-files -u)" && |
b4a04c8f | 684 | yes "l" | git mergetool submod && |
74578618 | 685 | git submodule update -N && |
e10dffd0 JS |
686 | echo "master submodule" >expect && |
687 | test_cmp expect submod/bar && | |
74578618 | 688 | |
bd9714f2 | 689 | git reset --hard && |
74578618 | 690 | git submodule update -N && |
ecfdf0bd | 691 | test_must_fail git merge test$test_count && |
74578618 DA |
692 | test -n "$(git ls-files -u)" && |
693 | test ! -e submod.orig && | |
b4a04c8f | 694 | yes "r" | git mergetool submod && |
e10dffd0 JS |
695 | echo "not a submodule" >expect && |
696 | test_cmp expect submod/file16 && | |
74578618 | 697 | |
bd9714f2 | 698 | git reset --hard master && |
74578618 DA |
699 | ( cd submod && git clean -f && git reset --hard ) && |
700 | git submodule update -N | |
ff7f089e JM |
701 | ' |
702 | ||
ec245ba0 | 703 | test_expect_success 'file with no base' ' |
bd9714f2 | 704 | test_when_finished "git reset --hard" && |
ecfdf0bd | 705 | git checkout -b test$test_count branch1 && |
74578618 DA |
706 | test_must_fail git merge master && |
707 | git mergetool --no-prompt --tool mybase -- both && | |
d3c6751b | 708 | test_must_be_empty both |
ec245ba0 DA |
709 | ' |
710 | ||
a427ef7a | 711 | test_expect_success 'custom commands override built-ins' ' |
bd9714f2 | 712 | test_when_finished "git reset --hard" && |
ecfdf0bd | 713 | git checkout -b test$test_count branch1 && |
f9e43085 DA |
714 | test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && |
715 | test_config mergetool.defaults.trustExitCode true && | |
74578618 DA |
716 | test_must_fail git merge master && |
717 | git mergetool --no-prompt --tool defaults -- both && | |
718 | echo master both added >expected && | |
9c5b2fab | 719 | test_cmp expected both |
a427ef7a DA |
720 | ' |
721 | ||
688684eb | 722 | test_expect_success 'filenames seen by tools start with ./' ' |
bd9714f2 | 723 | test_when_finished "git reset --hard" && |
ecfdf0bd | 724 | git checkout -b test$test_count branch1 && |
688684eb DA |
725 | test_config mergetool.writeToTemp false && |
726 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
727 | test_config mergetool.myecho.trustExitCode true && | |
728 | test_must_fail git merge master && | |
729 | git mergetool --no-prompt --tool myecho -- both >actual && | |
e9d309e2 | 730 | grep ^\./both_LOCAL_ actual |
688684eb DA |
731 | ' |
732 | ||
c578a09b AK |
733 | test_lazy_prereq MKTEMP ' |
734 | tempdir=$(mktemp -d -t foo.XXXXXX) && | |
fa3142c9 JK |
735 | test -d "$tempdir" && |
736 | rmdir "$tempdir" | |
c578a09b AK |
737 | ' |
738 | ||
739 | test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' ' | |
bd9714f2 | 740 | test_when_finished "git reset --hard" && |
ecfdf0bd | 741 | git checkout -b test$test_count branch1 && |
688684eb DA |
742 | test_config mergetool.writeToTemp true && |
743 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
744 | test_config mergetool.myecho.trustExitCode true && | |
745 | test_must_fail git merge master && | |
746 | git mergetool --no-prompt --tool myecho -- both >actual && | |
e9d309e2 DL |
747 | ! grep ^\./both_LOCAL_ actual && |
748 | grep /both_LOCAL_ actual | |
688684eb DA |
749 | ' |
750 | ||
57937f70 | 751 | test_expect_success 'diff.orderFile configuration is honored' ' |
bd9714f2 | 752 | test_when_finished "git reset --hard" && |
61b76d2d | 753 | git checkout -b test$test_count order-file-side2 && |
57937f70 DA |
754 | test_config diff.orderFile order-file && |
755 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
756 | test_config mergetool.myecho.trustExitCode true && | |
757 | echo b >order-file && | |
758 | echo a >>order-file && | |
57937f70 DA |
759 | test_must_fail git merge order-file-side1 && |
760 | cat >expect <<-\EOF && | |
761 | Merging: | |
762 | b | |
763 | a | |
764 | EOF | |
d0e0cfe7 RH |
765 | |
766 | # make sure "order-file" that is ambiguous between | |
767 | # rev and path is understood correctly. | |
768 | git branch order-file HEAD && | |
769 | ||
57937f70 DA |
770 | git mergetool --no-prompt --tool myecho >output && |
771 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 772 | test_cmp expect actual |
57937f70 | 773 | ' |
654311bf | 774 | test_expect_success 'mergetool -Oorder-file is honored' ' |
bd9714f2 | 775 | test_when_finished "git reset --hard" && |
fef6c06d | 776 | git checkout -b test$test_count order-file-side2 && |
654311bf DA |
777 | test_config diff.orderFile order-file && |
778 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
779 | test_config mergetool.myecho.trustExitCode true && | |
b696ac9a RH |
780 | echo b >order-file && |
781 | echo a >>order-file && | |
654311bf DA |
782 | test_must_fail git merge order-file-side1 && |
783 | cat >expect <<-\EOF && | |
784 | Merging: | |
785 | a | |
786 | b | |
787 | EOF | |
788 | git mergetool -O/dev/null --no-prompt --tool myecho >output && | |
789 | git grep --no-index -h -A2 Merging: output >actual && | |
790 | test_cmp expect actual && | |
bd9714f2 | 791 | git reset --hard && |
654311bf DA |
792 | |
793 | git config --unset diff.orderFile && | |
794 | test_must_fail git merge order-file-side1 && | |
795 | cat >expect <<-\EOF && | |
796 | Merging: | |
797 | b | |
798 | a | |
799 | EOF | |
800 | git mergetool -Oorder-file --no-prompt --tool myecho >output && | |
801 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 802 | test_cmp expect actual |
654311bf | 803 | ' |
57937f70 | 804 | |
05e934bb | 805 | test_done |