]>
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 | ||
1e2ae142 | 10 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
11 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
12 | ||
05e934bb CB |
13 | . ./test-lib.sh |
14 | ||
b9b5078e | 15 | # All the mergetool test work by checking out a temporary branch based |
1e2ae142 | 16 | # off 'branch1' and then merging in main and checking the results of |
b9b5078e CB |
17 | # running mergetool |
18 | ||
05e934bb | 19 | test_expect_success 'setup' ' |
f9e43085 | 20 | test_config rerere.enabled true && |
1e2ae142 JS |
21 | echo main >file1 && |
22 | echo main spaced >"spaced name" && | |
23 | echo main file11 >file11 && | |
24 | echo main file12 >file12 && | |
25 | echo main file13 >file13 && | |
26 | echo main file14 >file14 && | |
74578618 | 27 | mkdir subdir && |
1e2ae142 | 28 | echo main sub >subdir/file3 && |
74578618 DA |
29 | test_create_repo submod && |
30 | ( | |
31 | cd submod && | |
32 | : >foo && | |
33 | git add foo && | |
34 | git commit -m "Add foo" | |
35 | ) && | |
23fb328c | 36 | git submodule add file:///dev/null submod && |
74578618 DA |
37 | git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod && |
38 | git commit -m "add initial versions" && | |
39 | ||
1e2ae142 | 40 | git checkout -b branch1 main && |
74578618 DA |
41 | git submodule update -N && |
42 | echo branch1 change >file1 && | |
43 | echo branch1 newfile >file2 && | |
44 | echo branch1 spaced >"spaced name" && | |
45 | echo branch1 both added >both && | |
46 | echo branch1 change file11 >file11 && | |
47 | echo branch1 change file13 >file13 && | |
48 | echo branch1 sub >subdir/file3 && | |
49 | ( | |
50 | cd submod && | |
51 | echo branch1 submodule >bar && | |
52 | git add bar && | |
53 | git commit -m "Add bar on branch1" && | |
54 | git checkout -b submod-branch1 | |
55 | ) && | |
56 | git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && | |
57 | git add both && | |
58 | git rm file12 && | |
59 | git commit -m "branch1 changes" && | |
60 | ||
157acfcf RH |
61 | git checkout -b delete-base branch1 && |
62 | mkdir -p a/a && | |
0590ff26 | 63 | test_write_lines one two 3 4 >a/a/file.txt && |
157acfcf RH |
64 | git add a/a/file.txt && |
65 | git commit -m"base file" && | |
66 | git checkout -b move-to-b delete-base && | |
67 | mkdir -p b/b && | |
68 | git mv a/a/file.txt b/b/file.txt && | |
0590ff26 | 69 | test_write_lines one two 4 >b/b/file.txt && |
157acfcf RH |
70 | git commit -a -m"move to b" && |
71 | git checkout -b move-to-c delete-base && | |
72 | mkdir -p c/c && | |
73 | git mv a/a/file.txt c/c/file.txt && | |
0590ff26 | 74 | test_write_lines one two 3 >c/c/file.txt && |
157acfcf RH |
75 | git commit -a -m"move to c" && |
76 | ||
1e2ae142 | 77 | git checkout -b stash1 main && |
74578618 DA |
78 | echo stash1 change file11 >file11 && |
79 | git add file11 && | |
80 | git commit -m "stash1 changes" && | |
81 | ||
1e2ae142 | 82 | git checkout -b stash2 main && |
74578618 DA |
83 | echo stash2 change file11 >file11 && |
84 | git add file11 && | |
85 | git commit -m "stash2 changes" && | |
86 | ||
1e2ae142 | 87 | git checkout main && |
74578618 | 88 | git submodule update -N && |
1e2ae142 JS |
89 | echo main updated >file1 && |
90 | echo main new >file2 && | |
91 | echo main updated spaced >"spaced name" && | |
92 | echo main both added >both && | |
93 | echo main updated file12 >file12 && | |
94 | echo main updated file14 >file14 && | |
95 | echo main new sub >subdir/file3 && | |
74578618 DA |
96 | ( |
97 | cd submod && | |
1e2ae142 | 98 | echo main submodule >bar && |
74578618 | 99 | git add bar && |
1e2ae142 JS |
100 | git commit -m "Add bar on main" && |
101 | git checkout -b submod-main | |
74578618 DA |
102 | ) && |
103 | git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && | |
104 | git add both && | |
105 | git rm file11 && | |
1e2ae142 | 106 | git commit -m "main updates" && |
74578618 | 107 | |
157acfcf | 108 | git clean -fdx && |
1e2ae142 | 109 | git checkout -b order-file-start main && |
157acfcf RH |
110 | echo start >a && |
111 | echo start >b && | |
112 | git add a b && | |
113 | git commit -m start && | |
114 | git checkout -b order-file-side1 order-file-start && | |
115 | echo side1 >a && | |
116 | echo side1 >b && | |
117 | git add a b && | |
118 | git commit -m side1 && | |
119 | git checkout -b order-file-side2 order-file-start && | |
120 | echo side2 >a && | |
121 | echo side2 >b && | |
122 | git add a b && | |
123 | git commit -m side2 && | |
124 | ||
74578618 DA |
125 | git config merge.tool mytool && |
126 | git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && | |
127 | git config mergetool.mytool.trustExitCode true && | |
128 | git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" && | |
129 | git config mergetool.mybase.trustExitCode true | |
b9b5078e CB |
130 | ' |
131 | ||
132 | test_expect_success 'custom mergetool' ' | |
c3ad3126 | 133 | test_when_finished "git reset --hard" && |
ecfdf0bd | 134 | git checkout -b test$test_count branch1 && |
74578618 | 135 | git submodule update -N && |
1e2ae142 | 136 | test_must_fail git merge main && |
b4a04c8f JS |
137 | yes "" | git mergetool both && |
138 | yes "" | git mergetool file1 file1 && | |
139 | yes "" | git mergetool file2 "spaced name" && | |
140 | yes "" | git mergetool subdir/file3 && | |
141 | yes "d" | git mergetool file11 && | |
142 | yes "d" | git mergetool file12 && | |
143 | yes "l" | git mergetool submod && | |
1e2ae142 | 144 | echo "main updated" >expect && |
e10dffd0 | 145 | test_cmp expect file1 && |
1e2ae142 | 146 | echo "main new" >expect && |
e10dffd0 | 147 | test_cmp expect file2 && |
1e2ae142 | 148 | echo "main new sub" >expect && |
e10dffd0 JS |
149 | test_cmp expect subdir/file3 && |
150 | echo "branch1 submodule" >expect && | |
151 | test_cmp expect submod/bar && | |
74578618 | 152 | git commit -m "branch1 resolved with mergetool" |
57d93c1d DL |
153 | ' |
154 | ||
155 | test_expect_success 'gui mergetool' ' | |
156 | test_config merge.guitool myguitool && | |
157 | test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" && | |
158 | test_config mergetool.myguitool.trustExitCode true && | |
159 | test_when_finished "git reset --hard" && | |
160 | git checkout -b test$test_count branch1 && | |
161 | git submodule update -N && | |
1e2ae142 | 162 | test_must_fail git merge main && |
b4a04c8f JS |
163 | yes "" | git mergetool --gui both && |
164 | yes "" | git mergetool -g file1 file1 && | |
165 | yes "" | git mergetool --gui file2 "spaced name" && | |
166 | yes "" | git mergetool --gui subdir/file3 && | |
167 | yes "d" | git mergetool --gui file11 && | |
168 | yes "d" | git mergetool --gui file12 && | |
169 | yes "l" | git mergetool --gui submod && | |
1e2ae142 | 170 | echo "gui main updated" >expect && |
e10dffd0 | 171 | test_cmp expect file1 && |
1e2ae142 | 172 | echo "gui main new" >expect && |
e10dffd0 | 173 | test_cmp expect file2 && |
1e2ae142 | 174 | echo "gui main new sub" >expect && |
e10dffd0 JS |
175 | test_cmp expect subdir/file3 && |
176 | echo "branch1 submodule" >expect && | |
177 | test_cmp expect submod/bar && | |
57d93c1d | 178 | git commit -m "branch1 resolved with mergetool" |
60aced3d DL |
179 | ' |
180 | ||
181 | test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' ' | |
182 | test_when_finished "git reset --hard" && | |
183 | git checkout -b test$test_count branch1 && | |
184 | git submodule update -N && | |
1e2ae142 | 185 | test_must_fail git merge main && |
b4a04c8f JS |
186 | yes "" | git mergetool --gui both && |
187 | yes "" | git mergetool -g file1 file1 && | |
188 | yes "" | git mergetool --gui file2 "spaced name" && | |
189 | yes "" | git mergetool --gui subdir/file3 && | |
190 | yes "d" | git mergetool --gui file11 && | |
191 | yes "d" | git mergetool --gui file12 && | |
192 | yes "l" | git mergetool --gui submod && | |
1e2ae142 | 193 | echo "main updated" >expect && |
e10dffd0 | 194 | test_cmp expect file1 && |
1e2ae142 | 195 | echo "main new" >expect && |
e10dffd0 | 196 | test_cmp expect file2 && |
1e2ae142 | 197 | echo "main new sub" >expect && |
e10dffd0 JS |
198 | test_cmp expect subdir/file3 && |
199 | echo "branch1 submodule" >expect && | |
200 | test_cmp expect submod/bar && | |
60aced3d | 201 | git commit -m "branch1 resolved with mergetool" |
0ec7b6c2 CB |
202 | ' |
203 | ||
204 | test_expect_success 'mergetool crlf' ' | |
614eb27f RH |
205 | test_when_finished "git reset --hard" && |
206 | # This test_config line must go after the above reset line so that | |
207 | # core.autocrlf is unconfigured before reset runs. (The | |
208 | # test_config command uses test_when_finished internally and | |
209 | # test_when_finished is LIFO.) | |
f9e43085 | 210 | test_config core.autocrlf true && |
ecfdf0bd | 211 | git checkout -b test$test_count branch1 && |
1e2ae142 | 212 | test_must_fail git merge main && |
b4a04c8f JS |
213 | yes "" | git mergetool file1 && |
214 | yes "" | git mergetool file2 && | |
215 | yes "" | git mergetool "spaced name" && | |
216 | yes "" | git mergetool both && | |
217 | yes "" | git mergetool subdir/file3 && | |
218 | yes "d" | git mergetool file11 && | |
219 | yes "d" | git mergetool file12 && | |
220 | yes "r" | git mergetool submod && | |
1e2ae142 JS |
221 | test "$(printf x | cat file1 -)" = "$(printf "main updated\r\nx")" && |
222 | test "$(printf x | cat file2 -)" = "$(printf "main new\r\nx")" && | |
223 | test "$(printf x | cat subdir/file3 -)" = "$(printf "main new sub\r\nx")" && | |
74578618 | 224 | git submodule update -N && |
1e2ae142 | 225 | echo "main submodule" >expect && |
e10dffd0 | 226 | test_cmp expect submod/bar && |
614eb27f | 227 | git commit -m "branch1 resolved with mergetool - autocrlf" |
b9b5078e CB |
228 | ' |
229 | ||
ff4a1855 | 230 | test_expect_success 'mergetool in subdir' ' |
c3ad3126 | 231 | test_when_finished "git reset --hard" && |
ecfdf0bd | 232 | git checkout -b test$test_count branch1 && |
74578618 DA |
233 | git submodule update -N && |
234 | ( | |
235 | cd subdir && | |
1e2ae142 | 236 | test_must_fail git merge main && |
b4a04c8f | 237 | yes "" | git mergetool file3 && |
1e2ae142 | 238 | echo "main new sub" >expect && |
e10dffd0 | 239 | test_cmp expect file3 |
74578618 | 240 | ) |
05e934bb CB |
241 | ' |
242 | ||
bb0a484e | 243 | test_expect_success 'mergetool on file in parent dir' ' |
c3ad3126 | 244 | test_when_finished "git reset --hard" && |
fef6c06d | 245 | git checkout -b test$test_count branch1 && |
b696ac9a | 246 | git submodule update -N && |
74578618 DA |
247 | ( |
248 | cd subdir && | |
1e2ae142 | 249 | test_must_fail git merge main && |
b4a04c8f JS |
250 | yes "" | git mergetool file3 && |
251 | yes "" | git mergetool ../file1 && | |
252 | yes "" | git mergetool ../file2 ../spaced\ name && | |
253 | yes "" | git mergetool ../both && | |
254 | yes "d" | git mergetool ../file11 && | |
255 | yes "d" | git mergetool ../file12 && | |
256 | yes "l" | git mergetool ../submod && | |
1e2ae142 | 257 | echo "main updated" >expect && |
e10dffd0 | 258 | test_cmp expect ../file1 && |
1e2ae142 | 259 | echo "main new" >expect && |
e10dffd0 JS |
260 | test_cmp expect ../file2 && |
261 | echo "branch1 submodule" >expect && | |
262 | test_cmp expect ../submod/bar && | |
74578618 DA |
263 | git commit -m "branch1 resolved with mergetool - subdir" |
264 | ) | |
bb0a484e DA |
265 | ' |
266 | ||
267 | test_expect_success 'mergetool skips autoresolved' ' | |
614eb27f | 268 | test_when_finished "git reset --hard" && |
ecfdf0bd | 269 | git checkout -b test$test_count branch1 && |
74578618 | 270 | git submodule update -N && |
1e2ae142 | 271 | test_must_fail git merge main && |
74578618 | 272 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
273 | yes "d" | git mergetool file11 && |
274 | yes "d" | git mergetool file12 && | |
275 | yes "l" | git mergetool submod && | |
74578618 | 276 | output="$(git mergetool --no-prompt)" && |
614eb27f | 277 | test "$output" = "No files need merging" |
bb0a484e DA |
278 | ' |
279 | ||
b9ebb659 | 280 | test_expect_success 'mergetool merges all from subdir (rerere disabled)' ' |
c3ad3126 | 281 | test_when_finished "git reset --hard" && |
fef6c06d | 282 | git checkout -b test$test_count branch1 && |
1a9a23e3 | 283 | test_config rerere.enabled false && |
74578618 DA |
284 | ( |
285 | cd subdir && | |
1e2ae142 | 286 | test_must_fail git merge main && |
b4a04c8f JS |
287 | yes "r" | git mergetool ../submod && |
288 | yes "d" "d" | git mergetool --no-prompt && | |
1e2ae142 | 289 | echo "main updated" >expect && |
e10dffd0 | 290 | test_cmp expect ../file1 && |
1e2ae142 | 291 | echo "main new" >expect && |
e10dffd0 | 292 | test_cmp expect ../file2 && |
1e2ae142 | 293 | echo "main new sub" >expect && |
e10dffd0 | 294 | test_cmp expect file3 && |
74578618 | 295 | ( cd .. && git submodule update -N ) && |
1e2ae142 | 296 | echo "main submodule" >expect && |
e10dffd0 | 297 | test_cmp expect ../submod/bar && |
74578618 DA |
298 | git commit -m "branch2 resolved by mergetool from subdir" |
299 | ) | |
bb0a484e | 300 | ' |
b9b5078e | 301 | |
d0e0cfe7 | 302 | test_expect_success 'mergetool merges all from subdir (rerere enabled)' ' |
b9ebb659 RH |
303 | test_when_finished "git reset --hard" && |
304 | git checkout -b test$test_count branch1 && | |
305 | test_config rerere.enabled true && | |
306 | rm -rf .git/rr-cache && | |
307 | ( | |
308 | cd subdir && | |
1e2ae142 | 309 | test_must_fail git merge main && |
b4a04c8f JS |
310 | yes "r" | git mergetool ../submod && |
311 | yes "d" "d" | git mergetool --no-prompt && | |
1e2ae142 | 312 | echo "main updated" >expect && |
e10dffd0 | 313 | test_cmp expect ../file1 && |
1e2ae142 | 314 | echo "main new" >expect && |
e10dffd0 | 315 | test_cmp expect ../file2 && |
1e2ae142 | 316 | echo "main new sub" >expect && |
e10dffd0 | 317 | test_cmp expect file3 && |
74578618 | 318 | ( cd .. && git submodule update -N ) && |
1e2ae142 | 319 | echo "main submodule" >expect && |
e10dffd0 | 320 | test_cmp expect ../submod/bar && |
74578618 DA |
321 | git commit -m "branch2 resolved by mergetool from subdir" |
322 | ) | |
bb0a484e | 323 | ' |
b9b5078e | 324 | |
2f59c947 | 325 | test_expect_success 'mergetool skips resolved paths when rerere is active' ' |
614eb27f | 326 | test_when_finished "git reset --hard" && |
f9e43085 | 327 | test_config rerere.enabled true && |
74578618 | 328 | rm -rf .git/rr-cache && |
ecfdf0bd | 329 | git checkout -b test$test_count branch1 && |
74578618 | 330 | git submodule update -N && |
1e2ae142 | 331 | test_must_fail git merge main && |
b4a04c8f JS |
332 | yes "l" | git mergetool --no-prompt submod && |
333 | yes "d" "d" | git mergetool --no-prompt && | |
74578618 DA |
334 | git submodule update -N && |
335 | output="$(yes "n" | git mergetool --no-prompt)" && | |
614eb27f | 336 | test "$output" = "No files need merging" |
2f59c947 MZ |
337 | ' |
338 | ||
743bf6d8 | 339 | test_expect_success 'conflicted stash sets up rerere' ' |
c3ad3126 | 340 | test_when_finished "git reset --hard" && |
f9e43085 | 341 | test_config rerere.enabled true && |
74578618 DA |
342 | git checkout stash1 && |
343 | echo "Conflicting stash content" >file11 && | |
344 | git stash && | |
345 | ||
346 | git checkout --detach stash2 && | |
347 | test_must_fail git stash apply && | |
348 | ||
349 | test -n "$(git ls-files -u)" && | |
350 | conflicts="$(git rerere remaining)" && | |
351 | test "$conflicts" = "file11" && | |
352 | output="$(git mergetool --no-prompt)" && | |
353 | test "$output" != "No files need merging" && | |
354 | ||
355 | git commit -am "save the stash resolution" && | |
356 | ||
357 | git reset --hard stash2 && | |
358 | test_must_fail git stash apply && | |
359 | ||
360 | test -n "$(git ls-files -u)" && | |
361 | conflicts="$(git rerere remaining)" && | |
362 | test -z "$conflicts" && | |
363 | output="$(git mergetool --no-prompt)" && | |
364 | test "$output" = "No files need merging" | |
79dc2d0b PH |
365 | ' |
366 | ||
3e8e691a | 367 | test_expect_success 'mergetool takes partial path' ' |
614eb27f | 368 | test_when_finished "git reset --hard" && |
f9e43085 | 369 | test_config rerere.enabled false && |
ecfdf0bd | 370 | git checkout -b test$test_count branch1 && |
74578618 | 371 | git submodule update -N && |
1e2ae142 | 372 | test_must_fail git merge main && |
74578618 | 373 | |
b4a04c8f | 374 | yes "" | git mergetool subdir && |
74578618 | 375 | |
1e2ae142 | 376 | echo "main new sub" >expect && |
e10dffd0 | 377 | test_cmp expect subdir/file3 |
3e8e691a JM |
378 | ' |
379 | ||
faaab8d5 | 380 | test_expect_success 'mergetool delete/delete conflict' ' |
bd9714f2 | 381 | test_when_finished "git reset --hard" && |
61b76d2d | 382 | git checkout -b test$test_count move-to-c && |
faaab8d5 DA |
383 | test_must_fail git merge move-to-b && |
384 | echo d | git mergetool a/a/file.txt && | |
385 | ! test -f a/a/file.txt && | |
bd9714f2 | 386 | git reset --hard && |
faaab8d5 DA |
387 | test_must_fail git merge move-to-b && |
388 | echo m | git mergetool a/a/file.txt && | |
389 | test -f b/b/file.txt && | |
bd9714f2 | 390 | git reset --hard && |
faaab8d5 DA |
391 | test_must_fail git merge move-to-b && |
392 | ! echo a | git mergetool a/a/file.txt && | |
614eb27f | 393 | ! test -f a/a/file.txt |
faaab8d5 DA |
394 | ' |
395 | ||
396 | test_expect_success 'mergetool produces no errors when keepBackup is used' ' | |
bd9714f2 | 397 | test_when_finished "git reset --hard" && |
fef6c06d | 398 | git checkout -b test$test_count move-to-c && |
faaab8d5 DA |
399 | test_config mergetool.keepBackup true && |
400 | test_must_fail git merge move-to-b && | |
faaab8d5 | 401 | echo d | git mergetool a/a/file.txt 2>actual && |
1c5e94f4 | 402 | test_must_be_empty actual && |
614eb27f | 403 | ! test -d a |
a2986045 DA |
404 | ' |
405 | ||
406 | test_expect_success 'mergetool honors tempfile config for deleted files' ' | |
bd9714f2 | 407 | test_when_finished "git reset --hard" && |
fef6c06d | 408 | git checkout -b test$test_count move-to-c && |
a2986045 DA |
409 | test_config mergetool.keepTemporaries false && |
410 | test_must_fail git merge move-to-b && | |
411 | echo d | git mergetool a/a/file.txt && | |
614eb27f | 412 | ! test -d a |
a2986045 DA |
413 | ' |
414 | ||
415 | test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' ' | |
bd9714f2 | 416 | test_when_finished "git reset --hard" && |
614eb27f | 417 | test_when_finished "git clean -fdx" && |
fef6c06d | 418 | git checkout -b test$test_count move-to-c && |
a2986045 DA |
419 | test_config mergetool.keepTemporaries true && |
420 | test_must_fail git merge move-to-b && | |
0590ff26 | 421 | ! test_write_lines a n | git mergetool a/a/file.txt && |
a2986045 DA |
422 | test -d a/a && |
423 | cat >expect <<-\EOF && | |
424 | file_BASE_.txt | |
425 | file_LOCAL_.txt | |
426 | file_REMOTE_.txt | |
427 | EOF | |
428 | ls -1 a/a | sed -e "s/[0-9]*//g" >actual && | |
614eb27f | 429 | test_cmp expect actual |
faaab8d5 DA |
430 | ' |
431 | ||
ff7f089e | 432 | test_expect_success 'deleted vs modified submodule' ' |
bd9714f2 | 433 | test_when_finished "git reset --hard" && |
ecfdf0bd | 434 | git checkout -b test$test_count branch1 && |
74578618 DA |
435 | git submodule update -N && |
436 | mv submod submod-movedaside && | |
437 | git rm --cached submod && | |
438 | git commit -m "Submodule deleted from branch" && | |
ecfdf0bd | 439 | git checkout -b test$test_count.a test$test_count && |
1e2ae142 | 440 | test_must_fail git merge main && |
74578618 | 441 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
442 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
443 | yes "" | git mergetool both && | |
444 | yes "d" | git mergetool file11 file12 && | |
445 | yes "r" | git mergetool submod && | |
74578618 | 446 | rmdir submod && mv submod-movedaside submod && |
e10dffd0 JS |
447 | echo "branch1 submodule" >expect && |
448 | test_cmp expect submod/bar && | |
74578618 | 449 | git submodule update -N && |
1e2ae142 | 450 | echo "main submodule" >expect && |
e10dffd0 | 451 | test_cmp expect submod/bar && |
74578618 DA |
452 | output="$(git mergetool --no-prompt)" && |
453 | test "$output" = "No files need merging" && | |
454 | git commit -m "Merge resolved by keeping module" && | |
455 | ||
456 | mv submod submod-movedaside && | |
ecfdf0bd | 457 | git checkout -b test$test_count.b test$test_count && |
74578618 | 458 | git submodule update -N && |
1e2ae142 | 459 | test_must_fail git merge main && |
74578618 | 460 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
461 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
462 | yes "" | git mergetool both && | |
463 | yes "d" | git mergetool file11 file12 && | |
464 | yes "l" | git mergetool submod && | |
74578618 DA |
465 | test ! -e submod && |
466 | output="$(git mergetool --no-prompt)" && | |
467 | test "$output" = "No files need merging" && | |
468 | git commit -m "Merge resolved by deleting module" && | |
469 | ||
470 | mv submod-movedaside submod && | |
1e2ae142 | 471 | git checkout -b test$test_count.c main && |
74578618 | 472 | git submodule update -N && |
ecfdf0bd | 473 | test_must_fail git merge test$test_count && |
74578618 | 474 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
475 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
476 | yes "" | git mergetool both && | |
477 | yes "d" | git mergetool file11 file12 && | |
478 | yes "r" | git mergetool submod && | |
74578618 DA |
479 | test ! -e submod && |
480 | test -d submod.orig && | |
481 | git submodule update -N && | |
482 | output="$(git mergetool --no-prompt)" && | |
483 | test "$output" = "No files need merging" && | |
484 | git commit -m "Merge resolved by deleting module" && | |
485 | mv submod.orig submod && | |
486 | ||
1e2ae142 | 487 | git checkout -b test$test_count.d main && |
74578618 | 488 | git submodule update -N && |
ecfdf0bd | 489 | test_must_fail git merge test$test_count && |
74578618 | 490 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
491 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
492 | yes "" | git mergetool both && | |
493 | yes "d" | git mergetool file11 file12 && | |
494 | yes "l" | git mergetool submod && | |
1e2ae142 | 495 | echo "main submodule" >expect && |
e10dffd0 | 496 | test_cmp expect submod/bar && |
74578618 | 497 | git submodule update -N && |
1e2ae142 | 498 | echo "main submodule" >expect && |
e10dffd0 | 499 | test_cmp expect submod/bar && |
74578618 DA |
500 | output="$(git mergetool --no-prompt)" && |
501 | test "$output" = "No files need merging" && | |
614eb27f | 502 | git commit -m "Merge resolved by keeping module" |
ff7f089e JM |
503 | ' |
504 | ||
505 | test_expect_success 'file vs modified submodule' ' | |
c3ad3126 | 506 | test_when_finished "git reset --hard" && |
ecfdf0bd | 507 | git checkout -b test$test_count branch1 && |
74578618 DA |
508 | git submodule update -N && |
509 | mv submod submod-movedaside && | |
510 | git rm --cached submod && | |
511 | echo not a submodule >submod && | |
512 | git add submod && | |
513 | git commit -m "Submodule path becomes file" && | |
ecfdf0bd | 514 | git checkout -b test$test_count.a branch1 && |
1e2ae142 | 515 | test_must_fail git merge main && |
74578618 | 516 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
517 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
518 | yes "" | git mergetool both && | |
519 | yes "d" | git mergetool file11 file12 && | |
520 | yes "r" | git mergetool submod && | |
74578618 | 521 | rmdir submod && mv submod-movedaside submod && |
e10dffd0 JS |
522 | echo "branch1 submodule" >expect && |
523 | test_cmp expect submod/bar && | |
74578618 | 524 | git submodule update -N && |
1e2ae142 | 525 | echo "main submodule" >expect && |
e10dffd0 | 526 | test_cmp expect submod/bar && |
74578618 DA |
527 | output="$(git mergetool --no-prompt)" && |
528 | test "$output" = "No files need merging" && | |
529 | git commit -m "Merge resolved by keeping module" && | |
530 | ||
531 | mv submod submod-movedaside && | |
ecfdf0bd | 532 | git checkout -b test$test_count.b test$test_count && |
1e2ae142 | 533 | test_must_fail git merge main && |
74578618 | 534 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
535 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
536 | yes "" | git mergetool both && | |
537 | yes "d" | git mergetool file11 file12 && | |
ef527787 EN |
538 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
539 | then | |
540 | yes "c" | git mergetool submod~HEAD && | |
541 | git rm submod && | |
542 | git mv submod~HEAD submod | |
543 | else | |
544 | yes "l" | git mergetool submod | |
545 | fi && | |
74578618 | 546 | git submodule update -N && |
e10dffd0 JS |
547 | echo "not a submodule" >expect && |
548 | test_cmp expect submod && | |
74578618 DA |
549 | output="$(git mergetool --no-prompt)" && |
550 | test "$output" = "No files need merging" && | |
551 | git commit -m "Merge resolved by keeping file" && | |
552 | ||
1e2ae142 | 553 | git checkout -b test$test_count.c main && |
74578618 DA |
554 | rmdir submod && mv submod-movedaside submod && |
555 | test ! -e submod.orig && | |
556 | git submodule update -N && | |
ecfdf0bd | 557 | test_must_fail git merge test$test_count && |
74578618 | 558 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
559 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
560 | yes "" | git mergetool both && | |
561 | yes "d" | git mergetool file11 file12 && | |
ef527787 EN |
562 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
563 | then | |
564 | mv submod submod.orig && | |
565 | git rm --cached submod && | |
566 | yes "c" | git mergetool submod~test19 && | |
567 | git mv submod~test19 submod | |
568 | else | |
569 | yes "r" | git mergetool submod | |
570 | fi && | |
74578618 DA |
571 | test -d submod.orig && |
572 | git submodule update -N && | |
e10dffd0 JS |
573 | echo "not a submodule" >expect && |
574 | test_cmp expect submod && | |
74578618 DA |
575 | output="$(git mergetool --no-prompt)" && |
576 | test "$output" = "No files need merging" && | |
577 | git commit -m "Merge resolved by keeping file" && | |
578 | ||
1e2ae142 | 579 | git checkout -b test$test_count.d main && |
74578618 DA |
580 | rmdir submod && mv submod.orig submod && |
581 | git submodule update -N && | |
ecfdf0bd | 582 | test_must_fail git merge test$test_count && |
74578618 | 583 | test -n "$(git ls-files -u)" && |
b4a04c8f JS |
584 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
585 | yes "" | git mergetool both && | |
586 | yes "d" | git mergetool file11 file12 && | |
587 | yes "l" | git mergetool submod && | |
ef527787 EN |
588 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
589 | then | |
590 | yes "d" | git mergetool submod~test19 | |
591 | fi && | |
1e2ae142 | 592 | echo "main submodule" >expect && |
e10dffd0 | 593 | test_cmp expect submod/bar && |
74578618 | 594 | git submodule update -N && |
1e2ae142 | 595 | echo "main submodule" >expect && |
e10dffd0 | 596 | test_cmp expect submod/bar && |
74578618 DA |
597 | output="$(git mergetool --no-prompt)" && |
598 | test "$output" = "No files need merging" && | |
599 | git commit -m "Merge resolved by keeping module" | |
ff7f089e JM |
600 | ' |
601 | ||
602 | test_expect_success 'submodule in subdirectory' ' | |
c3ad3126 | 603 | test_when_finished "git reset --hard" && |
ecfdf0bd | 604 | git checkout -b test$test_count branch1 && |
74578618 DA |
605 | git submodule update -N && |
606 | ( | |
607 | cd subdir && | |
608 | test_create_repo subdir_module && | |
609 | ( | |
610 | cd subdir_module && | |
611 | : >file15 && | |
612 | git add file15 && | |
613 | git commit -m "add initial versions" | |
614 | ) | |
615 | ) && | |
614eb27f | 616 | test_when_finished "rm -rf subdir/subdir_module" && |
23fb328c | 617 | git submodule add file:///dev/null subdir/subdir_module && |
74578618 DA |
618 | git add subdir/subdir_module && |
619 | git commit -m "add submodule in subdirectory" && | |
620 | ||
ecfdf0bd | 621 | git checkout -b test$test_count.a test$test_count && |
74578618 | 622 | git submodule update -N && |
ff7f089e | 623 | ( |
ff7f089e | 624 | cd subdir/subdir_module && |
74578618 | 625 | git checkout -b super10.a && |
ecfdf0bd | 626 | echo test$test_count.a >file15 && |
74578618 DA |
627 | git add file15 && |
628 | git commit -m "on branch 10.a" | |
629 | ) && | |
630 | git add subdir/subdir_module && | |
ecfdf0bd | 631 | git commit -m "change submodule in subdirectory on test$test_count.a" && |
74578618 | 632 | |
ecfdf0bd | 633 | git checkout -b test$test_count.b test$test_count && |
74578618 DA |
634 | git submodule update -N && |
635 | ( | |
636 | cd subdir/subdir_module && | |
637 | git checkout -b super10.b && | |
ecfdf0bd | 638 | echo test$test_count.b >file15 && |
74578618 DA |
639 | git add file15 && |
640 | git commit -m "on branch 10.b" | |
641 | ) && | |
642 | git add subdir/subdir_module && | |
ecfdf0bd | 643 | git commit -m "change submodule in subdirectory on test$test_count.b" && |
74578618 | 644 | |
e9d309e2 | 645 | test_must_fail git merge test$test_count.a && |
74578618 DA |
646 | ( |
647 | cd subdir && | |
b4a04c8f | 648 | yes "l" | git mergetool subdir_module |
74578618 | 649 | ) && |
e10dffd0 JS |
650 | echo "test$test_count.b" >expect && |
651 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 | 652 | git submodule update -N && |
e10dffd0 JS |
653 | echo "test$test_count.b" >expect && |
654 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 DA |
655 | git reset --hard && |
656 | git submodule update -N && | |
657 | ||
e9d309e2 | 658 | test_must_fail git merge test$test_count.a && |
b4a04c8f | 659 | yes "r" | git mergetool subdir/subdir_module && |
e10dffd0 JS |
660 | echo "test$test_count.b" >expect && |
661 | test_cmp expect subdir/subdir_module/file15 && | |
74578618 | 662 | git submodule update -N && |
e10dffd0 JS |
663 | echo "test$test_count.a" >expect && |
664 | test_cmp expect subdir/subdir_module/file15 && | |
614eb27f | 665 | git commit -m "branch1 resolved with mergetool" |
ff7f089e JM |
666 | ' |
667 | ||
668 | test_expect_success 'directory vs modified submodule' ' | |
c3ad3126 | 669 | test_when_finished "git reset --hard" && |
ecfdf0bd | 670 | git checkout -b test$test_count branch1 && |
74578618 DA |
671 | mv submod submod-movedaside && |
672 | git rm --cached submod && | |
673 | mkdir submod && | |
674 | echo not a submodule >submod/file16 && | |
675 | git add submod/file16 && | |
676 | git commit -m "Submodule path becomes directory" && | |
677 | ||
1e2ae142 | 678 | test_must_fail git merge main && |
74578618 | 679 | test -n "$(git ls-files -u)" && |
b4a04c8f | 680 | yes "l" | git mergetool submod && |
e10dffd0 JS |
681 | echo "not a submodule" >expect && |
682 | test_cmp expect submod/file16 && | |
74578618 DA |
683 | rm -rf submod.orig && |
684 | ||
bd9714f2 | 685 | git reset --hard && |
1e2ae142 | 686 | test_must_fail git merge main && |
74578618 DA |
687 | test -n "$(git ls-files -u)" && |
688 | test ! -e submod.orig && | |
ef527787 EN |
689 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
690 | then | |
1e2ae142 | 691 | yes "r" | git mergetool submod~main && |
ef527787 | 692 | git mv submod submod.orig && |
1e2ae142 | 693 | git mv submod~main submod |
ef527787 EN |
694 | else |
695 | yes "r" | git mergetool submod | |
696 | fi && | |
74578618 | 697 | test -d submod.orig && |
e10dffd0 JS |
698 | echo "not a submodule" >expect && |
699 | test_cmp expect submod.orig/file16 && | |
74578618 DA |
700 | rm -r submod.orig && |
701 | mv submod-movedaside/.git submod && | |
702 | ( cd submod && git clean -f && git reset --hard ) && | |
703 | git submodule update -N && | |
1e2ae142 | 704 | echo "main submodule" >expect && |
e10dffd0 | 705 | test_cmp expect submod/bar && |
bd9714f2 RH |
706 | git reset --hard && |
707 | rm -rf submod-movedaside && | |
74578618 | 708 | |
1e2ae142 | 709 | git checkout -b test$test_count.c main && |
74578618 | 710 | git submodule update -N && |
ecfdf0bd | 711 | test_must_fail git merge test$test_count && |
74578618 | 712 | test -n "$(git ls-files -u)" && |
b4a04c8f | 713 | yes "l" | git mergetool submod && |
74578618 | 714 | git submodule update -N && |
1e2ae142 | 715 | echo "main submodule" >expect && |
e10dffd0 | 716 | test_cmp expect submod/bar && |
74578618 | 717 | |
bd9714f2 | 718 | git reset --hard && |
74578618 | 719 | git submodule update -N && |
ecfdf0bd | 720 | test_must_fail git merge test$test_count && |
74578618 DA |
721 | test -n "$(git ls-files -u)" && |
722 | test ! -e submod.orig && | |
b4a04c8f | 723 | yes "r" | git mergetool submod && |
e10dffd0 JS |
724 | echo "not a submodule" >expect && |
725 | test_cmp expect submod/file16 && | |
74578618 | 726 | |
1e2ae142 | 727 | git reset --hard main && |
74578618 DA |
728 | ( cd submod && git clean -f && git reset --hard ) && |
729 | git submodule update -N | |
ff7f089e JM |
730 | ' |
731 | ||
ec245ba0 | 732 | test_expect_success 'file with no base' ' |
bd9714f2 | 733 | test_when_finished "git reset --hard" && |
ecfdf0bd | 734 | git checkout -b test$test_count branch1 && |
1e2ae142 | 735 | test_must_fail git merge main && |
74578618 | 736 | git mergetool --no-prompt --tool mybase -- both && |
d3c6751b | 737 | test_must_be_empty both |
ec245ba0 DA |
738 | ' |
739 | ||
a427ef7a | 740 | test_expect_success 'custom commands override built-ins' ' |
bd9714f2 | 741 | test_when_finished "git reset --hard" && |
ecfdf0bd | 742 | git checkout -b test$test_count branch1 && |
f9e43085 DA |
743 | test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && |
744 | test_config mergetool.defaults.trustExitCode true && | |
1e2ae142 | 745 | test_must_fail git merge main && |
74578618 | 746 | git mergetool --no-prompt --tool defaults -- both && |
1e2ae142 | 747 | echo main both added >expected && |
9c5b2fab | 748 | test_cmp expected both |
a427ef7a DA |
749 | ' |
750 | ||
688684eb | 751 | test_expect_success 'filenames seen by tools start with ./' ' |
bd9714f2 | 752 | test_when_finished "git reset --hard" && |
ecfdf0bd | 753 | git checkout -b test$test_count branch1 && |
688684eb DA |
754 | test_config mergetool.writeToTemp false && |
755 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
756 | test_config mergetool.myecho.trustExitCode true && | |
1e2ae142 | 757 | test_must_fail git merge main && |
688684eb | 758 | git mergetool --no-prompt --tool myecho -- both >actual && |
e9d309e2 | 759 | grep ^\./both_LOCAL_ actual |
688684eb DA |
760 | ' |
761 | ||
c578a09b AK |
762 | test_lazy_prereq MKTEMP ' |
763 | tempdir=$(mktemp -d -t foo.XXXXXX) && | |
fa3142c9 JK |
764 | test -d "$tempdir" && |
765 | rmdir "$tempdir" | |
c578a09b AK |
766 | ' |
767 | ||
768 | test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' ' | |
bd9714f2 | 769 | test_when_finished "git reset --hard" && |
ecfdf0bd | 770 | git checkout -b test$test_count branch1 && |
688684eb DA |
771 | test_config mergetool.writeToTemp true && |
772 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
773 | test_config mergetool.myecho.trustExitCode true && | |
1e2ae142 | 774 | test_must_fail git merge main && |
688684eb | 775 | git mergetool --no-prompt --tool myecho -- both >actual && |
e9d309e2 DL |
776 | ! grep ^\./both_LOCAL_ actual && |
777 | grep /both_LOCAL_ actual | |
688684eb DA |
778 | ' |
779 | ||
57937f70 | 780 | test_expect_success 'diff.orderFile configuration is honored' ' |
bd9714f2 | 781 | test_when_finished "git reset --hard" && |
61b76d2d | 782 | git checkout -b test$test_count order-file-side2 && |
57937f70 DA |
783 | test_config diff.orderFile order-file && |
784 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
785 | test_config mergetool.myecho.trustExitCode true && | |
786 | echo b >order-file && | |
787 | echo a >>order-file && | |
57937f70 DA |
788 | test_must_fail git merge order-file-side1 && |
789 | cat >expect <<-\EOF && | |
790 | Merging: | |
791 | b | |
792 | a | |
793 | EOF | |
d0e0cfe7 RH |
794 | |
795 | # make sure "order-file" that is ambiguous between | |
796 | # rev and path is understood correctly. | |
797 | git branch order-file HEAD && | |
798 | ||
57937f70 DA |
799 | git mergetool --no-prompt --tool myecho >output && |
800 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 801 | test_cmp expect actual |
57937f70 | 802 | ' |
654311bf | 803 | test_expect_success 'mergetool -Oorder-file is honored' ' |
bd9714f2 | 804 | test_when_finished "git reset --hard" && |
fef6c06d | 805 | git checkout -b test$test_count order-file-side2 && |
654311bf DA |
806 | test_config diff.orderFile order-file && |
807 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && | |
808 | test_config mergetool.myecho.trustExitCode true && | |
b696ac9a RH |
809 | echo b >order-file && |
810 | echo a >>order-file && | |
654311bf DA |
811 | test_must_fail git merge order-file-side1 && |
812 | cat >expect <<-\EOF && | |
813 | Merging: | |
814 | a | |
815 | b | |
816 | EOF | |
817 | git mergetool -O/dev/null --no-prompt --tool myecho >output && | |
818 | git grep --no-index -h -A2 Merging: output >actual && | |
819 | test_cmp expect actual && | |
bd9714f2 | 820 | git reset --hard && |
654311bf DA |
821 | |
822 | git config --unset diff.orderFile && | |
823 | test_must_fail git merge order-file-side1 && | |
824 | cat >expect <<-\EOF && | |
825 | Merging: | |
826 | b | |
827 | a | |
828 | EOF | |
829 | git mergetool -Oorder-file --no-prompt --tool myecho >output && | |
830 | git grep --no-index -h -A2 Merging: output >actual && | |
614eb27f | 831 | test_cmp expect actual |
654311bf | 832 | ' |
57937f70 | 833 | |
80f5a167 PB |
834 | test_expect_success 'mergetool --tool-help shows recognized tools' ' |
835 | # Check a few known tools are correctly shown | |
836 | git mergetool --tool-help >mergetools && | |
837 | grep vimdiff mergetools && | |
838 | grep vimdiff3 mergetools && | |
839 | grep gvimdiff2 mergetools && | |
840 | grep araxis mergetools && | |
841 | grep xxdiff mergetools && | |
842 | grep meld mergetools | |
843 | ' | |
844 | ||
98ea309b SH |
845 | test_expect_success 'mergetool hideResolved' ' |
846 | test_config mergetool.hideResolved true && | |
847 | test_when_finished "git reset --hard" && | |
78a26cb7 | 848 | git checkout -b test${test_count}_b main && |
98ea309b SH |
849 | test_write_lines >file1 base "" a && |
850 | git commit -a -m "base" && | |
851 | test_write_lines >file1 base "" c && | |
852 | git commit -a -m "remote update" && | |
853 | git checkout -b test${test_count}_a HEAD~ && | |
854 | test_write_lines >file1 local "" b && | |
855 | git commit -a -m "local update" && | |
856 | test_must_fail git merge test${test_count}_b && | |
857 | yes "" | git mergetool file1 && | |
858 | test_write_lines >expect local "" c && | |
859 | test_cmp expect file1 && | |
860 | git commit -m "test resolved with mergetool" | |
861 | ' | |
862 | ||
42943b95 TK |
863 | test_expect_success 'mergetool with guiDefault' ' |
864 | test_config merge.guitool myguitool && | |
865 | test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" && | |
866 | test_config mergetool.myguitool.trustExitCode true && | |
867 | test_when_finished "git reset --hard" && | |
868 | git checkout -b test$test_count branch1 && | |
869 | git submodule update -N && | |
870 | test_must_fail git merge main && | |
871 | ||
872 | test_config mergetool.guiDefault auto && | |
873 | DISPLAY=SOMETHING && export DISPLAY && | |
874 | yes "" | git mergetool both && | |
875 | yes "" | git mergetool file1 file1 && | |
876 | ||
877 | DISPLAY= && export DISPLAY && | |
878 | yes "" | git mergetool file2 "spaced name" && | |
879 | ||
880 | test_config mergetool.guiDefault true && | |
881 | yes "" | git mergetool subdir/file3 && | |
882 | ||
883 | yes "d" | git mergetool file11 && | |
884 | yes "d" | git mergetool file12 && | |
885 | yes "l" | git mergetool submod && | |
886 | ||
887 | echo "gui main updated" >expect && | |
888 | test_cmp expect file1 && | |
889 | ||
890 | echo "main new" >expect && | |
891 | test_cmp expect file2 && | |
892 | ||
893 | echo "gui main new sub" >expect && | |
894 | test_cmp expect subdir/file3 && | |
895 | ||
896 | echo "branch1 submodule" >expect && | |
897 | test_cmp expect submod/bar && | |
898 | git commit -m "branch1 resolved with mergetool" | |
899 | ' | |
900 | ||
05e934bb | 901 | test_done |