Git 2.23-rc1
[git.git] / t / t6042-merge-rename-corner-cases.sh
blobc5b57f40c3d127cffda505f9ffe91effffafb135
1 #!/bin/sh
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
6 . ./test-lib.sh
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 &&
14 git add ring &&
15 test_tick &&
16 git commit -m beginning &&
18 git branch people &&
19 git checkout -b rename-the-ring &&
20 git mv ring one-ring-to-rule-them-all &&
21 test_tick &&
22 git commit -m fullname &&
24 git checkout people &&
25 git rm ring &&
26 echo gollum >owner &&
27 git add owner &&
28 test_tick &&
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 &&
58 git add a &&
59 git commit -m A &&
60 git tag A &&
62 git checkout -b B A &&
63 echo 8 >>a &&
64 git add a &&
65 git commit -m B &&
67 git checkout -b C A &&
68 git mv a b &&
69 echo something completely different >a &&
70 git add a &&
71 git commit -m C
75 test_expect_failure 'rename/modify/add-source conflict resolvable' '
77 cd rename-modify-add-source &&
79 git checkout B^0 &&
81 git merge -s recursive C^0 &&
83 git rev-parse >expect \
84 B:a C:a &&
85 git rev-parse >actual \
86 b c &&
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 &&
97 echo foo >b &&
98 git add a b &&
99 git commit -m A &&
100 git tag A &&
102 git checkout -b B A &&
103 git mv a c &&
104 echo "Completely different content" >a &&
105 git add a &&
106 git commit -m B &&
108 git checkout -b C A &&
109 echo 6 >>a &&
110 git add a &&
111 git commit -m C
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 \
131 B:a A:b &&
132 git rev-parse >actual \
133 :0:a :0:b &&
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 &&
144 echo foo >b &&
145 git add a b &&
146 git commit -m A &&
147 git tag A &&
149 git checkout -b D A &&
150 echo 7 >>a &&
151 git add a &&
152 git mv a c &&
153 echo "Completely different content" >a &&
154 git add a &&
155 git commit -m D &&
157 git checkout -b E A &&
158 git rm a &&
159 echo "Completely different content" >>a &&
160 git add a &&
161 git commit -m E
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 &&
191 git add a &&
192 git commit -m A &&
193 git tag A &&
195 git checkout -b B A &&
196 git mv a b &&
197 git commit -m B &&
199 git checkout -b C A &&
200 git mv a b &&
201 echo foobar >a &&
202 git add a &&
203 git commit -m C
207 test_expect_failure 'detect rename/add-source and preserve all data' '
209 cd break-detection-3 &&
211 git checkout B^0 &&
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 \
226 A:a C:a &&
227 git rev-parse >actual \
228 :0:b :0:a &&
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 &&
237 git checkout C^0 &&
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 \
252 A:a C:a &&
253 git rev-parse >actual \
254 :0:b :0:a &&
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 &&
265 git add file &&
266 test_tick &&
267 git commit -m base &&
268 git tag base &&
270 git checkout -b right &&
271 echo 7 >>file &&
272 mkdir newfile &&
273 echo junk >newfile/realfile &&
274 git add file newfile/realfile &&
275 test_tick &&
276 git commit -m right &&
278 git checkout -b left-conflict base &&
279 echo 8 >>file &&
280 git add file &&
281 git mv file newfile &&
282 test_tick &&
283 git commit -m left &&
285 git checkout -b left-clean base &&
286 echo 0 >newfile &&
287 cat file >>newfile &&
288 git add newfile &&
289 git rm file &&
290 test_tick &&
291 git commit -m left
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 &&
310 echo 0 >expect &&
311 git cat-file -p base:file >>expect &&
312 echo 7 >>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 &&
326 git reset --hard &&
327 git clean -fdqx &&
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 \
344 -L "HEAD:newfile" \
345 -L "" \
346 -L "right^0:file" \
347 left base right &&
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 &&
366 mkdir sub &&
367 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
368 git add sub/file &&
369 test_tick &&
370 git commit -m base &&
371 git tag base &&
373 git checkout -b right &&
374 echo 7 >>sub/file &&
375 git add sub/file &&
376 test_tick &&
377 git commit -m right &&
379 git checkout -b left base &&
380 echo 0 >newfile &&
381 cat sub/file >>newfile &&
382 git rm sub/file &&
383 mv newfile sub &&
384 git add sub &&
385 test_tick &&
386 git commit -m left
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 &&
405 echo 0 >expect &&
406 git cat-file -p base:sub/file >>expect &&
407 echo 7 >>expect &&
408 test_cmp expect sub &&
410 test_path_is_file sub
414 # Test for basic rename/add-dest conflict, with rename needing content merge:
415 # Commit O: a
416 # Commit A: rename a->b, modifying b too
417 # Commit B: modify a, add different b
419 test_expect_success 'setup rename-with-content-merge vs. add' '
420 test_create_repo rename-with-content-merge-and-add &&
422 cd rename-with-content-merge-and-add &&
424 test_seq 1 5 >a &&
425 git add a &&
426 git commit -m O &&
427 git tag O &&
429 git checkout -b A O &&
430 git mv a b &&
431 test_seq 0 5 >b &&
432 git add b &&
433 git commit -m A &&
435 git checkout -b B O &&
436 echo 6 >>a &&
437 echo hello world >b &&
438 git add a b &&
439 git commit -m B
443 test_expect_success 'handle rename-with-content-merge vs. add' '
445 cd rename-with-content-merge-and-add &&
447 git checkout A^0 &&
449 test_must_fail git merge -s recursive B^0 >out &&
450 test_i18ngrep "CONFLICT (rename/add)" out &&
452 git ls-files -s >out &&
453 test_line_count = 2 out &&
454 git ls-files -u >out &&
455 test_line_count = 2 out &&
456 # Also, make sure both unmerged entries are for "b"
457 git ls-files -u b >out &&
458 test_line_count = 2 out &&
459 git ls-files -o >out &&
460 test_line_count = 1 out &&
462 test_path_is_missing a &&
463 test_path_is_file b &&
465 test_seq 0 6 >tmp &&
466 git hash-object tmp >expect &&
467 git rev-parse B:b >>expect &&
468 git rev-parse >actual \
469 :2:b :3:b &&
470 test_cmp expect actual &&
472 # Test that the two-way merge in b is as expected
473 git cat-file -p :2:b >>ours &&
474 git cat-file -p :3:b >>theirs &&
475 >empty &&
476 test_must_fail git merge-file \
477 -L "HEAD" \
478 -L "" \
479 -L "B^0" \
480 ours empty theirs &&
481 test_cmp ours b
485 test_expect_success 'handle rename-with-content-merge vs. add, merge other way' '
487 cd rename-with-content-merge-and-add &&
489 git reset --hard &&
490 git clean -fdx &&
492 git checkout B^0 &&
494 test_must_fail git merge -s recursive A^0 >out &&
495 test_i18ngrep "CONFLICT (rename/add)" out &&
497 git ls-files -s >out &&
498 test_line_count = 2 out &&
499 git ls-files -u >out &&
500 test_line_count = 2 out &&
501 # Also, make sure both unmerged entries are for "b"
502 git ls-files -u b >out &&
503 test_line_count = 2 out &&
504 git ls-files -o >out &&
505 test_line_count = 1 out &&
507 test_path_is_missing a &&
508 test_path_is_file b &&
510 test_seq 0 6 >tmp &&
511 git rev-parse B:b >expect &&
512 git hash-object tmp >>expect &&
513 git rev-parse >actual \
514 :2:b :3:b &&
515 test_cmp expect actual &&
517 # Test that the two-way merge in b is as expected
518 git cat-file -p :2:b >>ours &&
519 git cat-file -p :3:b >>theirs &&
520 >empty &&
521 test_must_fail git merge-file \
522 -L "HEAD" \
523 -L "" \
524 -L "A^0" \
525 ours empty theirs &&
526 test_cmp ours b
530 # Test for all kinds of things that can go wrong with rename/rename (2to1):
531 # Commit A: new files: a & b
532 # Commit B: rename a->c, modify b
533 # Commit C: rename b->c, modify a
535 # Merging of B & C should NOT be clean. Questions:
536 # * Both a & b should be removed by the merge; are they?
537 # * The two c's should contain modifications to a & b; do they?
538 # * The index should contain two files, both for c; does it?
539 # * The working copy should have two files, both of form c~<unique>; does it?
540 # * Nothing else should be present. Is anything?
542 test_expect_success 'setup rename/rename (2to1) + modify/modify' '
543 test_create_repo rename-rename-2to1 &&
545 cd rename-rename-2to1 &&
547 printf "1\n2\n3\n4\n5\n" >a &&
548 printf "5\n4\n3\n2\n1\n" >b &&
549 git add a b &&
550 git commit -m A &&
551 git tag A &&
553 git checkout -b B A &&
554 git mv a c &&
555 echo 0 >>b &&
556 git add b &&
557 git commit -m B &&
559 git checkout -b C A &&
560 git mv b c &&
561 echo 6 >>a &&
562 git add a &&
563 git commit -m C
567 test_expect_success 'handle rename/rename (2to1) conflict correctly' '
569 cd rename-rename-2to1 &&
571 git checkout B^0 &&
573 test_must_fail git merge -s recursive C^0 >out &&
574 test_i18ngrep "CONFLICT (rename/rename)" out &&
576 git ls-files -s >out &&
577 test_line_count = 2 out &&
578 git ls-files -u >out &&
579 test_line_count = 2 out &&
580 git ls-files -u c >out &&
581 test_line_count = 2 out &&
582 git ls-files -o >out &&
583 test_line_count = 1 out &&
585 test_path_is_missing a &&
586 test_path_is_missing b &&
588 git rev-parse >expect \
589 C:a B:b &&
590 git rev-parse >actual \
591 :2:c :3:c &&
592 test_cmp expect actual &&
594 # Test that the two-way merge in new_a is as expected
595 git cat-file -p :2:c >>ours &&
596 git cat-file -p :3:c >>theirs &&
597 >empty &&
598 test_must_fail git merge-file \
599 -L "HEAD" \
600 -L "" \
601 -L "C^0" \
602 ours empty theirs &&
603 git hash-object c >actual &&
604 git hash-object ours >expect &&
605 test_cmp expect actual
609 # Testcase setup for simple rename/rename (1to2) conflict:
610 # Commit A: new file: a
611 # Commit B: rename a->b
612 # Commit C: rename a->c
613 test_expect_success 'setup simple rename/rename (1to2) conflict' '
614 test_create_repo rename-rename-1to2 &&
616 cd rename-rename-1to2 &&
618 echo stuff >a &&
619 git add a &&
620 test_tick &&
621 git commit -m A &&
622 git tag A &&
624 git checkout -b B A &&
625 git mv a b &&
626 test_tick &&
627 git commit -m B &&
629 git checkout -b C A &&
630 git mv a c &&
631 test_tick &&
632 git commit -m C
636 test_expect_success 'merge has correct working tree contents' '
638 cd rename-rename-1to2 &&
640 git checkout C^0 &&
642 test_must_fail git merge -s recursive B^0 &&
644 git ls-files -s >out &&
645 test_line_count = 3 out &&
646 git ls-files -u >out &&
647 test_line_count = 3 out &&
648 git ls-files -o >out &&
649 test_line_count = 1 out &&
651 test_path_is_missing a &&
652 git rev-parse >expect \
653 A:a A:a A:a \
654 A:a A:a &&
655 git rev-parse >actual \
656 :1:a :3:b :2:c &&
657 git hash-object >>actual \
658 b c &&
659 test_cmp expect actual
663 # Testcase setup for rename/rename(1to2)/add-source conflict:
664 # Commit A: new file: a
665 # Commit B: rename a->b
666 # Commit C: rename a->c, add completely different a
668 # Merging of B & C should NOT be clean; there's a rename/rename conflict
670 test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
671 test_create_repo rename-rename-1to2-add-source-1 &&
673 cd rename-rename-1to2-add-source-1 &&
675 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
676 git add a &&
677 git commit -m A &&
678 git tag A &&
680 git checkout -b B A &&
681 git mv a b &&
682 git commit -m B &&
684 git checkout -b C A &&
685 git mv a c &&
686 echo something completely different >a &&
687 git add a &&
688 git commit -m C
692 test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
694 cd rename-rename-1to2-add-source-1 &&
696 git checkout B^0 &&
698 test_must_fail git merge -s recursive C^0 &&
700 git ls-files -s >out &&
701 test_line_count = 4 out &&
702 git ls-files -o >out &&
703 test_line_count = 1 out &&
705 git rev-parse >expect \
706 C:a A:a B:b C:C &&
707 git rev-parse >actual \
708 :3:a :1:a :2:b :3:c &&
709 test_cmp expect actual &&
711 test_path_is_file a &&
712 test_path_is_file b &&
713 test_path_is_file c
717 test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
718 test_create_repo rename-rename-1to2-add-source-2 &&
720 cd rename-rename-1to2-add-source-2 &&
722 >a &&
723 git add a &&
724 test_tick &&
725 git commit -m base &&
726 git tag A &&
728 git checkout -b B A &&
729 git mv a b &&
730 test_tick &&
731 git commit -m one &&
733 git checkout -b C A &&
734 git mv a b &&
735 echo important-info >a &&
736 git add a &&
737 test_tick &&
738 git commit -m two
742 test_expect_failure 'rename/rename/add-source still tracks new a file' '
744 cd rename-rename-1to2-add-source-2 &&
746 git checkout C^0 &&
747 git merge -s recursive B^0 &&
749 git ls-files -s >out &&
750 test_line_count = 2 out &&
751 git ls-files -o >out &&
752 test_line_count = 1 out &&
754 git rev-parse >expect \
755 C:a A:a &&
756 git rev-parse >actual \
757 :0:a :0:b &&
758 test_cmp expect actual
762 test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
763 test_create_repo rename-rename-1to2-add-dest &&
765 cd rename-rename-1to2-add-dest &&
767 echo stuff >a &&
768 git add a &&
769 test_tick &&
770 git commit -m base &&
771 git tag A &&
773 git checkout -b B A &&
774 git mv a b &&
775 echo precious-data >c &&
776 git add c &&
777 test_tick &&
778 git commit -m one &&
780 git checkout -b C A &&
781 git mv a c &&
782 echo important-info >b &&
783 git add b &&
784 test_tick &&
785 git commit -m two
789 test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
791 cd rename-rename-1to2-add-dest &&
793 git checkout C^0 &&
794 test_must_fail git merge -s recursive B^0 &&
796 git ls-files -s >out &&
797 test_line_count = 5 out &&
798 git ls-files -u b >out &&
799 test_line_count = 2 out &&
800 git ls-files -u c >out &&
801 test_line_count = 2 out &&
802 git ls-files -o >out &&
803 test_line_count = 1 out &&
805 git rev-parse >expect \
806 A:a C:b B:b C:c B:c &&
807 git rev-parse >actual \
808 :1:a :2:b :3:b :2:c :3:c &&
809 test_cmp expect actual &&
811 # Record some contents for re-doing merges
812 git cat-file -p A:a >stuff &&
813 git cat-file -p C:b >important_info &&
814 git cat-file -p B:c >precious_data &&
815 >empty &&
817 # Test the merge in b
818 test_must_fail git merge-file \
819 -L "HEAD" \
820 -L "" \
821 -L "B^0" \
822 important_info empty stuff &&
823 test_cmp important_info b &&
825 # Test the merge in c
826 test_must_fail git merge-file \
827 -L "HEAD" \
828 -L "" \
829 -L "B^0" \
830 stuff empty precious_data &&
831 test_cmp stuff c
835 # Testcase rad, rename/add/delete
836 # Commit O: foo
837 # Commit A: rm foo, add different bar
838 # Commit B: rename foo->bar
839 # Expected: CONFLICT (rename/add/delete), two-way merged bar
841 test_expect_success 'rad-setup: rename/add/delete conflict' '
842 test_create_repo rad &&
844 cd rad &&
845 echo "original file" >foo &&
846 git add foo &&
847 git commit -m "original" &&
849 git branch O &&
850 git branch A &&
851 git branch B &&
853 git checkout A &&
854 git rm foo &&
855 echo "different file" >bar &&
856 git add bar &&
857 git commit -m "Remove foo, add bar" &&
859 git checkout B &&
860 git mv foo bar &&
861 git commit -m "rename foo to bar"
865 test_expect_failure 'rad-check: rename/add/delete conflict' '
867 cd rad &&
869 git checkout B^0 &&
870 test_must_fail git merge -s recursive A^0 >out 2>err &&
872 # Not sure whether the output should contain just one
873 # "CONFLICT (rename/add/delete)" line, or if it should break
874 # it into a pair of "CONFLICT (rename/delete)" and
875 # "CONFLICT (rename/add)"; allow for either.
876 test_i18ngrep "CONFLICT (rename.*add)" out &&
877 test_i18ngrep "CONFLICT (rename.*delete)" out &&
878 test_must_be_empty err &&
880 git ls-files -s >file_count &&
881 test_line_count = 2 file_count &&
882 git ls-files -u >file_count &&
883 test_line_count = 2 file_count &&
884 git ls-files -o >file_count &&
885 test_line_count = 2 file_count &&
887 git rev-parse >actual \
888 :2:bar :3:bar &&
889 git rev-parse >expect \
890 B:bar A:bar &&
892 test_cmp file_is_missing foo &&
893 # bar should have two-way merged contents of the different
894 # versions of bar; check that content from both sides is
895 # present.
896 grep original bar &&
897 grep different bar
901 # Testcase rrdd, rename/rename(2to1)/delete/delete
902 # Commit O: foo, bar
903 # Commit A: rename foo->baz, rm bar
904 # Commit B: rename bar->baz, rm foo
905 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
907 test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
908 test_create_repo rrdd &&
910 cd rrdd &&
911 echo foo >foo &&
912 echo bar >bar &&
913 git add foo bar &&
914 git commit -m O &&
916 git branch O &&
917 git branch A &&
918 git branch B &&
920 git checkout A &&
921 git mv foo baz &&
922 git rm bar &&
923 git commit -m "Rename foo, remove bar" &&
925 git checkout B &&
926 git mv bar baz &&
927 git rm foo &&
928 git commit -m "Rename bar, remove foo"
932 test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
934 cd rrdd &&
936 git checkout A^0 &&
937 test_must_fail git merge -s recursive B^0 >out 2>err &&
939 # Not sure whether the output should contain just one
940 # "CONFLICT (rename/rename/delete/delete)" line, or if it
941 # should break it into three: "CONFLICT (rename/rename)" and
942 # two "CONFLICT (rename/delete)" lines; allow for either.
943 test_i18ngrep "CONFLICT (rename/rename)" out &&
944 test_i18ngrep "CONFLICT (rename.*delete)" out &&
945 test_must_be_empty err &&
947 git ls-files -s >file_count &&
948 test_line_count = 2 file_count &&
949 git ls-files -u >file_count &&
950 test_line_count = 2 file_count &&
951 git ls-files -o >file_count &&
952 test_line_count = 2 file_count &&
954 git rev-parse >actual \
955 :2:baz :3:baz &&
956 git rev-parse >expect \
957 O:foo O:bar &&
959 test_cmp file_is_missing foo &&
960 test_cmp file_is_missing bar &&
961 # baz should have two-way merged contents of the original
962 # contents of foo and bar; check that content from both sides
963 # is present.
964 grep foo baz &&
965 grep bar baz
969 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
970 # Commit O: one, three, five
971 # Commit A: one->two, three->four, five->six
972 # Commit B: one->six, three->two, five->four
973 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
974 # multi-way merged contents found in two, four, six
976 test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
977 test_create_repo mod6 &&
979 cd mod6 &&
980 test_seq 11 19 >one &&
981 test_seq 31 39 >three &&
982 test_seq 51 59 >five &&
983 git add . &&
984 test_tick &&
985 git commit -m "O" &&
987 git branch O &&
988 git branch A &&
989 git branch B &&
991 git checkout A &&
992 test_seq 10 19 >one &&
993 echo 40 >>three &&
994 git add one three &&
995 git mv one two &&
996 git mv three four &&
997 git mv five six &&
998 test_tick &&
999 git commit -m "A" &&
1001 git checkout B &&
1002 echo 20 >>one &&
1003 echo forty >>three &&
1004 echo 60 >>five &&
1005 git add one three five &&
1006 git mv one six &&
1007 git mv three two &&
1008 git mv five four &&
1009 test_tick &&
1010 git commit -m "B"
1014 test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
1016 cd mod6 &&
1018 git checkout A^0 &&
1020 test_must_fail git merge -s recursive B^0 >out 2>err &&
1022 test_i18ngrep "CONFLICT (rename/rename)" out &&
1023 test_must_be_empty err &&
1025 git ls-files -s >file_count &&
1026 test_line_count = 6 file_count &&
1027 git ls-files -u >file_count &&
1028 test_line_count = 6 file_count &&
1029 git ls-files -o >file_count &&
1030 test_line_count = 3 file_count &&
1032 test_seq 10 20 >merged-one &&
1033 test_seq 51 60 >merged-five &&
1034 # Determine what the merge of three would give us.
1035 test_seq 30 40 >three-side-A &&
1036 test_seq 31 39 >three-side-B &&
1037 echo forty >three-side-B &&
1038 >empty &&
1039 test_must_fail git merge-file \
1040 -L "HEAD" \
1041 -L "" \
1042 -L "B^0" \
1043 three-side-A empty three-side-B &&
1044 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
1046 # Verify the index is as expected
1047 git rev-parse >actual \
1048 :2:two :3:two \
1049 :2:four :3:four \
1050 :2:six :3:six &&
1051 git hash-object >expect \
1052 merged-one merged-three \
1053 merged-three merged-five \
1054 merged-five merged-one &&
1055 test_cmp expect actual &&
1057 git cat-file -p :2:two >expect &&
1058 git cat-file -p :3:two >other &&
1059 test_must_fail git merge-file \
1060 -L "HEAD" -L "" -L "B^0" \
1061 expect empty other &&
1062 test_cmp expect two &&
1064 git cat-file -p :2:four >expect &&
1065 git cat-file -p :3:four >other &&
1066 test_must_fail git merge-file \
1067 -L "HEAD" -L "" -L "B^0" \
1068 expect empty other &&
1069 test_cmp expect four &&
1071 git cat-file -p :2:six >expect &&
1072 git cat-file -p :3:six >other &&
1073 test_must_fail git merge-file \
1074 -L "HEAD" -L "" -L "B^0" \
1075 expect empty other &&
1076 test_cmp expect six
1080 test_conflicts_with_adds_and_renames() {
1081 sideL=$1
1082 sideR=$2
1084 # Setup:
1086 # / \
1087 # master ?
1088 # \ /
1091 # Where:
1092 # Both L and R have files named 'three' which collide. Each of
1093 # the colliding files could have been involved in a rename, in
1094 # which case there was a file named 'one' or 'two' that was
1095 # modified on the opposite side of history and renamed into the
1096 # collision on this side of history.
1098 # Questions:
1099 # 1) The index should contain both a stage 2 and stage 3 entry
1100 # for the colliding file. Does it?
1101 # 2) When renames are involved, the content merges are clean, so
1102 # the index should reflect the content merges, not merely the
1103 # version of the colliding file from the prior commit. Does
1104 # it?
1105 # 3) There should be a file in the worktree named 'three'
1106 # containing the two-way merged contents of the content-merged
1107 # versions of 'three' from each of the two colliding
1108 # files. Is it present?
1109 # 4) There should not be any three~* files in the working
1110 # tree
1111 test_expect_success "setup simple $sideL/$sideR conflict" '
1112 test_create_repo simple_${sideL}_${sideR} &&
1114 cd simple_${sideL}_${sideR} &&
1116 # Create some related files now
1117 for i in $(test_seq 1 10)
1119 echo Random base content line $i
1120 done >file_v1 &&
1121 cp file_v1 file_v2 &&
1122 echo modification >>file_v2 &&
1124 cp file_v1 file_v3 &&
1125 echo more stuff >>file_v3 &&
1126 cp file_v3 file_v4 &&
1127 echo yet more stuff >>file_v4 &&
1129 # Use a tag to record both these files for simple
1130 # access, and clean out these untracked files
1131 git tag file_v1 $(git hash-object -w file_v1) &&
1132 git tag file_v2 $(git hash-object -w file_v2) &&
1133 git tag file_v3 $(git hash-object -w file_v3) &&
1134 git tag file_v4 $(git hash-object -w file_v4) &&
1135 git clean -f &&
1137 # Setup original commit (or merge-base), consisting of
1138 # files named "one" and "two" if renames were involved.
1139 touch irrelevant_file &&
1140 git add irrelevant_file &&
1141 if [ $sideL = "rename" ]
1142 then
1143 git show file_v1 >one &&
1144 git add one
1145 fi &&
1146 if [ $sideR = "rename" ]
1147 then
1148 git show file_v3 >two &&
1149 git add two
1150 fi &&
1151 test_tick && git commit -m initial &&
1153 git branch L &&
1154 git branch R &&
1156 # Handle the left side
1157 git checkout L &&
1158 if [ $sideL = "rename" ]
1159 then
1160 git mv one three
1161 else
1162 git show file_v2 >three &&
1163 git add three
1164 fi &&
1165 if [ $sideR = "rename" ]
1166 then
1167 git show file_v4 >two &&
1168 git add two
1169 fi &&
1170 test_tick && git commit -m L &&
1172 # Handle the right side
1173 git checkout R &&
1174 if [ $sideL = "rename" ]
1175 then
1176 git show file_v2 >one &&
1177 git add one
1178 fi &&
1179 if [ $sideR = "rename" ]
1180 then
1181 git mv two three
1182 else
1183 git show file_v4 >three &&
1184 git add three
1185 fi &&
1186 test_tick && git commit -m R
1190 test_expect_success "check simple $sideL/$sideR conflict" '
1192 cd simple_${sideL}_${sideR} &&
1194 git checkout L^0 &&
1196 # Merge must fail; there is a conflict
1197 test_must_fail git merge -s recursive R^0 &&
1199 # Make sure the index has the right number of entries
1200 git ls-files -s >out &&
1201 test_line_count = 3 out &&
1202 git ls-files -u >out &&
1203 test_line_count = 2 out &&
1204 # Ensure we have the correct number of untracked files
1205 git ls-files -o >out &&
1206 test_line_count = 1 out &&
1208 # Nothing should have touched irrelevant_file
1209 git rev-parse >actual \
1210 :0:irrelevant_file \
1211 :2:three \
1212 :3:three &&
1213 git rev-parse >expected \
1214 master:irrelevant_file \
1215 file_v2 \
1216 file_v4 &&
1217 test_cmp expected actual &&
1219 # Make sure we have the correct merged contents for
1220 # three
1221 git show file_v1 >expected &&
1222 cat <<-\EOF >>expected &&
1223 <<<<<<< HEAD
1224 modification
1225 =======
1226 more stuff
1227 yet more stuff
1228 >>>>>>> R^0
1231 test_cmp expected three
1236 test_conflicts_with_adds_and_renames rename rename
1237 test_conflicts_with_adds_and_renames rename add
1238 test_conflicts_with_adds_and_renames add rename
1239 test_conflicts_with_adds_and_renames add add
1241 # Setup:
1243 # / \
1244 # master ?
1245 # \ /
1248 # Where:
1249 # master has two files, named 'one' and 'two'.
1250 # branches L and R both modify 'one', in conflicting ways.
1251 # branches L and R both modify 'two', in conflicting ways.
1252 # branch L also renames 'one' to 'three'.
1253 # branch R also renames 'two' to 'three'.
1255 # So, we have four different conflicting files that all end up at path
1256 # 'three'.
1257 test_expect_success 'setup nested conflicts from rename/rename(2to1)' '
1258 test_create_repo nested_conflicts_from_rename_rename &&
1260 cd nested_conflicts_from_rename_rename &&
1262 # Create some related files now
1263 for i in $(test_seq 1 10)
1265 echo Random base content line $i
1266 done >file_v1 &&
1268 cp file_v1 file_v2 &&
1269 cp file_v1 file_v3 &&
1270 cp file_v1 file_v4 &&
1271 cp file_v1 file_v5 &&
1272 cp file_v1 file_v6 &&
1274 echo one >>file_v1 &&
1275 echo uno >>file_v2 &&
1276 echo eins >>file_v3 &&
1278 echo two >>file_v4 &&
1279 echo dos >>file_v5 &&
1280 echo zwei >>file_v6 &&
1282 # Setup original commit (or merge-base), consisting of
1283 # files named "one" and "two".
1284 mv file_v1 one &&
1285 mv file_v4 two &&
1286 git add one two &&
1287 test_tick && git commit -m english &&
1289 git branch L &&
1290 git branch R &&
1292 # Handle the left side
1293 git checkout L &&
1294 git rm one two &&
1295 mv -f file_v2 three &&
1296 mv -f file_v5 two &&
1297 git add two three &&
1298 test_tick && git commit -m spanish &&
1300 # Handle the right side
1301 git checkout R &&
1302 git rm one two &&
1303 mv -f file_v3 one &&
1304 mv -f file_v6 three &&
1305 git add one three &&
1306 test_tick && git commit -m german
1310 test_expect_success 'check nested conflicts from rename/rename(2to1)' '
1312 cd nested_conflicts_from_rename_rename &&
1314 git checkout L^0 &&
1316 # Merge must fail; there is a conflict
1317 test_must_fail git merge -s recursive R^0 &&
1319 # Make sure the index has the right number of entries
1320 git ls-files -s >out &&
1321 test_line_count = 2 out &&
1322 git ls-files -u >out &&
1323 test_line_count = 2 out &&
1324 # Ensure we have the correct number of untracked files
1325 git ls-files -o >out &&
1326 test_line_count = 1 out &&
1328 # Compare :2:three to expected values
1329 git cat-file -p master:one >base &&
1330 git cat-file -p L:three >ours &&
1331 git cat-file -p R:one >theirs &&
1332 test_must_fail git merge-file \
1333 -L "HEAD:three" -L "" -L "R^0:one" \
1334 ours base theirs &&
1335 sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
1336 git cat-file -p :2:three >expect &&
1337 test_cmp expect L-three &&
1339 # Compare :2:three to expected values
1340 git cat-file -p master:two >base &&
1341 git cat-file -p L:two >ours &&
1342 git cat-file -p R:three >theirs &&
1343 test_must_fail git merge-file \
1344 -L "HEAD:two" -L "" -L "R^0:three" \
1345 ours base theirs &&
1346 sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
1347 git cat-file -p :3:three >expect &&
1348 test_cmp expect R-three &&
1350 # Compare three to expected contents
1351 >empty &&
1352 test_must_fail git merge-file \
1353 -L "HEAD" -L "" -L "R^0" \
1354 L-three empty R-three &&
1355 test_cmp three L-three
1359 test_done