3 test_description="recursive merge corner cases w/ renames but not criss-crosses"
4 # t6036 has corner cases that involve both criss-cross merges and renames
8 test_expect_success 'setup rename/delete + untracked file' '
9 echo "A pretty inscription" >ring &&
12 git commit -m beginning &&
15 git checkout -b rename-the-ring &&
16 git mv ring one-ring-to-rule-them-all &&
18 git commit -m fullname &&
20 git checkout people &&
25 git commit -m track-people-instead-of-objects &&
26 echo "Myyy PRECIOUSSS" >ring
29 test_expect_success "Does git preserve Gollum's precious artifact?" '
30 test_must_fail git merge -s recursive rename-the-ring &&
32 # Make sure git did not delete an untracked file
36 # Testcase setup for rename/modify/add-source:
37 # Commit A: new file: a
38 # Commit B: modify a slightly
39 # Commit C: rename a->b, add completely different a
41 # We should be able to merge B & C cleanly
43 test_expect_success 'setup rename/modify/add-source conflict' '
49 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
54 git checkout -b B A &&
59 git checkout -b C A &&
61 echo something completely different >a &&
66 test_expect_failure 'rename/modify/add-source conflict resolvable' '
69 git merge -s recursive C^0 &&
71 test $(git rev-parse B:a) = $(git rev-parse b) &&
72 test $(git rev-parse C:a) = $(git rev-parse a)
75 test_expect_success 'setup resolvable conflict missed if rename missed' '
81 printf "1\n2\n3\n4\n5\n" >a &&
87 git checkout -b B A &&
89 echo "Completely different content" >a &&
93 git checkout -b C A &&
99 test_expect_failure 'conflict caused if rename not detected' '
100 git checkout -q C^0 &&
101 git merge -s recursive B^0 &&
103 test 3 -eq $(git ls-files -s | wc -l) &&
104 test 0 -eq $(git ls-files -u | wc -l) &&
105 test 0 -eq $(git ls-files -o | wc -l) &&
107 test_line_count = 6 c &&
108 test $(git rev-parse HEAD:a) = $(git rev-parse B:a) &&
109 test $(git rev-parse HEAD:b) = $(git rev-parse A:b)
112 test_expect_success 'setup conflict resolved wrong if rename missed' '
116 git checkout -b D A &&
120 echo "Completely different content" >a &&
124 git checkout -b E A &&
126 echo "Completely different content" >>a &&
131 test_expect_failure 'missed conflict if rename not detected' '
132 git checkout -q E^0 &&
133 test_must_fail git merge -s recursive D^0
136 # Tests for undetected rename/add-source causing a file to erroneously be
137 # deleted (and for mishandled rename/rename(1to1) causing the same issue).
139 # This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
140 # same file is renamed on both sides to the same thing; it should trigger
141 # the 1to2 logic, which it would do if the add-source didn't cause issues
142 # for git's rename detection):
143 # Commit A: new file: a
144 # Commit B: rename a->b
145 # Commit C: rename a->b, add unrelated a
147 test_expect_success 'setup undetected rename/add-source causes data loss' '
153 printf "1\n2\n3\n4\n5\n" >a &&
158 git checkout -b B A &&
162 git checkout -b C A &&
169 test_expect_failure 'detect rename/add-source and preserve all data' '
172 git merge -s recursive C^0 &&
174 test 2 -eq $(git ls-files -s | wc -l) &&
175 test 2 -eq $(git ls-files -u | wc -l) &&
176 test 0 -eq $(git ls-files -o | wc -l) &&
181 test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
182 test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
185 test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
188 git merge -s recursive B^0 &&
190 test 2 -eq $(git ls-files -s | wc -l) &&
191 test 2 -eq $(git ls-files -u | wc -l) &&
192 test 0 -eq $(git ls-files -o | wc -l) &&
197 test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
198 test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
201 test_expect_success 'setup content merge + rename/directory conflict' '
207 printf "1\n2\n3\n4\n5\n6\n" >file &&
210 git commit -m base &&
213 git checkout -b right &&
216 echo junk >newfile/realfile &&
217 git add file newfile/realfile &&
219 git commit -m right &&
221 git checkout -b left-conflict base &&
224 git mv file newfile &&
226 git commit -m left &&
228 git checkout -b left-clean base &&
230 cat file >>newfile &&
237 test_expect_success 'rename/directory conflict + clean content merge' '
242 git checkout left-clean^0 &&
244 test_must_fail git merge -s recursive right^0 &&
246 test 2 -eq $(git ls-files -s | wc -l) &&
247 test 1 -eq $(git ls-files -u | wc -l) &&
248 test 1 -eq $(git ls-files -o | wc -l) &&
251 git cat-file -p base:file >>expect &&
253 test_cmp expect newfile~HEAD &&
255 test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
257 test -f newfile/realfile &&
261 test_expect_success 'rename/directory conflict + content merge conflict' '
266 git checkout left-conflict^0 &&
268 test_must_fail git merge -s recursive right^0 &&
270 test 4 -eq $(git ls-files -s | wc -l) &&
271 test 3 -eq $(git ls-files -u | wc -l) &&
272 test 1 -eq $(git ls-files -o | wc -l) &&
274 git cat-file -p left-conflict:newfile >left &&
275 git cat-file -p base:file >base &&
276 git cat-file -p right:file >right &&
277 test_must_fail git merge-file \
282 test_cmp left newfile~HEAD &&
284 test $(git rev-parse :1:newfile) = $(git rev-parse base:file) &&
285 test $(git rev-parse :2:newfile) = $(git rev-parse left-conflict:newfile) &&
286 test $(git rev-parse :3:newfile) = $(git rev-parse right:file) &&
288 test -f newfile/realfile &&
292 test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
300 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
303 git commit -m base &&
306 git checkout -b right &&
310 git commit -m right &&
312 git checkout -b left base &&
314 cat sub/file >>newfile &&
322 test_expect_success 'disappearing dir in rename/directory conflict handled' '
326 git checkout left^0 &&
328 git merge -s recursive right^0 &&
330 test 1 -eq $(git ls-files -s | wc -l) &&
331 test 0 -eq $(git ls-files -u | wc -l) &&
332 test 0 -eq $(git ls-files -o | wc -l) &&
335 git cat-file -p base:sub/file >>expect &&
337 test_cmp expect sub &&
342 # Test for all kinds of things that can go wrong with rename/rename (2to1):
343 # Commit A: new files: a & b
344 # Commit B: rename a->c, modify b
345 # Commit C: rename b->c, modify a
347 # Merging of B & C should NOT be clean. Questions:
348 # * Both a & b should be removed by the merge; are they?
349 # * The two c's should contain modifications to a & b; do they?
350 # * The index should contain two files, both for c; does it?
351 # * The working copy should have two files, both of form c~<unique>; does it?
352 # * Nothing else should be present. Is anything?
354 test_expect_success 'setup rename/rename (2to1) + modify/modify' '
360 printf "1\n2\n3\n4\n5\n" >a &&
361 printf "5\n4\n3\n2\n1\n" >b &&
366 git checkout -b B A &&
372 git checkout -b C A &&
379 test_expect_success 'handle rename/rename (2to1) conflict correctly' '
382 test_must_fail git merge -s recursive C^0 >out &&
383 grep "CONFLICT (rename/rename)" out &&
385 test 2 -eq $(git ls-files -s | wc -l) &&
386 test 2 -eq $(git ls-files -u | wc -l) &&
387 test 2 -eq $(git ls-files -u c | wc -l) &&
388 test 3 -eq $(git ls-files -o | wc -l) &&
395 test $(git hash-object c~HEAD) = $(git rev-parse C:a) &&
396 test $(git hash-object c~C^0) = $(git rev-parse B:b)
399 # Testcase setup for simple rename/rename (1to2) conflict:
400 # Commit A: new file: a
401 # Commit B: rename a->b
402 # Commit C: rename a->c
403 test_expect_success 'setup simple rename/rename (1to2) conflict' '
415 git checkout -b B A &&
420 git checkout -b C A &&
426 test_expect_success 'merge has correct working tree contents' '
429 test_must_fail git merge -s recursive B^0 &&
431 test 3 -eq $(git ls-files -s | wc -l) &&
432 test 3 -eq $(git ls-files -u | wc -l) &&
433 test 0 -eq $(git ls-files -o | wc -l) &&
435 test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
436 test $(git rev-parse :3:b) = $(git rev-parse A:a) &&
437 test $(git rev-parse :2:c) = $(git rev-parse A:a) &&
440 test $(git hash-object b) = $(git rev-parse A:a) &&
441 test $(git hash-object c) = $(git rev-parse A:a)
444 # Testcase setup for rename/rename(1to2)/add-source conflict:
445 # Commit A: new file: a
446 # Commit B: rename a->b
447 # Commit C: rename a->c, add completely different a
449 # Merging of B & C should NOT be clean; there's a rename/rename conflict
451 test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
457 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
462 git checkout -b B A &&
466 git checkout -b C A &&
468 echo something completely different >a &&
473 test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
476 test_must_fail git merge -s recursive C^0 &&
478 test 4 -eq $(git ls-files -s | wc -l) &&
479 test 0 -eq $(git ls-files -o | wc -l) &&
481 test $(git rev-parse 3:a) = $(git rev-parse C:a) &&
482 test $(git rev-parse 1:a) = $(git rev-parse A:a) &&
483 test $(git rev-parse 2:b) = $(git rev-parse B:b) &&
484 test $(git rev-parse 3:c) = $(git rev-parse C:c) &&
491 test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
500 git commit -m base &&
503 git checkout -b B A &&
508 git checkout -b C A &&
510 echo important-info >a &&
516 test_expect_failure 'rename/rename/add-source still tracks new a file' '
518 git merge -s recursive B^0 &&
520 test 2 -eq $(git ls-files -s | wc -l) &&
521 test 0 -eq $(git ls-files -o | wc -l) &&
523 test $(git rev-parse HEAD:a) = $(git rev-parse C:a) &&
524 test $(git rev-parse HEAD:b) = $(git rev-parse A:a)
527 test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
536 git commit -m base &&
539 git checkout -b B A &&
541 echo precious-data >c &&
546 git checkout -b C A &&
548 echo important-info >b &&
554 test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
556 test_must_fail git merge -s recursive B^0 &&
558 test 5 -eq $(git ls-files -s | wc -l) &&
559 test 2 -eq $(git ls-files -u b | wc -l) &&
560 test 2 -eq $(git ls-files -u c | wc -l) &&
561 test 4 -eq $(git ls-files -o | wc -l) &&
563 test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
564 test $(git rev-parse :2:b) = $(git rev-parse C:b) &&
565 test $(git rev-parse :3:b) = $(git rev-parse B:b) &&
566 test $(git rev-parse :2:c) = $(git rev-parse C:c) &&
567 test $(git rev-parse :3:c) = $(git rev-parse B:c) &&
569 test $(git hash-object c~HEAD) = $(git rev-parse C:c) &&
570 test $(git hash-object c~B\^0) = $(git rev-parse B:c) &&
571 test $(git hash-object b~HEAD) = $(git rev-parse C:b) &&
572 test $(git hash-object b~B\^0) = $(git rev-parse B:b) &&