]>
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 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 | ||
148 | test_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 | 173 | test_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 | 185 | test_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 | ||
206 | test_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 | 219 | test_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 | 237 | test_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 | 256 | test_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 | 270 | test_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 | 298 | test_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 | 310 | test_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 | ||
326 | test_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 && | |
faaab8d5 | 331 | echo d | git mergetool a/a/file.txt 2>actual && |
1c5e94f4 | 332 | test_must_be_empty actual && |
614eb27f | 333 | ! test -d a |
a2986045 DA |
334 | ' |
335 | ||
336 | test_expect_success 'mergetool honors tempfile config for deleted files' ' | |
bd9714f2 | 337 | test_when_finished "git reset --hard" && |
fef6c06d | 338 | git checkout -b test$test_count move-to-c && |
a2986045 DA |
339 | test_config mergetool.keepTemporaries false && |
340 | test_must_fail git merge move-to-b && | |
341 | echo d | git mergetool a/a/file.txt && | |
614eb27f | 342 | ! test -d a |
a2986045 DA |
343 | ' |
344 | ||
345 | test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' ' | |
bd9714f2 | 346 | test_when_finished "git reset --hard" && |
614eb27f | 347 | test_when_finished "git clean -fdx" && |
fef6c06d | 348 | git checkout -b test$test_count move-to-c && |
a2986045 DA |
349 | test_config mergetool.keepTemporaries true && |
350 | test_must_fail git merge move-to-b && | |
0590ff26 | 351 | ! test_write_lines a n | git mergetool a/a/file.txt && |
a2986045 DA |
352 | test -d a/a && |
353 | cat >expect <<-\EOF && | |
354 | file_BASE_.txt | |
355 | file_LOCAL_.txt | |
356 | file_REMOTE_.txt | |
357 | EOF | |
358 | ls -1 a/a | sed -e "s/[0-9]*//g" >actual && | |
614eb27f | 359 | test_cmp expect actual |
faaab8d5 DA |
360 | ' |
361 | ||
ff7f089e | 362 | test_expect_success 'deleted vs modified submodule' ' |
bd9714f2 | 363 | test_when_finished "git reset --hard" && |
ecfdf0bd | 364 | git checkout -b test$test_count branch1 && |
74578618 DA |
365 | git submodule update -N && |
366 | mv submod submod-movedaside && | |
367 | git rm --cached submod && | |
368 | git commit -m "Submodule deleted from branch" && | |
ecfdf0bd | 369 | git checkout -b test$test_count.a test$test_count && |
74578618 DA |
370 | test_must_fail git merge master && |
371 | test -n "$(git ls-files -u)" && | |
372 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
373 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
374 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
375 | ( yes "r" | git mergetool submod ) && | |
376 | rmdir submod && mv submod-movedaside submod && | |
377 | test "$(cat submod/bar)" = "branch1 submodule" && | |
378 | git submodule update -N && | |
379 | test "$(cat submod/bar)" = "master submodule" && | |
380 | output="$(git mergetool --no-prompt)" && | |
381 | test "$output" = "No files need merging" && | |
382 | git commit -m "Merge resolved by keeping module" && | |
383 | ||
384 | mv submod submod-movedaside && | |
ecfdf0bd | 385 | git checkout -b test$test_count.b test$test_count && |
74578618 DA |
386 | git submodule update -N && |
387 | test_must_fail git merge master && | |
388 | test -n "$(git ls-files -u)" && | |
389 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
390 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
391 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
392 | ( yes "l" | git mergetool submod ) && | |
393 | test ! -e submod && | |
394 | output="$(git mergetool --no-prompt)" && | |
395 | test "$output" = "No files need merging" && | |
396 | git commit -m "Merge resolved by deleting module" && | |
397 | ||
398 | mv submod-movedaside submod && | |
ecfdf0bd | 399 | git checkout -b test$test_count.c master && |
74578618 | 400 | git submodule update -N && |
ecfdf0bd | 401 | test_must_fail git merge test$test_count && |
74578618 DA |
402 | test -n "$(git ls-files -u)" && |
403 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
404 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
405 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
406 | ( yes "r" | git mergetool submod ) && | |
407 | test ! -e submod && | |
408 | test -d submod.orig && | |
409 | git submodule update -N && | |
410 | output="$(git mergetool --no-prompt)" && | |
411 | test "$output" = "No files need merging" && | |
412 | git commit -m "Merge resolved by deleting module" && | |
413 | mv submod.orig submod && | |
414 | ||
ecfdf0bd | 415 | git checkout -b test$test_count.d master && |
74578618 | 416 | git submodule update -N && |
ecfdf0bd | 417 | test_must_fail git merge test$test_count && |
74578618 DA |
418 | test -n "$(git ls-files -u)" && |
419 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
420 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
421 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
422 | ( yes "l" | git mergetool submod ) && | |
423 | test "$(cat submod/bar)" = "master submodule" && | |
424 | git submodule update -N && | |
425 | test "$(cat submod/bar)" = "master submodule" && | |
426 | output="$(git mergetool --no-prompt)" && | |
427 | test "$output" = "No files need merging" && | |
614eb27f | 428 | git commit -m "Merge resolved by keeping module" |
ff7f089e JM |
429 | ' |
430 | ||
431 | test_expect_success 'file vs modified submodule' ' | |
c3ad3126 | 432 | test_when_finished "git reset --hard" && |
ecfdf0bd | 433 | git checkout -b test$test_count branch1 && |
74578618 DA |
434 | git submodule update -N && |
435 | mv submod submod-movedaside && | |
436 | git rm --cached submod && | |
437 | echo not a submodule >submod && | |
438 | git add submod && | |
439 | git commit -m "Submodule path becomes file" && | |
ecfdf0bd | 440 | git checkout -b test$test_count.a branch1 && |
74578618 DA |
441 | test_must_fail git merge master && |
442 | test -n "$(git ls-files -u)" && | |
443 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
444 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
445 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
446 | ( yes "r" | git mergetool submod ) && | |
447 | rmdir submod && mv submod-movedaside submod && | |
448 | test "$(cat submod/bar)" = "branch1 submodule" && | |
449 | git submodule update -N && | |
450 | test "$(cat submod/bar)" = "master submodule" && | |
451 | output="$(git mergetool --no-prompt)" && | |
452 | test "$output" = "No files need merging" && | |
453 | git commit -m "Merge resolved by keeping module" && | |
454 | ||
455 | mv submod submod-movedaside && | |
ecfdf0bd | 456 | git checkout -b test$test_count.b test$test_count && |
74578618 DA |
457 | test_must_fail git merge master && |
458 | test -n "$(git ls-files -u)" && | |
459 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
460 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
461 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
462 | ( yes "l" | git mergetool submod ) && | |
463 | git submodule update -N && | |
464 | test "$(cat submod)" = "not a submodule" && | |
465 | output="$(git mergetool --no-prompt)" && | |
466 | test "$output" = "No files need merging" && | |
467 | git commit -m "Merge resolved by keeping file" && | |
468 | ||
ecfdf0bd | 469 | git checkout -b test$test_count.c master && |
74578618 DA |
470 | rmdir submod && mv submod-movedaside submod && |
471 | test ! -e submod.orig && | |
472 | git submodule update -N && | |
ecfdf0bd | 473 | test_must_fail git merge test$test_count && |
74578618 DA |
474 | test -n "$(git ls-files -u)" && |
475 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
476 | ( yes "" | git mergetool both >/dev/null 2>&1 ) && | |
477 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
478 | ( yes "r" | git mergetool submod ) && | |
479 | test -d submod.orig && | |
480 | git submodule update -N && | |
481 | test "$(cat submod)" = "not a submodule" && | |
482 | output="$(git mergetool --no-prompt)" && | |
483 | test "$output" = "No files need merging" && | |
484 | git commit -m "Merge resolved by keeping file" && | |
485 | ||
ecfdf0bd | 486 | git checkout -b test$test_count.d master && |
74578618 DA |
487 | rmdir submod && mv submod.orig submod && |
488 | git submodule update -N && | |
ecfdf0bd | 489 | test_must_fail git merge test$test_count && |
74578618 DA |
490 | test -n "$(git ls-files -u)" && |
491 | ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && | |
492 | ( yes "" | git mergetool both>/dev/null 2>&1 ) && | |
493 | ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && | |
494 | ( yes "l" | git mergetool submod ) && | |
495 | test "$(cat submod/bar)" = "master submodule" && | |
496 | git submodule update -N && | |
497 | test "$(cat submod/bar)" = "master submodule" && | |
498 | output="$(git mergetool --no-prompt)" && | |
499 | test "$output" = "No files need merging" && | |
500 | git commit -m "Merge resolved by keeping module" | |
ff7f089e JM |
501 | ' |
502 | ||
503 | test_expect_success 'submodule in subdirectory' ' | |
c3ad3126 | 504 | test_when_finished "git reset --hard" && |
ecfdf0bd | 505 | git checkout -b test$test_count branch1 && |
74578618 DA |
506 | git submodule update -N && |
507 | ( | |
508 | cd subdir && | |
509 | test_create_repo subdir_module && | |
510 | ( | |
511 | cd subdir_module && | |
512 | : >file15 && | |
513 | git add file15 && | |
514 | git commit -m "add initial versions" | |
515 | ) | |
516 | ) && | |
614eb27f | 517 | test_when_finished "rm -rf subdir/subdir_module" && |
74578618 DA |
518 | git submodule add git://example.com/subsubmodule subdir/subdir_module && |
519 | git add subdir/subdir_module && | |
520 | git commit -m "add submodule in subdirectory" && | |
521 | ||
ecfdf0bd | 522 | git checkout -b test$test_count.a test$test_count && |
74578618 | 523 | git submodule update -N && |
ff7f089e | 524 | ( |
ff7f089e | 525 | cd subdir/subdir_module && |
74578618 | 526 | git checkout -b super10.a && |
ecfdf0bd | 527 | echo test$test_count.a >file15 && |
74578618 DA |
528 | git add file15 && |
529 | git commit -m "on branch 10.a" | |
530 | ) && | |
531 | git add subdir/subdir_module && | |
ecfdf0bd | 532 | git commit -m "change submodule in subdirectory on test$test_count.a" && |
74578618 | 533 | |
ecfdf0bd | 534 | git checkout -b test$test_count.b test$test_count && |
74578618 DA |
535 | git submodule update -N && |
536 | ( | |
537 | cd subdir/subdir_module && | |
538 | git checkout -b super10.b && | |
ecfdf0bd | 539 | echo test$test_count.b >file15 && |
74578618 DA |
540 | git add file15 && |
541 | git commit -m "on branch 10.b" | |
542 | ) && | |
543 | git add subdir/subdir_module && | |
ecfdf0bd | 544 | git commit -m "change submodule in subdirectory on test$test_count.b" && |
74578618 | 545 | |
ecfdf0bd | 546 | test_must_fail git merge test$test_count.a >/dev/null 2>&1 && |
74578618 DA |
547 | ( |
548 | cd subdir && | |
549 | ( yes "l" | git mergetool subdir_module ) | |
550 | ) && | |
ecfdf0bd | 551 | test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" && |
74578618 | 552 | git submodule update -N && |
ecfdf0bd | 553 | test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" && |
74578618 DA |
554 | git reset --hard && |
555 | git submodule update -N && | |
556 | ||
ecfdf0bd | 557 | test_must_fail git merge test$test_count.a >/dev/null 2>&1 && |
74578618 | 558 | ( yes "r" | git mergetool subdir/subdir_module ) && |
ecfdf0bd | 559 | test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" && |
74578618 | 560 | git submodule update -N && |
ecfdf0bd | 561 | test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" && |
614eb27f | 562 | git commit -m "branch1 resolved with mergetool" |
ff7f089e JM |
563 | ' |
564 | ||
565 | test_expect_success 'directory vs modified submodule' ' | |
c3ad3126 | 566 | test_when_finished "git reset --hard" && |
ecfdf0bd | 567 | git checkout -b test$test_count branch1 && |
74578618 DA |
568 | mv submod submod-movedaside && |
569 | git rm --cached submod && | |
570 | mkdir submod && | |
571 | echo not a submodule >submod/file16 && | |
572 | git add submod/file16 && | |
573 | git commit -m "Submodule path becomes directory" && | |
574 | ||
575 | test_must_fail git merge master && | |
576 | test -n "$(git ls-files -u)" && | |
577 | ( yes "l" | git mergetool submod ) && | |
578 | test "$(cat submod/file16)" = "not a submodule" && | |
579 | rm -rf submod.orig && | |
580 | ||
bd9714f2 | 581 | git reset --hard && |
74578618 DA |
582 | test_must_fail git merge master && |
583 | test -n "$(git ls-files -u)" && | |
584 | test ! -e submod.orig && | |
585 | ( yes "r" | git mergetool submod ) && | |
586 | test -d submod.orig && | |
587 | test "$(cat submod.orig/file16)" = "not a submodule" && | |
588 | rm -r submod.orig && | |
589 | mv submod-movedaside/.git submod && | |
590 | ( cd submod && git clean -f && git reset --hard ) && | |
591 | git submodule update -N && | |
592 | test "$(cat submod/bar)" = "master submodule" && | |
bd9714f2 RH |
593 | git reset --hard && |
594 | rm -rf submod-movedaside && | |
74578618 | 595 | |
ecfdf0bd | 596 | git checkout -b test$test_count.c master && |
74578618 | 597 | git submodule update -N && |
ecfdf0bd | 598 | test_must_fail git merge test$test_count && |
74578618 DA |
599 | test -n "$(git ls-files -u)" && |
600 | ( yes "l" | git mergetool submod ) && | |
601 | git submodule update -N && | |
602 | test "$(cat submod/bar)" = "master submodule" && | |
603 | ||
bd9714f2 | 604 | git reset --hard && |
74578618 | 605 | git submodule update -N && |
ecfdf0bd | 606 | test_must_fail git merge test$test_count && |
74578618 DA |
607 | test -n "$(git ls-files -u)" && |
608 | test ! -e submod.orig && | |
609 | ( yes "r" | git mergetool submod ) && | |
610 | test "$(cat submod/file16)" = "not a submodule" && | |
611 | ||
bd9714f2 | 612 | git reset --hard master && |
74578618 DA |
613 | ( cd submod && git clean -f && git reset --hard ) && |
614 | git submodule update -N | |
ff7f089e JM |
615 | ' |
616 | ||
ec245ba0 | 617 | test_expect_success 'file with no base' ' |
bd9714f2 | 618 | test_when_finished "git reset --hard" && |
ecfdf0bd | 619 | git checkout -b test$test_count branch1 && |
74578618 DA |
620 | test_must_fail git merge master && |
621 | git mergetool --no-prompt --tool mybase -- both && | |
d3c6751b | 622 | test_must_be_empty both |
ec245ba0 DA |
623 | ' |
624 | ||
a427ef7a | 625 | test_expect_success 'custom commands override built-ins' ' |
bd9714f2 | 626 | test_when_finished "git reset --hard" && |
ecfdf0bd | 627 | git checkout -b test$test_count branch1 && |
f9e43085 DA |
628 | test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && |
629 | test_config mergetool.defaults.trustExitCode true && | |
74578618 DA |
630 | test_must_fail git merge master && |
631 | git mergetool --no-prompt --tool defaults -- both && | |
632 | echo master both added >expected && | |
9c5b2fab | 633 | test_cmp expected both |
a427ef7a DA |
634 | ' |
635 | ||
688684eb | 636 | test_expect_success 'filenames seen by tools start with ./' ' |
bd9714f2 | 637 | test_when_finished "git reset --hard" && |
ecfdf0bd | 638 | git checkout -b test$test_count branch1 && |
688684eb DA |
639 | test_config mergetool.writeToTemp false && |
640 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
641 | test_config mergetool.myecho.trustExitCode true && | |
642 | test_must_fail git merge master && | |
643 | git mergetool --no-prompt --tool myecho -- both >actual && | |
614eb27f | 644 | grep ^\./both_LOCAL_ actual >/dev/null |
688684eb DA |
645 | ' |
646 | ||
c578a09b AK |
647 | test_lazy_prereq MKTEMP ' |
648 | tempdir=$(mktemp -d -t foo.XXXXXX) && | |
fa3142c9 JK |
649 | test -d "$tempdir" && |
650 | rmdir "$tempdir" | |
c578a09b AK |
651 | ' |
652 | ||
653 | test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' ' | |
bd9714f2 | 654 | test_when_finished "git reset --hard" && |
ecfdf0bd | 655 | git checkout -b test$test_count branch1 && |
688684eb DA |
656 | test_config mergetool.writeToTemp true && |
657 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
658 | test_config mergetool.myecho.trustExitCode true && | |
659 | test_must_fail git merge master && | |
660 | git mergetool --no-prompt --tool myecho -- both >actual && | |
c7cf9566 | 661 | ! grep ^\./both_LOCAL_ actual >/dev/null && |
614eb27f | 662 | grep /both_LOCAL_ actual >/dev/null |
688684eb DA |
663 | ' |
664 | ||
57937f70 | 665 | test_expect_success 'diff.orderFile configuration is honored' ' |
bd9714f2 | 666 | test_when_finished "git reset --hard" && |
61b76d2d | 667 | git checkout -b test$test_count order-file-side2 && |
57937f70 DA |
668 | test_config diff.orderFile order-file && |
669 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
670 | test_config mergetool.myecho.trustExitCode true && | |
671 | echo b >order-file && | |
672 | echo a >>order-file && | |
57937f70 DA |
673 | test_must_fail git merge order-file-side1 && |
674 | cat >expect <<-\EOF && | |
675 | Merging: | |
676 | b | |
677 | a | |
678 | EOF | |
d0e0cfe7 RH |
679 | |
680 | # make sure "order-file" that is ambiguous between | |
681 | # rev and path is understood correctly. | |
682 | git branch order-file HEAD && | |
683 | ||
57937f70 DA |
684 | git mergetool --no-prompt --tool myecho >output && |
685 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 686 | test_cmp expect actual |
57937f70 | 687 | ' |
654311bf | 688 | test_expect_success 'mergetool -Oorder-file is honored' ' |
bd9714f2 | 689 | test_when_finished "git reset --hard" && |
fef6c06d | 690 | git checkout -b test$test_count order-file-side2 && |
654311bf DA |
691 | test_config diff.orderFile order-file && |
692 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
693 | test_config mergetool.myecho.trustExitCode true && | |
b696ac9a RH |
694 | echo b >order-file && |
695 | echo a >>order-file && | |
654311bf DA |
696 | test_must_fail git merge order-file-side1 && |
697 | cat >expect <<-\EOF && | |
698 | Merging: | |
699 | a | |
700 | b | |
701 | EOF | |
702 | git mergetool -O/dev/null --no-prompt --tool myecho >output && | |
703 | git grep --no-index -h -A2 Merging: output >actual && | |
704 | test_cmp expect actual && | |
bd9714f2 | 705 | git reset --hard && |
654311bf DA |
706 | |
707 | git config --unset diff.orderFile && | |
708 | test_must_fail git merge order-file-side1 && | |
709 | cat >expect <<-\EOF && | |
710 | Merging: | |
711 | b | |
712 | a | |
713 | EOF | |
714 | git mergetool -Oorder-file --no-prompt --tool myecho >output && | |
715 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 716 | test_cmp expect actual |
654311bf | 717 | ' |
57937f70 | 718 | |
05e934bb | 719 | test_done |