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 &&
329 git checkout left-conflict^0 &&
331 test_must_fail git merge -s recursive right^0 &&
333 git ls-files -s >out &&
334 test_line_count = 4 out &&
335 git ls-files -u >out &&
336 test_line_count = 3 out &&
337 git ls-files -o >out &&
338 test_line_count = 2 out &&
340 git cat-file -p left-conflict:newfile >left &&
341 git cat-file -p base:file >base &&
342 git cat-file -p right:file >right &&
343 test_must_fail git merge-file \
348 test_cmp left newfile~HEAD &&
350 git rev-parse >expect \
351 base:file left-conflict:newfile right:file &&
352 git rev-parse >actual \
353 :1:newfile :2:newfile :3:newfile &&
354 test_cmp expect actual &&
356 test_path_is_file newfile/realfile &&
357 test_path_is_file newfile~HEAD
361 test_expect_success
'setup content merge + rename/directory conflict w/ disappearing dir' '
362 test_create_repo rename-directory-2 &&
364 cd rename-directory-2 &&
367 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
370 git commit -m base &&
373 git checkout -b right &&
377 git commit -m right &&
379 git checkout -b left base &&
381 cat sub/file >>newfile &&
390 test_expect_success
'disappearing dir in rename/directory conflict handled' '
392 cd rename-directory-2 &&
394 git checkout left^0 &&
396 git merge -s recursive right^0 &&
398 git ls-files -s >out &&
399 test_line_count = 1 out &&
400 git ls-files -u >out &&
401 test_line_count = 0 out &&
402 git ls-files -o >out &&
403 test_line_count = 1 out &&
406 git cat-file -p base:sub/file >>expect &&
408 test_cmp expect sub &&
410 test_path_is_file sub
414 # Test for all kinds of things that can go wrong with rename/rename (2to1):
415 # Commit A: new files: a & b
416 # Commit B: rename a->c, modify b
417 # Commit C: rename b->c, modify a
419 # Merging of B & C should NOT be clean. Questions:
420 # * Both a & b should be removed by the merge; are they?
421 # * The two c's should contain modifications to a & b; do they?
422 # * The index should contain two files, both for c; does it?
423 # * The working copy should have two files, both of form c~<unique>; does it?
424 # * Nothing else should be present. Is anything?
426 test_expect_success
'setup rename/rename (2to1) + modify/modify' '
427 test_create_repo rename-rename-2to1 &&
429 cd rename-rename-2to1 &&
431 printf "1\n2\n3\n4\n5\n" >a &&
432 printf "5\n4\n3\n2\n1\n" >b &&
437 git checkout -b B A &&
443 git checkout -b C A &&
451 test_expect_success
'handle rename/rename (2to1) conflict correctly' '
453 cd rename-rename-2to1 &&
457 test_must_fail git merge -s recursive C^0 >out &&
458 test_i18ngrep "CONFLICT (rename/rename)" out &&
460 git ls-files -s >out &&
461 test_line_count = 2 out &&
462 git ls-files -u >out &&
463 test_line_count = 2 out &&
464 git ls-files -u c >out &&
465 test_line_count = 2 out &&
466 git ls-files -o >out &&
467 test_line_count = 3 out &&
469 test_path_is_missing a &&
470 test_path_is_missing b &&
471 test_path_is_file c~HEAD &&
472 test_path_is_file c~C^0 &&
474 git rev-parse >expect \
476 git hash-object >actual \
478 test_cmp expect actual
482 # Testcase setup for simple rename/rename (1to2) conflict:
483 # Commit A: new file: a
484 # Commit B: rename a->b
485 # Commit C: rename a->c
486 test_expect_success
'setup simple rename/rename (1to2) conflict' '
487 test_create_repo rename-rename-1to2 &&
489 cd rename-rename-1to2 &&
497 git checkout -b B A &&
502 git checkout -b C A &&
509 test_expect_success
'merge has correct working tree contents' '
511 cd rename-rename-1to2 &&
515 test_must_fail git merge -s recursive B^0 &&
517 git ls-files -s >out &&
518 test_line_count = 3 out &&
519 git ls-files -u >out &&
520 test_line_count = 3 out &&
521 git ls-files -o >out &&
522 test_line_count = 1 out &&
524 test_path_is_missing a &&
525 git rev-parse >expect \
528 git rev-parse >actual \
530 git hash-object >>actual \
532 test_cmp expect actual
536 # Testcase setup for rename/rename(1to2)/add-source conflict:
537 # Commit A: new file: a
538 # Commit B: rename a->b
539 # Commit C: rename a->c, add completely different a
541 # Merging of B & C should NOT be clean; there's a rename/rename conflict
543 test_expect_success
'setup rename/rename(1to2)/add-source conflict' '
544 test_create_repo rename-rename-1to2-add-source-1 &&
546 cd rename-rename-1to2-add-source-1 &&
548 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
553 git checkout -b B A &&
557 git checkout -b C A &&
559 echo something completely different >a &&
565 test_expect_failure
'detect conflict with rename/rename(1to2)/add-source merge' '
567 cd rename-rename-1to2-add-source-1 &&
571 test_must_fail git merge -s recursive C^0 &&
573 git ls-files -s >out &&
574 test_line_count = 4 out &&
575 git ls-files -o >out &&
576 test_line_count = 1 out &&
578 git rev-parse >expect \
580 git rev-parse >actual \
581 :3:a :1:a :2:b :3:c &&
582 test_cmp expect actual &&
584 test_path_is_file a &&
585 test_path_is_file b &&
590 test_expect_success
'setup rename/rename(1to2)/add-source resolvable conflict' '
591 test_create_repo rename-rename-1to2-add-source-2 &&
593 cd rename-rename-1to2-add-source-2 &&
598 git commit -m base &&
601 git checkout -b B A &&
606 git checkout -b C A &&
608 echo important-info >a &&
615 test_expect_failure
'rename/rename/add-source still tracks new a file' '
617 cd rename-rename-1to2-add-source-2 &&
620 git merge -s recursive B^0 &&
622 git ls-files -s >out &&
623 test_line_count = 2 out &&
624 git ls-files -o >out &&
625 test_line_count = 1 out &&
627 git rev-parse >expect \
629 git rev-parse >actual \
631 test_cmp expect actual
635 test_expect_success
'setup rename/rename(1to2)/add-dest conflict' '
636 test_create_repo rename-rename-1to2-add-dest &&
638 cd rename-rename-1to2-add-dest &&
643 git commit -m base &&
646 git checkout -b B A &&
648 echo precious-data >c &&
653 git checkout -b C A &&
655 echo important-info >b &&
662 test_expect_success
'rename/rename/add-dest merge still knows about conflicting file versions' '
664 cd rename-rename-1to2-add-dest &&
667 test_must_fail git merge -s recursive B^0 &&
669 git ls-files -s >out &&
670 test_line_count = 5 out &&
671 git ls-files -u b >out &&
672 test_line_count = 2 out &&
673 git ls-files -u c >out &&
674 test_line_count = 2 out &&
675 git ls-files -o >out &&
676 test_line_count = 5 out &&
678 git rev-parse >expect \
679 A:a C:b B:b C:c B:c &&
680 git rev-parse >actual \
681 :1:a :2:b :3:b :2:c :3:c &&
682 test_cmp expect actual &&
684 git rev-parse >expect \
686 git hash-object >actual \
687 c~HEAD c~B\^0 b~HEAD b~B\^0 &&
688 test_cmp expect actual &&
690 test_path_is_missing b &&
691 test_path_is_missing c
695 # Testcase rad, rename/add/delete
697 # Commit A: rm foo, add different bar
698 # Commit B: rename foo->bar
699 # Expected: CONFLICT (rename/add/delete), two-way merged bar
701 test_expect_success
'rad-setup: rename/add/delete conflict' '
702 test_create_repo rad &&
705 echo "original file" >foo &&
707 git commit -m "original" &&
715 echo "different file" >bar &&
717 git commit -m "Remove foo, add bar" &&
721 git commit -m "rename foo to bar"
725 test_expect_failure
'rad-check: rename/add/delete conflict' '
730 test_must_fail git merge -s recursive A^0 >out 2>err &&
732 # Not sure whether the output should contain just one
733 # "CONFLICT (rename/add/delete)" line, or if it should break
734 # it into a pair of "CONFLICT (rename/delete)" and
735 # "CONFLICT (rename/add)"; allow for either.
736 test_i18ngrep "CONFLICT (rename.*add)" out &&
737 test_i18ngrep "CONFLICT (rename.*delete)" out &&
738 test_must_be_empty err &&
740 git ls-files -s >file_count &&
741 test_line_count = 2 file_count &&
742 git ls-files -u >file_count &&
743 test_line_count = 2 file_count &&
744 git ls-files -o >file_count &&
745 test_line_count = 2 file_count &&
747 git rev-parse >actual \
749 git rev-parse >expect \
752 test_cmp file_is_missing foo &&
753 # bar should have two-way merged contents of the different
754 # versions of bar; check that content from both sides is
761 # Testcase rrdd, rename/rename(2to1)/delete/delete
763 # Commit A: rename foo->baz, rm bar
764 # Commit B: rename bar->baz, rm foo
765 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
767 test_expect_success
'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
768 test_create_repo rrdd &&
783 git commit -m "Rename foo, remove bar" &&
788 git commit -m "Rename bar, remove foo"
792 test_expect_failure
'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
797 test_must_fail git merge -s recursive B^0 >out 2>err &&
799 # Not sure whether the output should contain just one
800 # "CONFLICT (rename/rename/delete/delete)" line, or if it
801 # should break it into three: "CONFLICT (rename/rename)" and
802 # two "CONFLICT (rename/delete)" lines; allow for either.
803 test_i18ngrep "CONFLICT (rename/rename)" out &&
804 test_i18ngrep "CONFLICT (rename.*delete)" out &&
805 test_must_be_empty err &&
807 git ls-files -s >file_count &&
808 test_line_count = 2 file_count &&
809 git ls-files -u >file_count &&
810 test_line_count = 2 file_count &&
811 git ls-files -o >file_count &&
812 test_line_count = 2 file_count &&
814 git rev-parse >actual \
816 git rev-parse >expect \
819 test_cmp file_is_missing foo &&
820 test_cmp file_is_missing bar &&
821 # baz should have two-way merged contents of the original
822 # contents of foo and bar; check that content from both sides
829 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
830 # Commit O: one, three, five
831 # Commit A: one->two, three->four, five->six
832 # Commit B: one->six, three->two, five->four
833 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
834 # multi-way merged contents found in two, four, six
836 test_expect_success
'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
837 test_create_repo mod6 &&
840 test_seq 11 19 >one &&
841 test_seq 31 39 >three &&
842 test_seq 51 59 >five &&
852 test_seq 10 19 >one &&
863 echo forty >>three &&
865 git add one three five &&
874 test_expect_failure
'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
880 test_must_fail git merge -s recursive B^0 >out 2>err &&
882 test_i18ngrep "CONFLICT (rename/rename)" out &&
883 test_must_be_empty err &&
885 git ls-files -s >file_count &&
886 test_line_count = 6 file_count &&
887 git ls-files -u >file_count &&
888 test_line_count = 6 file_count &&
889 git ls-files -o >file_count &&
890 test_line_count = 3 file_count &&
892 test_seq 10 20 >merged-one &&
893 test_seq 51 60 >merged-five &&
894 # Determine what the merge of three would give us.
895 test_seq 30 40 >three-side-A &&
896 test_seq 31 39 >three-side-B &&
897 echo forty >three-side-B &&
899 test_must_fail git merge-file \
903 three-side-A empty three-side-B &&
904 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
906 # Verify the index is as expected
907 git rev-parse >actual \
911 git hash-object >expect \
912 merged-one merged-three \
913 merged-three merged-five \
914 merged-five merged-one &&
915 test_cmp expect actual &&
917 git cat-file -p :2:two >expect &&
918 git cat-file -p :3:two >other &&
919 test_must_fail git merge-file \
920 -L "HEAD" -L "" -L "B^0" \
921 expect empty other &&
922 test_cmp expect two &&
924 git cat-file -p :2:four >expect &&
925 git cat-file -p :3:four >other &&
926 test_must_fail git merge-file \
927 -L "HEAD" -L "" -L "B^0" \
928 expect empty other &&
929 test_cmp expect four &&
931 git cat-file -p :2:six >expect &&
932 git cat-file -p :3:six >other &&
933 test_must_fail git merge-file \
934 -L "HEAD" -L "" -L "B^0" \
935 expect empty other &&