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 test_create_repo rename-delete-untracked &&
11 cd rename-delete-untracked &&
13 echo "A pretty inscription" >ring &&
16 git commit -m beginning &&
19 git checkout -b rename-the-ring &&
20 git mv ring one-ring-to-rule-them-all &&
22 git commit -m fullname &&
24 git checkout people &&
29 git commit -m track-people-instead-of-objects &&
30 echo "Myyy PRECIOUSSS" >ring
34 test_expect_success "Does git preserve Gollum's precious artifact?" '
36 cd rename-delete-untracked &&
38 test_must_fail git merge -s recursive rename-the-ring &&
40 # Make sure git did not delete an untracked file
41 test_path_is_file ring
45 # Testcase setup for rename/modify/add-source:
46 # Commit A: new file: a
47 # Commit B: modify a slightly
48 # Commit C: rename a->b, add completely different a
50 # We should be able to merge B & C cleanly
52 test_expect_success 'setup rename/modify/add-source conflict' '
53 test_create_repo rename-modify-add-source &&
55 cd rename-modify-add-source &&
57 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
62 git checkout -b B A &&
67 git checkout -b C A &&
69 echo something completely different >a &&
75 test_expect_failure 'rename/modify/add-source conflict resolvable' '
77 cd rename-modify-add-source &&
81 git merge -s recursive C^0 &&
83 git rev-parse >expect \
85 git rev-parse >actual \
87 test_cmp expect actual
91 test_expect_success 'setup resolvable conflict missed if rename missed' '
92 test_create_repo break-detection-1 &&
94 cd break-detection-1 &&
96 printf "1\n2\n3\n4\n5\n" >a &&
102 git checkout -b B A &&
104 echo "Completely different content" >a &&
108 git checkout -b C A &&
115 test_expect_failure 'conflict caused if rename not detected' '
117 cd break-detection-1 &&
119 git checkout -q C^0 &&
120 git merge -s recursive B^0 &&
122 git ls-files -s >out &&
123 test_line_count = 3 out &&
124 git ls-files -u >out &&
125 test_line_count = 0 out &&
126 git ls-files -o >out &&
127 test_line_count = 1 out &&
129 test_line_count = 6 c &&
130 git rev-parse >expect \
132 git rev-parse >actual \
134 test_cmp expect actual
138 test_expect_success 'setup conflict resolved wrong if rename missed' '
139 test_create_repo break-detection-2 &&
141 cd break-detection-2 &&
143 printf "1\n2\n3\n4\n5\n" >a &&
149 git checkout -b D A &&
153 echo "Completely different content" >a &&
157 git checkout -b E A &&
159 echo "Completely different content" >>a &&
165 test_expect_failure 'missed conflict if rename not detected' '
167 cd break-detection-2 &&
169 git checkout -q E^0 &&
170 test_must_fail git merge -s recursive D^0
174 # Tests for undetected rename/add-source causing a file to erroneously be
175 # deleted (and for mishandled rename/rename(1to1) causing the same issue).
177 # This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
178 # same file is renamed on both sides to the same thing; it should trigger
179 # the 1to2 logic, which it would do if the add-source didn't cause issues
180 # for git's rename detection):
181 # Commit A: new file: a
182 # Commit B: rename a->b
183 # Commit C: rename a->b, add unrelated a
185 test_expect_success 'setup undetected rename/add-source causes data loss' '
186 test_create_repo break-detection-3 &&
188 cd break-detection-3 &&
190 printf "1\n2\n3\n4\n5\n" >a &&
195 git checkout -b B A &&
199 git checkout -b C A &&
207 test_expect_failure 'detect rename/add-source and preserve all data' '
209 cd break-detection-3 &&
213 git merge -s recursive C^0 &&
215 git ls-files -s >out &&
216 test_line_count = 2 out &&
217 git ls-files -u >out &&
218 test_line_count = 2 out &&
219 git ls-files -o >out &&
220 test_line_count = 1 out &&
222 test_path_is_file a &&
223 test_path_is_file b &&
225 git rev-parse >expect \
227 git rev-parse >actual \
229 test_cmp expect actual
233 test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
235 cd break-detection-3 &&
239 git merge -s recursive B^0 &&
241 git ls-files -s >out &&
242 test_line_count = 2 out &&
243 git ls-files -u >out &&
244 test_line_count = 2 out &&
245 git ls-files -o >out &&
246 test_line_count = 1 out &&
248 test_path_is_file a &&
249 test_path_is_file b &&
251 git rev-parse >expect \
253 git rev-parse >actual \
255 test_cmp expect actual
259 test_expect_success 'setup content merge + rename/directory conflict' '
260 test_create_repo rename-directory-1 &&
262 cd rename-directory-1 &&
264 printf "1\n2\n3\n4\n5\n6\n" >file &&
267 git commit -m base &&
270 git checkout -b right &&
273 echo junk >newfile/realfile &&
274 git add file newfile/realfile &&
276 git commit -m right &&
278 git checkout -b left-conflict base &&
281 git mv file newfile &&
283 git commit -m left &&
285 git checkout -b left-clean base &&
287 cat file >>newfile &&
295 test_expect_success 'rename/directory conflict + clean content merge' '
297 cd rename-directory-1 &&
299 git checkout left-clean^0 &&
301 test_must_fail git merge -s recursive right^0 &&
303 git ls-files -s >out &&
304 test_line_count = 2 out &&
305 git ls-files -u >out &&
306 test_line_count = 1 out &&
307 git ls-files -o >out &&
308 test_line_count = 2 out &&
311 git cat-file -p base:file >>expect &&
313 test_cmp expect newfile~HEAD &&
315 test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
317 test_path_is_file newfile/realfile &&
318 test_path_is_file newfile~HEAD
322 test_expect_success 'rename/directory conflict + content merge conflict' '
324 cd rename-directory-1 &&
330 git checkout left-conflict^0 &&
332 test_must_fail git merge -s recursive right^0 &&
334 git ls-files -s >out &&
335 test_line_count = 4 out &&
336 git ls-files -u >out &&
337 test_line_count = 3 out &&
338 git ls-files -o >out &&
339 test_line_count = 2 out &&
341 git cat-file -p left-conflict:newfile >left &&
342 git cat-file -p base:file >base &&
343 git cat-file -p right:file >right &&
344 test_must_fail git merge-file \
349 test_cmp left newfile~HEAD &&
351 git rev-parse >expect \
352 base:file left-conflict:newfile right:file &&
353 git rev-parse >actual \
354 :1:newfile :2:newfile :3:newfile &&
355 test_cmp expect actual &&
357 test_path_is_file newfile/realfile &&
358 test_path_is_file newfile~HEAD
362 test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
363 test_create_repo rename-directory-2 &&
365 cd rename-directory-2 &&
368 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
371 git commit -m base &&
374 git checkout -b right &&
378 git commit -m right &&
380 git checkout -b left base &&
382 cat sub/file >>newfile &&
391 test_expect_success 'disappearing dir in rename/directory conflict handled' '
393 cd rename-directory-2 &&
395 git checkout left^0 &&
397 git merge -s recursive right^0 &&
399 git ls-files -s >out &&
400 test_line_count = 1 out &&
401 git ls-files -u >out &&
402 test_line_count = 0 out &&
403 git ls-files -o >out &&
404 test_line_count = 1 out &&
407 git cat-file -p base:sub/file >>expect &&
409 test_cmp expect sub &&
411 test_path_is_file sub
415 # Test for all kinds of things that can go wrong with rename/rename (2to1):
416 # Commit A: new files: a & b
417 # Commit B: rename a->c, modify b
418 # Commit C: rename b->c, modify a
420 # Merging of B & C should NOT be clean. Questions:
421 # * Both a & b should be removed by the merge; are they?
422 # * The two c's should contain modifications to a & b; do they?
423 # * The index should contain two files, both for c; does it?
424 # * The working copy should have two files, both of form c~<unique>; does it?
425 # * Nothing else should be present. Is anything?
427 test_expect_success 'setup rename/rename (2to1) + modify/modify' '
428 test_create_repo rename-rename-2to1 &&
430 cd rename-rename-2to1 &&
432 printf "1\n2\n3\n4\n5\n" >a &&
433 printf "5\n4\n3\n2\n1\n" >b &&
438 git checkout -b B A &&
444 git checkout -b C A &&
452 test_expect_success 'handle rename/rename (2to1) conflict correctly' '
454 cd rename-rename-2to1 &&
458 test_must_fail git merge -s recursive C^0 >out &&
459 test_i18ngrep "CONFLICT (rename/rename)" out &&
461 git ls-files -s >out &&
462 test_line_count = 2 out &&
463 git ls-files -u >out &&
464 test_line_count = 2 out &&
465 git ls-files -u c >out &&
466 test_line_count = 2 out &&
467 git ls-files -o >out &&
468 test_line_count = 3 out &&
470 test_path_is_missing a &&
471 test_path_is_missing b &&
472 test_path_is_file c~HEAD &&
473 test_path_is_file c~C^0 &&
475 git rev-parse >expect \
477 git hash-object >actual \
479 test_cmp expect actual
483 # Testcase setup for simple rename/rename (1to2) conflict:
484 # Commit A: new file: a
485 # Commit B: rename a->b
486 # Commit C: rename a->c
487 test_expect_success 'setup simple rename/rename (1to2) conflict' '
488 test_create_repo rename-rename-1to2 &&
490 cd rename-rename-1to2 &&
498 git checkout -b B A &&
503 git checkout -b C A &&
510 test_expect_success 'merge has correct working tree contents' '
512 cd rename-rename-1to2 &&
516 test_must_fail git merge -s recursive B^0 &&
518 git ls-files -s >out &&
519 test_line_count = 3 out &&
520 git ls-files -u >out &&
521 test_line_count = 3 out &&
522 git ls-files -o >out &&
523 test_line_count = 1 out &&
525 test_path_is_missing a &&
526 git rev-parse >expect \
529 git rev-parse >actual \
531 git hash-object >>actual \
533 test_cmp expect actual
537 # Testcase setup for rename/rename(1to2)/add-source conflict:
538 # Commit A: new file: a
539 # Commit B: rename a->b
540 # Commit C: rename a->c, add completely different a
542 # Merging of B & C should NOT be clean; there's a rename/rename conflict
544 test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
545 test_create_repo rename-rename-1to2-add-source-1 &&
547 cd rename-rename-1to2-add-source-1 &&
549 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
554 git checkout -b B A &&
558 git checkout -b C A &&
560 echo something completely different >a &&
566 test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
568 cd rename-rename-1to2-add-source-1 &&
572 test_must_fail git merge -s recursive C^0 &&
574 git ls-files -s >out &&
575 test_line_count = 4 out &&
576 git ls-files -o >out &&
577 test_line_count = 1 out &&
579 git rev-parse >expect \
581 git rev-parse >actual \
582 :3:a :1:a :2:b :3:c &&
583 test_cmp expect actual &&
585 test_path_is_file a &&
586 test_path_is_file b &&
591 test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
592 test_create_repo rename-rename-1to2-add-source-2 &&
594 cd rename-rename-1to2-add-source-2 &&
599 git commit -m base &&
602 git checkout -b B A &&
607 git checkout -b C A &&
609 echo important-info >a &&
616 test_expect_failure 'rename/rename/add-source still tracks new a file' '
618 cd rename-rename-1to2-add-source-2 &&
621 git merge -s recursive B^0 &&
623 git ls-files -s >out &&
624 test_line_count = 2 out &&
625 git ls-files -o >out &&
626 test_line_count = 1 out &&
628 git rev-parse >expect \
630 git rev-parse >actual \
632 test_cmp expect actual
636 test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
637 test_create_repo rename-rename-1to2-add-dest &&
639 cd rename-rename-1to2-add-dest &&
644 git commit -m base &&
647 git checkout -b B A &&
649 echo precious-data >c &&
654 git checkout -b C A &&
656 echo important-info >b &&
663 test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
665 cd rename-rename-1to2-add-dest &&
668 test_must_fail git merge -s recursive B^0 &&
670 git ls-files -s >out &&
671 test_line_count = 5 out &&
672 git ls-files -u b >out &&
673 test_line_count = 2 out &&
674 git ls-files -u c >out &&
675 test_line_count = 2 out &&
676 git ls-files -o >out &&
677 test_line_count = 5 out &&
679 git rev-parse >expect \
680 A:a C:b B:b C:c B:c &&
681 git rev-parse >actual \
682 :1:a :2:b :3:b :2:c :3:c &&
683 test_cmp expect actual &&
685 git rev-parse >expect \
687 git hash-object >actual \
688 c~HEAD c~B\^0 b~HEAD b~B\^0 &&
689 test_cmp expect actual &&
691 test_path_is_missing b &&
692 test_path_is_missing c
696 # Testcase rad, rename/add/delete
698 # Commit A: rm foo, add different bar
699 # Commit B: rename foo->bar
700 # Expected: CONFLICT (rename/add/delete), two-way merged bar
702 test_expect_success 'rad-setup: rename/add/delete conflict' '
703 test_create_repo rad &&
706 echo "original file" >foo &&
708 git commit -m "original" &&
716 echo "different file" >bar &&
718 git commit -m "Remove foo, add bar" &&
722 git commit -m "rename foo to bar"
726 test_expect_failure 'rad-check: rename/add/delete conflict' '
731 test_must_fail git merge -s recursive A^0 >out 2>err &&
733 # Not sure whether the output should contain just one
734 # "CONFLICT (rename/add/delete)" line, or if it should break
735 # it into a pair of "CONFLICT (rename/delete)" and
736 # "CONFLICT (rename/add)"; allow for either.
737 test_i18ngrep "CONFLICT (rename.*add)" out &&
738 test_i18ngrep "CONFLICT (rename.*delete)" out &&
739 test_must_be_empty err &&
741 git ls-files -s >file_count &&
742 test_line_count = 2 file_count &&
743 git ls-files -u >file_count &&
744 test_line_count = 2 file_count &&
745 git ls-files -o >file_count &&
746 test_line_count = 2 file_count &&
748 git rev-parse >actual \
750 git rev-parse >expect \
753 test_cmp file_is_missing foo &&
754 # bar should have two-way merged contents of the different
755 # versions of bar; check that content from both sides is
762 # Testcase rrdd, rename/rename(2to1)/delete/delete
764 # Commit A: rename foo->baz, rm bar
765 # Commit B: rename bar->baz, rm foo
766 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
768 test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
769 test_create_repo rrdd &&
784 git commit -m "Rename foo, remove bar" &&
789 git commit -m "Rename bar, remove foo"
793 test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
798 test_must_fail git merge -s recursive B^0 >out 2>err &&
800 # Not sure whether the output should contain just one
801 # "CONFLICT (rename/rename/delete/delete)" line, or if it
802 # should break it into three: "CONFLICT (rename/rename)" and
803 # two "CONFLICT (rename/delete)" lines; allow for either.
804 test_i18ngrep "CONFLICT (rename/rename)" out &&
805 test_i18ngrep "CONFLICT (rename.*delete)" out &&
806 test_must_be_empty err &&
808 git ls-files -s >file_count &&
809 test_line_count = 2 file_count &&
810 git ls-files -u >file_count &&
811 test_line_count = 2 file_count &&
812 git ls-files -o >file_count &&
813 test_line_count = 2 file_count &&
815 git rev-parse >actual \
817 git rev-parse >expect \
820 test_cmp file_is_missing foo &&
821 test_cmp file_is_missing bar &&
822 # baz should have two-way merged contents of the original
823 # contents of foo and bar; check that content from both sides
830 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
831 # Commit O: one, three, five
832 # Commit A: one->two, three->four, five->six
833 # Commit B: one->six, three->two, five->four
834 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
835 # multi-way merged contents found in two, four, six
837 test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
838 test_create_repo mod6 &&
841 test_seq 11 19 >one &&
842 test_seq 31 39 >three &&
843 test_seq 51 59 >five &&
853 test_seq 10 19 >one &&
864 echo forty >>three &&
866 git add one three five &&
875 test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
881 test_must_fail git merge -s recursive B^0 >out 2>err &&
883 test_i18ngrep "CONFLICT (rename/rename)" out &&
884 test_must_be_empty err &&
886 git ls-files -s >file_count &&
887 test_line_count = 6 file_count &&
888 git ls-files -u >file_count &&
889 test_line_count = 6 file_count &&
890 git ls-files -o >file_count &&
891 test_line_count = 3 file_count &&
893 test_seq 10 20 >merged-one &&
894 test_seq 51 60 >merged-five &&
895 # Determine what the merge of three would give us.
896 test_seq 30 40 >three-side-A &&
897 test_seq 31 39 >three-side-B &&
898 echo forty >three-side-B &&
900 test_must_fail git merge-file \
904 three-side-A empty three-side-B &&
905 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
907 # Verify the index is as expected
908 git rev-parse >actual \
912 git hash-object >expect \
913 merged-one merged-three \
914 merged-three merged-five \
915 merged-five merged-one &&
916 test_cmp expect actual &&
918 git cat-file -p :2:two >expect &&
919 git cat-file -p :3:two >other &&
920 test_must_fail git merge-file \
921 -L "HEAD" -L "" -L "B^0" \
922 expect empty other &&
923 test_cmp expect two &&
925 git cat-file -p :2:four >expect &&
926 git cat-file -p :3:four >other &&
927 test_must_fail git merge-file \
928 -L "HEAD" -L "" -L "B^0" \
929 expect empty other &&
930 test_cmp expect four &&
932 git cat-file -p :2:six >expect &&
933 git cat-file -p :3:six >other &&
934 test_must_fail git merge-file \
935 -L "HEAD" -L "" -L "B^0" \
936 expect empty other &&