]>
Commit | Line | Data |
---|---|---|
885b9810 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='merge-recursive backend test' | |
4 | ||
5 | . ./test-lib.sh | |
f06481f1 | 6 | . "$TEST_DIRECTORY"/lib-merge.sh |
885b9810 JH |
7 | |
8 | test_expect_success 'setup 1' ' | |
9 | ||
10 | echo hello >a && | |
11 | o0=$(git hash-object a) && | |
12 | cp a b && | |
744747ef | 13 | cp a c && |
885b9810 JH |
14 | mkdir d && |
15 | cp a d/e && | |
16 | ||
17 | test_tick && | |
744747ef | 18 | git add a b c d/e && |
885b9810 JH |
19 | git commit -m initial && |
20 | c0=$(git rev-parse --verify HEAD) && | |
21 | git branch side && | |
22 | git branch df-1 && | |
23 | git branch df-2 && | |
24 | git branch df-3 && | |
25 | git branch remove && | |
7d82b06d | 26 | git branch submod && |
d5af5105 SK |
27 | git branch copy && |
28 | git branch rename && | |
bba56042 | 29 | git branch rename-ln && |
885b9810 JH |
30 | |
31 | echo hello >>a && | |
32 | cp a d/e && | |
33 | o1=$(git hash-object a) && | |
34 | ||
35 | git add a d/e && | |
36 | ||
37 | test_tick && | |
38 | git commit -m "master modifies a and d/e" && | |
39 | c1=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 40 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 41 | ( |
b6c32f63 ES |
42 | echo "100644 blob $o1 a" && |
43 | echo "100644 blob $o0 b" && | |
44 | echo "100644 blob $o0 c" && | |
45 | echo "100644 blob $o1 d/e" && | |
46 | echo "100644 $o1 0 a" && | |
47 | echo "100644 $o0 0 b" && | |
48 | echo "100644 $o0 0 c" && | |
885b9810 JH |
49 | echo "100644 $o1 0 d/e" |
50 | ) >expected && | |
3af82863 | 51 | test_cmp expected actual |
885b9810 JH |
52 | ' |
53 | ||
54 | test_expect_success 'setup 2' ' | |
55 | ||
744747ef | 56 | rm -rf [abcd] && |
885b9810 | 57 | git checkout side && |
b6c32f63 | 58 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 59 | ( |
b6c32f63 ES |
60 | echo "100644 blob $o0 a" && |
61 | echo "100644 blob $o0 b" && | |
62 | echo "100644 blob $o0 c" && | |
63 | echo "100644 blob $o0 d/e" && | |
64 | echo "100644 $o0 0 a" && | |
65 | echo "100644 $o0 0 b" && | |
66 | echo "100644 $o0 0 c" && | |
885b9810 JH |
67 | echo "100644 $o0 0 d/e" |
68 | ) >expected && | |
3af82863 | 69 | test_cmp expected actual && |
885b9810 JH |
70 | |
71 | echo goodbye >>a && | |
72 | o2=$(git hash-object a) && | |
73 | ||
74 | git add a && | |
75 | ||
76 | test_tick && | |
77 | git commit -m "side modifies a" && | |
78 | c2=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 79 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 80 | ( |
b6c32f63 ES |
81 | echo "100644 blob $o2 a" && |
82 | echo "100644 blob $o0 b" && | |
83 | echo "100644 blob $o0 c" && | |
84 | echo "100644 blob $o0 d/e" && | |
85 | echo "100644 $o2 0 a" && | |
86 | echo "100644 $o0 0 b" && | |
87 | echo "100644 $o0 0 c" && | |
885b9810 JH |
88 | echo "100644 $o0 0 d/e" |
89 | ) >expected && | |
3af82863 | 90 | test_cmp expected actual |
885b9810 JH |
91 | ' |
92 | ||
93 | test_expect_success 'setup 3' ' | |
94 | ||
744747ef | 95 | rm -rf [abcd] && |
885b9810 | 96 | git checkout df-1 && |
b6c32f63 | 97 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 98 | ( |
b6c32f63 ES |
99 | echo "100644 blob $o0 a" && |
100 | echo "100644 blob $o0 b" && | |
101 | echo "100644 blob $o0 c" && | |
102 | echo "100644 blob $o0 d/e" && | |
103 | echo "100644 $o0 0 a" && | |
104 | echo "100644 $o0 0 b" && | |
105 | echo "100644 $o0 0 c" && | |
885b9810 JH |
106 | echo "100644 $o0 0 d/e" |
107 | ) >expected && | |
3af82863 | 108 | test_cmp expected actual && |
885b9810 JH |
109 | |
110 | rm -f b && mkdir b && echo df-1 >b/c && git add b/c && | |
111 | o3=$(git hash-object b/c) && | |
112 | ||
113 | test_tick && | |
114 | git commit -m "df-1 makes b/c" && | |
115 | c3=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 116 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 117 | ( |
b6c32f63 ES |
118 | echo "100644 blob $o0 a" && |
119 | echo "100644 blob $o3 b/c" && | |
120 | echo "100644 blob $o0 c" && | |
121 | echo "100644 blob $o0 d/e" && | |
122 | echo "100644 $o0 0 a" && | |
123 | echo "100644 $o3 0 b/c" && | |
124 | echo "100644 $o0 0 c" && | |
885b9810 JH |
125 | echo "100644 $o0 0 d/e" |
126 | ) >expected && | |
3af82863 | 127 | test_cmp expected actual |
885b9810 JH |
128 | ' |
129 | ||
130 | test_expect_success 'setup 4' ' | |
131 | ||
744747ef | 132 | rm -rf [abcd] && |
885b9810 | 133 | git checkout df-2 && |
b6c32f63 | 134 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 135 | ( |
b6c32f63 ES |
136 | echo "100644 blob $o0 a" && |
137 | echo "100644 blob $o0 b" && | |
138 | echo "100644 blob $o0 c" && | |
139 | echo "100644 blob $o0 d/e" && | |
140 | echo "100644 $o0 0 a" && | |
141 | echo "100644 $o0 0 b" && | |
142 | echo "100644 $o0 0 c" && | |
885b9810 JH |
143 | echo "100644 $o0 0 d/e" |
144 | ) >expected && | |
3af82863 | 145 | test_cmp expected actual && |
885b9810 JH |
146 | |
147 | rm -f a && mkdir a && echo df-2 >a/c && git add a/c && | |
148 | o4=$(git hash-object a/c) && | |
149 | ||
150 | test_tick && | |
151 | git commit -m "df-2 makes a/c" && | |
152 | c4=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 153 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 154 | ( |
b6c32f63 ES |
155 | echo "100644 blob $o4 a/c" && |
156 | echo "100644 blob $o0 b" && | |
157 | echo "100644 blob $o0 c" && | |
158 | echo "100644 blob $o0 d/e" && | |
159 | echo "100644 $o4 0 a/c" && | |
160 | echo "100644 $o0 0 b" && | |
161 | echo "100644 $o0 0 c" && | |
885b9810 JH |
162 | echo "100644 $o0 0 d/e" |
163 | ) >expected && | |
3af82863 | 164 | test_cmp expected actual |
885b9810 JH |
165 | ' |
166 | ||
167 | test_expect_success 'setup 5' ' | |
168 | ||
744747ef | 169 | rm -rf [abcd] && |
885b9810 | 170 | git checkout remove && |
b6c32f63 | 171 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 172 | ( |
b6c32f63 ES |
173 | echo "100644 blob $o0 a" && |
174 | echo "100644 blob $o0 b" && | |
175 | echo "100644 blob $o0 c" && | |
176 | echo "100644 blob $o0 d/e" && | |
177 | echo "100644 $o0 0 a" && | |
178 | echo "100644 $o0 0 b" && | |
179 | echo "100644 $o0 0 c" && | |
885b9810 JH |
180 | echo "100644 $o0 0 d/e" |
181 | ) >expected && | |
3af82863 | 182 | test_cmp expected actual && |
885b9810 JH |
183 | |
184 | rm -f b && | |
185 | echo remove-conflict >a && | |
186 | ||
187 | git add a && | |
188 | git rm b && | |
189 | o5=$(git hash-object a) && | |
190 | ||
191 | test_tick && | |
192 | git commit -m "remove removes b and modifies a" && | |
193 | c5=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 194 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 195 | ( |
b6c32f63 ES |
196 | echo "100644 blob $o5 a" && |
197 | echo "100644 blob $o0 c" && | |
198 | echo "100644 blob $o0 d/e" && | |
199 | echo "100644 $o5 0 a" && | |
200 | echo "100644 $o0 0 c" && | |
885b9810 JH |
201 | echo "100644 $o0 0 d/e" |
202 | ) >expected && | |
3af82863 | 203 | test_cmp expected actual |
885b9810 JH |
204 | |
205 | ' | |
206 | ||
207 | test_expect_success 'setup 6' ' | |
208 | ||
744747ef | 209 | rm -rf [abcd] && |
885b9810 | 210 | git checkout df-3 && |
b6c32f63 | 211 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 212 | ( |
b6c32f63 ES |
213 | echo "100644 blob $o0 a" && |
214 | echo "100644 blob $o0 b" && | |
215 | echo "100644 blob $o0 c" && | |
216 | echo "100644 blob $o0 d/e" && | |
217 | echo "100644 $o0 0 a" && | |
218 | echo "100644 $o0 0 b" && | |
219 | echo "100644 $o0 0 c" && | |
885b9810 JH |
220 | echo "100644 $o0 0 d/e" |
221 | ) >expected && | |
3af82863 | 222 | test_cmp expected actual && |
885b9810 JH |
223 | |
224 | rm -fr d && echo df-3 >d && git add d && | |
225 | o6=$(git hash-object d) && | |
226 | ||
227 | test_tick && | |
228 | git commit -m "df-3 makes d" && | |
229 | c6=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 230 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 231 | ( |
b6c32f63 ES |
232 | echo "100644 blob $o0 a" && |
233 | echo "100644 blob $o0 b" && | |
234 | echo "100644 blob $o0 c" && | |
235 | echo "100644 blob $o6 d" && | |
236 | echo "100644 $o0 0 a" && | |
237 | echo "100644 $o0 0 b" && | |
238 | echo "100644 $o0 0 c" && | |
885b9810 JH |
239 | echo "100644 $o6 0 d" |
240 | ) >expected && | |
3af82863 | 241 | test_cmp expected actual |
885b9810 JH |
242 | ' |
243 | ||
7d82b06d JS |
244 | test_expect_success 'setup 7' ' |
245 | ||
246 | git checkout submod && | |
247 | git rm d/e && | |
248 | test_tick && | |
249 | git commit -m "remove d/e" && | |
250 | git update-index --add --cacheinfo 160000 $c1 d && | |
251 | test_tick && | |
252 | git commit -m "make d/ a submodule" | |
253 | ' | |
254 | ||
d5af5105 SK |
255 | test_expect_success 'setup 8' ' |
256 | git checkout rename && | |
257 | git mv a e && | |
258 | git add e && | |
259 | test_tick && | |
8a1c0d32 | 260 | git commit -m "rename a->e" && |
29d9af58 | 261 | c7=$(git rev-parse --verify HEAD) && |
bba56042 JS |
262 | git checkout rename-ln && |
263 | git mv a e && | |
264 | test_ln_s_add e a && | |
265 | test_tick && | |
266 | git commit -m "rename a->e, symlink a->e" && | |
85aea1e7 | 267 | oln=$(printf e | git hash-object --stdin) |
d5af5105 SK |
268 | ' |
269 | ||
270 | test_expect_success 'setup 9' ' | |
271 | git checkout copy && | |
272 | cp a e && | |
273 | git add e && | |
274 | test_tick && | |
275 | git commit -m "copy a->e" | |
276 | ' | |
277 | ||
885b9810 JH |
278 | test_expect_success 'merge-recursive simple' ' |
279 | ||
744747ef | 280 | rm -fr [abcd] && |
885b9810 JH |
281 | git checkout -f "$c2" && |
282 | ||
67b6afe1 | 283 | test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1" |
885b9810 JH |
284 | ' |
285 | ||
286 | test_expect_success 'merge-recursive result' ' | |
287 | ||
288 | git ls-files -s >actual && | |
289 | ( | |
b6c32f63 ES |
290 | echo "100644 $o0 1 a" && |
291 | echo "100644 $o2 2 a" && | |
292 | echo "100644 $o1 3 a" && | |
293 | echo "100644 $o0 0 b" && | |
294 | echo "100644 $o0 0 c" && | |
885b9810 JH |
295 | echo "100644 $o1 0 d/e" |
296 | ) >expected && | |
3af82863 | 297 | test_cmp expected actual |
885b9810 JH |
298 | |
299 | ' | |
300 | ||
f2c8c800 | 301 | test_expect_success 'fail if the index has unresolved entries' ' |
446247db JH |
302 | |
303 | rm -fr [abcd] && | |
304 | git checkout -f "$c1" && | |
305 | ||
306 | test_must_fail git merge "$c5" && | |
307 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 308 | test_i18ngrep "not possible because you have unmerged files" out && |
d38a30df MM |
309 | git add -u && |
310 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 311 | test_i18ngrep "You have not concluded your merge" out && |
c8c562a2 CB |
312 | rm -f .git/MERGE_HEAD && |
313 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 314 | test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out |
446247db JH |
315 | ' |
316 | ||
885b9810 JH |
317 | test_expect_success 'merge-recursive remove conflict' ' |
318 | ||
744747ef | 319 | rm -fr [abcd] && |
885b9810 JH |
320 | git checkout -f "$c1" && |
321 | ||
67b6afe1 | 322 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5" |
885b9810 JH |
323 | ' |
324 | ||
325 | test_expect_success 'merge-recursive remove conflict' ' | |
326 | ||
327 | git ls-files -s >actual && | |
328 | ( | |
b6c32f63 ES |
329 | echo "100644 $o0 1 a" && |
330 | echo "100644 $o1 2 a" && | |
331 | echo "100644 $o5 3 a" && | |
332 | echo "100644 $o0 0 c" && | |
885b9810 JH |
333 | echo "100644 $o1 0 d/e" |
334 | ) >expected && | |
3af82863 | 335 | test_cmp expected actual |
885b9810 JH |
336 | |
337 | ' | |
338 | ||
339 | test_expect_success 'merge-recursive d/f simple' ' | |
744747ef | 340 | rm -fr [abcd] && |
885b9810 JH |
341 | git reset --hard && |
342 | git checkout -f "$c1" && | |
343 | ||
0cb0e143 | 344 | git merge-recursive "$c0" -- "$c1" "$c3" |
885b9810 JH |
345 | ' |
346 | ||
347 | test_expect_success 'merge-recursive result' ' | |
348 | ||
349 | git ls-files -s >actual && | |
350 | ( | |
b6c32f63 ES |
351 | echo "100644 $o1 0 a" && |
352 | echo "100644 $o3 0 b/c" && | |
353 | echo "100644 $o0 0 c" && | |
885b9810 JH |
354 | echo "100644 $o1 0 d/e" |
355 | ) >expected && | |
3af82863 | 356 | test_cmp expected actual |
885b9810 JH |
357 | |
358 | ' | |
359 | ||
360 | test_expect_success 'merge-recursive d/f conflict' ' | |
361 | ||
744747ef | 362 | rm -fr [abcd] && |
885b9810 JH |
363 | git reset --hard && |
364 | git checkout -f "$c1" && | |
365 | ||
67b6afe1 | 366 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4" |
885b9810 JH |
367 | ' |
368 | ||
369 | test_expect_success 'merge-recursive d/f conflict result' ' | |
370 | ||
371 | git ls-files -s >actual && | |
372 | ( | |
b6c32f63 ES |
373 | echo "100644 $o0 1 a" && |
374 | echo "100644 $o1 2 a" && | |
375 | echo "100644 $o4 0 a/c" && | |
376 | echo "100644 $o0 0 b" && | |
377 | echo "100644 $o0 0 c" && | |
885b9810 JH |
378 | echo "100644 $o1 0 d/e" |
379 | ) >expected && | |
3af82863 | 380 | test_cmp expected actual |
885b9810 JH |
381 | |
382 | ' | |
383 | ||
384 | test_expect_success 'merge-recursive d/f conflict the other way' ' | |
385 | ||
744747ef | 386 | rm -fr [abcd] && |
885b9810 JH |
387 | git reset --hard && |
388 | git checkout -f "$c4" && | |
389 | ||
67b6afe1 | 390 | test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1" |
885b9810 JH |
391 | ' |
392 | ||
393 | test_expect_success 'merge-recursive d/f conflict result the other way' ' | |
394 | ||
395 | git ls-files -s >actual && | |
396 | ( | |
b6c32f63 ES |
397 | echo "100644 $o0 1 a" && |
398 | echo "100644 $o1 3 a" && | |
399 | echo "100644 $o4 0 a/c" && | |
400 | echo "100644 $o0 0 b" && | |
401 | echo "100644 $o0 0 c" && | |
885b9810 JH |
402 | echo "100644 $o1 0 d/e" |
403 | ) >expected && | |
3af82863 | 404 | test_cmp expected actual |
885b9810 JH |
405 | |
406 | ' | |
407 | ||
408 | test_expect_success 'merge-recursive d/f conflict' ' | |
409 | ||
744747ef | 410 | rm -fr [abcd] && |
885b9810 JH |
411 | git reset --hard && |
412 | git checkout -f "$c1" && | |
413 | ||
67b6afe1 | 414 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6" |
885b9810 JH |
415 | ' |
416 | ||
417 | test_expect_success 'merge-recursive d/f conflict result' ' | |
418 | ||
419 | git ls-files -s >actual && | |
420 | ( | |
b6c32f63 ES |
421 | echo "100644 $o1 0 a" && |
422 | echo "100644 $o0 0 b" && | |
423 | echo "100644 $o0 0 c" && | |
424 | echo "100644 $o6 3 d" && | |
425 | echo "100644 $o0 1 d/e" && | |
885b9810 JH |
426 | echo "100644 $o1 2 d/e" |
427 | ) >expected && | |
3af82863 | 428 | test_cmp expected actual |
885b9810 JH |
429 | |
430 | ' | |
431 | ||
432 | test_expect_success 'merge-recursive d/f conflict' ' | |
433 | ||
744747ef | 434 | rm -fr [abcd] && |
885b9810 JH |
435 | git reset --hard && |
436 | git checkout -f "$c6" && | |
437 | ||
67b6afe1 | 438 | test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1" |
885b9810 JH |
439 | ' |
440 | ||
441 | test_expect_success 'merge-recursive d/f conflict result' ' | |
442 | ||
443 | git ls-files -s >actual && | |
444 | ( | |
b6c32f63 ES |
445 | echo "100644 $o1 0 a" && |
446 | echo "100644 $o0 0 b" && | |
447 | echo "100644 $o0 0 c" && | |
448 | echo "100644 $o6 2 d" && | |
449 | echo "100644 $o0 1 d/e" && | |
885b9810 JH |
450 | echo "100644 $o1 3 d/e" |
451 | ) >expected && | |
3af82863 | 452 | test_cmp expected actual |
885b9810 JH |
453 | |
454 | ' | |
455 | ||
83e3ad3b JT |
456 | test_expect_success SYMLINKS 'dir in working tree with symlink ancestor does not produce d/f conflict' ' |
457 | git init sym && | |
458 | ( | |
459 | cd sym && | |
460 | ln -s . foo && | |
461 | mkdir bar && | |
462 | >bar/file && | |
463 | git add foo bar/file && | |
464 | git commit -m "foo symlink" && | |
465 | ||
466 | git checkout -b branch1 && | |
467 | git commit --allow-empty -m "empty commit" && | |
468 | ||
469 | git checkout master && | |
470 | git rm foo && | |
471 | mkdir foo && | |
472 | >foo/bar && | |
473 | git add foo/bar && | |
474 | git commit -m "replace foo symlink with real foo dir and foo/bar file" && | |
475 | ||
476 | git checkout branch1 && | |
477 | ||
478 | git cherry-pick master && | |
479 | test_path_is_dir foo && | |
480 | test_path_is_file foo/bar | |
481 | ) | |
482 | ' | |
483 | ||
885b9810 JH |
484 | test_expect_success 'reset and 3-way merge' ' |
485 | ||
486 | git reset --hard "$c2" && | |
487 | git read-tree -m "$c0" "$c2" "$c1" | |
488 | ||
489 | ' | |
490 | ||
491 | test_expect_success 'reset and bind merge' ' | |
492 | ||
493 | git reset --hard master && | |
494 | git read-tree --prefix=M/ master && | |
495 | git ls-files -s >actual && | |
496 | ( | |
b6c32f63 ES |
497 | echo "100644 $o1 0 M/a" && |
498 | echo "100644 $o0 0 M/b" && | |
499 | echo "100644 $o0 0 M/c" && | |
500 | echo "100644 $o1 0 M/d/e" && | |
501 | echo "100644 $o1 0 a" && | |
502 | echo "100644 $o0 0 b" && | |
503 | echo "100644 $o0 0 c" && | |
885b9810 JH |
504 | echo "100644 $o1 0 d/e" |
505 | ) >expected && | |
3af82863 | 506 | test_cmp expected actual && |
885b9810 JH |
507 | |
508 | git read-tree --prefix=a1/ master && | |
509 | git ls-files -s >actual && | |
510 | ( | |
b6c32f63 ES |
511 | echo "100644 $o1 0 M/a" && |
512 | echo "100644 $o0 0 M/b" && | |
513 | echo "100644 $o0 0 M/c" && | |
514 | echo "100644 $o1 0 M/d/e" && | |
515 | echo "100644 $o1 0 a" && | |
516 | echo "100644 $o1 0 a1/a" && | |
517 | echo "100644 $o0 0 a1/b" && | |
518 | echo "100644 $o0 0 a1/c" && | |
519 | echo "100644 $o1 0 a1/d/e" && | |
520 | echo "100644 $o0 0 b" && | |
521 | echo "100644 $o0 0 c" && | |
885b9810 JH |
522 | echo "100644 $o1 0 d/e" |
523 | ) >expected && | |
a48fcd83 | 524 | test_cmp expected actual && |
885b9810 JH |
525 | |
526 | git read-tree --prefix=z/ master && | |
527 | git ls-files -s >actual && | |
528 | ( | |
b6c32f63 ES |
529 | echo "100644 $o1 0 M/a" && |
530 | echo "100644 $o0 0 M/b" && | |
531 | echo "100644 $o0 0 M/c" && | |
532 | echo "100644 $o1 0 M/d/e" && | |
533 | echo "100644 $o1 0 a" && | |
534 | echo "100644 $o1 0 a1/a" && | |
535 | echo "100644 $o0 0 a1/b" && | |
536 | echo "100644 $o0 0 a1/c" && | |
537 | echo "100644 $o1 0 a1/d/e" && | |
538 | echo "100644 $o0 0 b" && | |
539 | echo "100644 $o0 0 c" && | |
540 | echo "100644 $o1 0 d/e" && | |
541 | echo "100644 $o1 0 z/a" && | |
542 | echo "100644 $o0 0 z/b" && | |
543 | echo "100644 $o0 0 z/c" && | |
885b9810 JH |
544 | echo "100644 $o1 0 z/d/e" |
545 | ) >expected && | |
3af82863 | 546 | test_cmp expected actual |
885b9810 JH |
547 | |
548 | ' | |
549 | ||
6e2068ae | 550 | test_expect_success 'merge-recursive w/ empty work tree - ours has rename' ' |
29d9af58 BK |
551 | ( |
552 | GIT_WORK_TREE="$PWD/ours-has-rename-work" && | |
553 | export GIT_WORK_TREE && | |
554 | GIT_INDEX_FILE="$PWD/ours-has-rename-index" && | |
555 | export GIT_INDEX_FILE && | |
556 | mkdir "$GIT_WORK_TREE" && | |
40dc533f SG |
557 | git read-tree -i -m $c7 2>actual-err && |
558 | test_must_be_empty actual-err && | |
559 | git update-index --ignore-missing --refresh 2>actual-err && | |
560 | test_must_be_empty actual-err && | |
561 | git merge-recursive $c0 -- $c7 $c3 2>actual-err && | |
562 | test_must_be_empty actual-err && | |
563 | git ls-files -s >actual-files 2>actual-err && | |
564 | test_must_be_empty actual-err | |
565 | ) && | |
29d9af58 BK |
566 | cat >expected-files <<-EOF && |
567 | 100644 $o3 0 b/c | |
568 | 100644 $o0 0 c | |
569 | 100644 $o0 0 d/e | |
570 | 100644 $o0 0 e | |
571 | EOF | |
40dc533f | 572 | test_cmp expected-files actual-files |
29d9af58 BK |
573 | ' |
574 | ||
575 | test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' ' | |
576 | ( | |
577 | GIT_WORK_TREE="$PWD/theirs-has-rename-work" && | |
578 | export GIT_WORK_TREE && | |
579 | GIT_INDEX_FILE="$PWD/theirs-has-rename-index" && | |
580 | export GIT_INDEX_FILE && | |
581 | mkdir "$GIT_WORK_TREE" && | |
40dc533f SG |
582 | git read-tree -i -m $c3 2>actual-err && |
583 | test_must_be_empty actual-err && | |
584 | git update-index --ignore-missing --refresh 2>actual-err && | |
585 | test_must_be_empty actual-err && | |
586 | git merge-recursive $c0 -- $c3 $c7 2>actual-err && | |
587 | test_must_be_empty actual-err && | |
588 | git ls-files -s >actual-files 2>actual-err && | |
589 | test_must_be_empty actual-err | |
590 | ) && | |
29d9af58 BK |
591 | cat >expected-files <<-EOF && |
592 | 100644 $o3 0 b/c | |
593 | 100644 $o0 0 c | |
594 | 100644 $o0 0 d/e | |
595 | 100644 $o0 0 e | |
596 | EOF | |
40dc533f | 597 | test_cmp expected-files actual-files |
29d9af58 BK |
598 | ' |
599 | ||
41f13af5 AR |
600 | test_expect_success 'merge removes empty directories' ' |
601 | ||
602 | git reset --hard master && | |
603 | git checkout -b rm && | |
604 | git rm d/e && | |
605 | git commit -mremoved-d/e && | |
606 | git checkout master && | |
607 | git merge -s recursive rm && | |
245b9ba0 | 608 | test_path_is_missing d |
41f13af5 AR |
609 | ' |
610 | ||
5423d2e7 | 611 | test_expect_success 'merge-recursive simple w/submodule' ' |
7d82b06d JS |
612 | |
613 | git checkout submod && | |
614 | git merge remove | |
615 | ' | |
616 | ||
5423d2e7 | 617 | test_expect_success 'merge-recursive simple w/submodule result' ' |
7d82b06d JS |
618 | |
619 | git ls-files -s >actual && | |
620 | ( | |
b6c32f63 ES |
621 | echo "100644 $o5 0 a" && |
622 | echo "100644 $o0 0 c" && | |
7d82b06d JS |
623 | echo "160000 $c1 0 d" |
624 | ) >expected && | |
625 | test_cmp expected actual | |
626 | ' | |
627 | ||
d5af5105 SK |
628 | test_expect_success 'merge-recursive copy vs. rename' ' |
629 | git checkout -f copy && | |
630 | git merge rename && | |
631 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && | |
632 | ( | |
b6c32f63 ES |
633 | echo "100644 blob $o0 b" && |
634 | echo "100644 blob $o0 c" && | |
635 | echo "100644 blob $o0 d/e" && | |
636 | echo "100644 blob $o0 e" && | |
637 | echo "100644 $o0 0 b" && | |
638 | echo "100644 $o0 0 c" && | |
639 | echo "100644 $o0 0 d/e" && | |
d5af5105 SK |
640 | echo "100644 $o0 0 e" |
641 | ) >expected && | |
642 | test_cmp expected actual | |
643 | ' | |
644 | ||
f06481f1 | 645 | test_expect_merge_algorithm failure success 'merge-recursive rename vs. rename/symlink' ' |
bba56042 JS |
646 | |
647 | git checkout -f rename && | |
648 | git merge rename-ln && | |
b6c32f63 | 649 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
bba56042 | 650 | ( |
b6c32f63 ES |
651 | echo "120000 blob $oln a" && |
652 | echo "100644 blob $o0 b" && | |
653 | echo "100644 blob $o0 c" && | |
654 | echo "100644 blob $o0 d/e" && | |
655 | echo "100644 blob $o0 e" && | |
656 | echo "120000 $oln 0 a" && | |
657 | echo "100644 $o0 0 b" && | |
658 | echo "100644 $o0 0 c" && | |
659 | echo "100644 $o0 0 d/e" && | |
bba56042 JS |
660 | echo "100644 $o0 0 e" |
661 | ) >expected && | |
662 | test_cmp expected actual | |
663 | ' | |
8a1c0d32 | 664 | |
6f50833e JK |
665 | test_expect_success 'merging with triple rename across D/F conflict' ' |
666 | git reset --hard HEAD && | |
538228ed | 667 | git checkout -b topic && |
6f50833e JK |
668 | git rm -rf . && |
669 | ||
670 | echo "just a file" >sub1 && | |
671 | mkdir -p sub2 && | |
672 | echo content1 >sub2/file1 && | |
673 | echo content2 >sub2/file2 && | |
674 | echo content3 >sub2/file3 && | |
675 | mkdir simple && | |
676 | echo base >simple/bar && | |
677 | git add -A && | |
678 | test_tick && | |
679 | git commit -m base && | |
680 | ||
681 | git checkout -b other && | |
682 | echo more >>simple/bar && | |
683 | test_tick && | |
684 | git commit -a -m changesimplefile && | |
685 | ||
538228ed | 686 | git checkout topic && |
6f50833e JK |
687 | git rm sub1 && |
688 | git mv sub2 sub1 && | |
689 | test_tick && | |
690 | git commit -m changefiletodir && | |
691 | ||
692 | test_tick && | |
693 | git merge other | |
694 | ' | |
8a1c0d32 | 695 | |
a2571653 RS |
696 | test_expect_success 'merge-recursive remembers the names of all base trees' ' |
697 | git reset --hard HEAD && | |
698 | ||
9822175d EN |
699 | # make the index match $c1 so that merge-recursive below does not |
700 | # fail early | |
701 | git diff --binary HEAD $c1 -- | git apply --cached && | |
702 | ||
a2571653 RS |
703 | # more trees than static slots used by oid_to_hex() |
704 | for commit in $c0 $c2 $c4 $c5 $c6 $c7 | |
705 | do | |
706 | git rev-parse "$commit^{tree}" | |
707 | done >trees && | |
708 | ||
9822175d | 709 | # ignore the return code; it only fails because the input is weird... |
a2571653 RS |
710 | test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out && |
711 | ||
9822175d EN |
712 | # ...but make sure it fails in the expected way |
713 | test_i18ngrep CONFLICT.*rename/rename out && | |
714 | ||
a2571653 RS |
715 | # merge-recursive prints in reverse order, but we do not care |
716 | sort <trees >expect && | |
717 | sed -n "s/^virtual //p" out | sort >actual && | |
718 | test_cmp expect actual | |
719 | ' | |
720 | ||
f309e8e7 JH |
721 | test_expect_success 'merge-recursive internal merge resolves to the sameness' ' |
722 | git reset --hard HEAD && | |
723 | ||
724 | # We are going to create a history leading to two criss-cross | |
725 | # branches A and B. The common ancestor at the bottom, O0, | |
726 | # has two child commits O1 and O2, both of which will be merge | |
727 | # base between A and B, like so: | |
728 | # | |
729 | # O1---A | |
730 | # / \ / | |
731 | # O0 . | |
732 | # \ / \ | |
733 | # O2---B | |
734 | # | |
735 | # The recently added "check to see if the index is different from | |
736 | # the tree into which something else is getting merged" check must | |
737 | # NOT kick in when an inner merge between O1 and O2 is made. Both | |
738 | # O1 and O2 happen to have the same tree as O0 in this test to | |
739 | # trigger the bug---whether the inner merge is made by merging O2 | |
740 | # into O1 or O1 into O2, their common ancestor O0 and the branch | |
741 | # being merged have the same tree. We should not trigger the "is | |
742 | # the index dirty?" check in this case. | |
743 | ||
744 | echo "zero" >file && | |
745 | git add file && | |
746 | test_tick && | |
747 | git commit -m "O0" && | |
748 | O0=$(git rev-parse HEAD) && | |
749 | ||
750 | test_tick && | |
751 | git commit --allow-empty -m "O1" && | |
752 | O1=$(git rev-parse HEAD) && | |
753 | ||
754 | git reset --hard $O0 && | |
755 | test_tick && | |
756 | git commit --allow-empty -m "O2" && | |
757 | O2=$(git rev-parse HEAD) && | |
758 | ||
759 | test_tick && | |
760 | git merge -s ours $O1 && | |
761 | B=$(git rev-parse HEAD) && | |
762 | ||
763 | git reset --hard $O1 && | |
764 | test_tick && | |
765 | git merge -s ours $O2 && | |
766 | A=$(git rev-parse HEAD) && | |
767 | ||
768 | git merge $B | |
769 | ' | |
770 | ||
885b9810 | 771 | test_done |