3 test_description
="recursive merge with directory renames"
4 # includes checking of many corner cases, with a similar methodology to:
5 # t6042: corner cases with renames but not criss-cross merges
6 # t6036: corner cases with both renames and criss-cross merges
8 # The setup for all of them, pictorially, is:
18 # To help make it easier to follow the flow of tests, they have been
19 # divided into sections and each test will start with a quick explanation
20 # of what commits O, A, and B contain.
23 # z/{b,c} means files z/b and z/c both exist
24 # x/d_1 means file x/d exists with content d1. (Purpose of the
25 # underscore notation is to differentiate different
26 # files that might be renamed into each other's paths.)
29 .
"$TEST_DIRECTORY"/lib-merge.sh
32 ###########################################################################
33 # SECTION 1: Basic cases we should be able to handle
34 ###########################################################################
36 # Testcase 1a, Basic directory rename.
39 # Commit B: z/{b,c,d,e/f}
40 # Expected: y/{b,c,d,e/f}
43 test_create_repo
1a
&&
73 test_expect_success
'1a: Simple directory rename detection' '
80 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
82 git ls-files -s >out &&
83 test_line_count = 4 out &&
85 git rev-parse >actual \
86 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
87 git rev-parse >expect \
88 O:z/b O:z/c B:z/d B:z/e/f &&
89 test_cmp expect actual &&
91 git hash-object y/d >actual &&
92 git rev-parse B:z/d >expect &&
93 test_cmp expect actual &&
95 test_must_fail git rev-parse HEAD:z/d &&
96 test_must_fail git rev-parse HEAD:z/e/f &&
97 test_path_is_missing z/d &&
98 test_path_is_missing z/e/f
102 # Testcase 1b, Merge a directory with another
103 # Commit O: z/{b,c}, y/d
104 # Commit A: z/{b,c,e}, y/d
105 # Commit B: y/{b,c,d}
106 # Expected: y/{b,c,d,e}
109 test_create_repo
1b
&&
141 test_expect_success
'1b: Merge a directory with another' '
148 git -c merge.directoryRenames=true merge -s recursive B^0 &&
150 git ls-files -s >out &&
151 test_line_count = 4 out &&
153 git rev-parse >actual \
154 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
155 git rev-parse >expect \
156 O:z/b O:z/c O:y/d A:z/e &&
157 test_cmp expect actual &&
158 test_must_fail git rev-parse HEAD:z/e
162 # Testcase 1c, Transitive renaming
163 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
164 # (Related to testcases 9c and 9d -- can transitivity repeat?)
165 # (Related to testcase 12b -- joint-transitivity?)
166 # Commit O: z/{b,c}, x/d
167 # Commit A: y/{b,c}, x/d
168 # Commit B: z/{b,c,d}
169 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
172 test_create_repo
1c
&&
201 test_expect_success
'1c: Transitive renaming' '
208 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
210 git ls-files -s >out &&
211 test_line_count = 3 out &&
213 git rev-parse >actual \
214 HEAD:y/b HEAD:y/c HEAD:y/d &&
215 git rev-parse >expect \
217 test_cmp expect actual &&
218 test_must_fail git rev-parse HEAD:x/d &&
219 test_must_fail git rev-parse HEAD:z/d &&
220 test_path_is_missing z/d
224 # Testcase 1d, Directory renames (merging two directories into one new one)
225 # cause a rename/rename(2to1) conflict
226 # (Related to testcases 1c and 7b)
227 # Commit O. z/{b,c}, y/{d,e}
228 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
229 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
230 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
231 # Note: y/m & z/n should definitely move into x. By the same token, both
232 # y/wham_1 & z/wham_2 should too...giving us a conflict.
235 test_create_repo
1d
&&
256 echo wham1
>y
/wham
&&
264 echo wham2
>z
/wham
&&
271 test_expect_success
'1d: Directory renames cause a rename/rename(2to1) conflict' '
278 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
279 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
281 git ls-files -s >out &&
282 test_line_count = 8 out &&
283 git ls-files -u >out &&
284 test_line_count = 2 out &&
285 git ls-files -o >out &&
286 test_line_count = 1 out &&
288 git rev-parse >actual \
289 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
290 git rev-parse >expect \
291 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
292 test_cmp expect actual &&
294 test_must_fail git rev-parse :0:x/wham &&
295 git rev-parse >actual \
296 :2:x/wham :3:x/wham &&
297 git rev-parse >expect \
299 test_cmp expect actual &&
301 # Test that the two-way merge in x/wham is as expected
302 git cat-file -p :2:x/wham >expect &&
303 git cat-file -p :3:x/wham >other &&
305 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
307 test_must_fail git merge-file \
313 test_must_fail git merge-file \
319 test_cmp expect x/wham
323 # Testcase 1e, Renamed directory, with all filenames being renamed too
324 # (Related to testcases 9f & 9g)
325 # Commit O: z/{oldb,oldc}
326 # Commit A: y/{newb,newc}
327 # Commit B: z/{oldb,oldc,d}
328 # Expected: y/{newb,newc,d}
331 test_create_repo
1e
&&
348 git
mv z
/oldb y
/newb
&&
349 git
mv z
/oldc y
/newc
&&
361 test_expect_success
'1e: Renamed directory, with all files being renamed too' '
368 git -c merge.directoryRenames=true merge -s recursive B^0 &&
370 git ls-files -s >out &&
371 test_line_count = 3 out &&
373 git rev-parse >actual \
374 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
375 git rev-parse >expect \
376 O:z/oldb O:z/oldc B:z/d &&
377 test_cmp expect actual &&
378 test_must_fail git rev-parse HEAD:z/d
382 # Testcase 1f, Split a directory into two other directories
383 # (Related to testcases 3a, all of section 2, and all of section 4)
384 # Commit O: z/{b,c,d,e,f}
385 # Commit A: z/{b,c,d,e,f,g}
386 # Commit B: y/{b,c}, x/{d,e,f}
387 # Expected: y/{b,c}, x/{d,e,f,g}
390 test_create_repo
1f
&&
428 test_expect_success
'1f: Split a directory into two other directories' '
435 git -c merge.directoryRenames=true merge -s recursive B^0 &&
437 git ls-files -s >out &&
438 test_line_count = 6 out &&
440 git rev-parse >actual \
441 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
442 git rev-parse >expect \
443 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
444 test_cmp expect actual &&
445 test_path_is_missing z/g &&
446 test_must_fail git rev-parse HEAD:z/g
450 ###########################################################################
451 # Rules suggested by testcases in section 1:
453 # We should still detect the directory rename even if it wasn't just
454 # the directory renamed, but the files within it. (see 1b)
456 # If renames split a directory into two or more others, the directory
457 # with the most renames, "wins" (see 1c). However, see the testcases
458 # in section 2, plus testcases 3a and 4a.
459 ###########################################################################
462 ###########################################################################
463 # SECTION 2: Split into multiple directories, with equal number of paths
465 # Explore the splitting-a-directory rules a bit; what happens in the
468 # Note that there is a closely related case of a directory not being
469 # split on either side of history, but being renamed differently on
470 # each side. See testcase 8e for that.
471 ###########################################################################
473 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
476 # Commit B: z/{b,c,d}
477 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
479 test_create_repo
2a
&&
510 test_expect_success
'2a: Directory split into two on one side, with equal numbers of paths' '
517 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
518 test_i18ngrep "CONFLICT.*directory rename split" out &&
520 git ls-files -s >out &&
521 test_line_count = 3 out &&
522 git ls-files -u >out &&
523 test_line_count = 0 out &&
524 git ls-files -o >out &&
525 test_line_count = 1 out &&
527 git rev-parse >actual \
528 :0:y/b :0:w/c :0:z/d &&
529 git rev-parse >expect \
531 test_cmp expect actual
535 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
538 # Commit B: z/{b,c}, x/d
539 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
541 test_create_repo
2b
&&
573 test_expect_success
'2b: Directory split into two on one side, with equal numbers of paths' '
580 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
582 git ls-files -s >out &&
583 test_line_count = 3 out &&
584 git ls-files -u >out &&
585 test_line_count = 0 out &&
586 git ls-files -o >out &&
587 test_line_count = 1 out &&
589 git rev-parse >actual \
590 :0:y/b :0:w/c :0:x/d &&
591 git rev-parse >expect \
593 test_cmp expect actual &&
594 test_i18ngrep ! "CONFLICT.*directory rename split" out
598 ###########################################################################
599 # Rules suggested by section 2:
601 # None; the rule was already covered in section 1. These testcases are
602 # here just to make sure the conflict resolution and necessary warning
603 # messages are handled correctly.
604 ###########################################################################
607 ###########################################################################
608 # SECTION 3: Path in question is the source path for some rename already
610 # Combining cases from Section 1 and trying to handle them could lead to
611 # directory renaming detection being over-applied. So, this section
612 # provides some good testcases to check that the implementation doesn't go
614 ###########################################################################
616 # Testcase 3a, Avoid implicit rename if involved as source on other side
617 # (Related to testcases 1c, 1f, and 9h)
618 # Commit O: z/{b,c,d}
619 # Commit A: z/{b,c,d} (no change)
620 # Commit B: y/{b,c}, x/d
621 # Expected: y/{b,c}, x/d
623 test_create_repo
3a
&&
641 git commit
--allow-empty -m "A" &&
655 test_expect_success
'3a: Avoid implicit rename if involved as source on other side' '
662 git -c merge.directoryRenames=true merge -s recursive B^0 &&
664 git ls-files -s >out &&
665 test_line_count = 3 out &&
667 git rev-parse >actual \
668 HEAD:y/b HEAD:y/c HEAD:x/d &&
669 git rev-parse >expect \
671 test_cmp expect actual
675 # Testcase 3b, Avoid implicit rename if involved as source on other side
676 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
677 # Commit O: z/{b,c,d}
678 # Commit A: y/{b,c}, x/d
679 # Commit B: z/{b,c}, w/d
680 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
681 # NOTE: We're particularly checking that since z/d is already involved as
682 # a source in a file rename on the same side of history, that we don't
683 # get it involved in directory rename detection. If it were, we might
684 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
685 # rename/rename/rename(1to3) conflict, which is just weird.
687 test_create_repo
3b
&&
721 test_expect_success
'3b: Avoid implicit rename if involved as source on current side' '
728 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
729 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
730 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
732 git ls-files -s >out &&
733 test_line_count = 5 out &&
734 git ls-files -u >out &&
735 test_line_count = 3 out &&
736 git ls-files -o >out &&
737 test_line_count = 1 out &&
739 git rev-parse >actual \
740 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
741 git rev-parse >expect \
742 O:z/b O:z/c O:z/d O:z/d O:z/d &&
743 test_cmp expect actual &&
745 test_path_is_missing z/d &&
746 git hash-object >actual \
748 git rev-parse >expect \
750 test_cmp expect actual
754 ###########################################################################
755 # Rules suggested by section 3:
757 # Avoid directory-rename-detection for a path, if that path is the source
758 # of a rename on either side of a merge.
759 ###########################################################################
762 ###########################################################################
763 # SECTION 4: Partially renamed directory; still exists on both sides of merge
765 # What if we were to attempt to do directory rename detection when someone
766 # "mostly" moved a directory but still left some files around, or,
767 # equivalently, fully renamed a directory in one commit and then recreated
768 # that directory in a later commit adding some new files and then tried to
771 # It's hard to divine user intent in these cases, because you can make an
772 # argument that, depending on the intermediate history of the side being
773 # merged, that some users will want files in that directory to
774 # automatically be detected and renamed, while users with a different
775 # intermediate history wouldn't want that rename to happen.
777 # I think that it is best to simply not have directory rename detection
778 # apply to such cases. My reasoning for this is four-fold: (1) it's
779 # easiest for users in general to figure out what happened if we don't
780 # apply directory rename detection in any such case, (2) it's an easy rule
781 # to explain ["We don't do directory rename detection if the directory
782 # still exists on both sides of the merge"], (3) we can get some hairy
783 # edge/corner cases that would be really confusing and possibly not even
784 # representable in the index if we were to even try, and [related to 3] (4)
785 # attempting to resolve this issue of divining user intent by examining
786 # intermediate history goes against the spirit of three-way merges and is a
787 # path towards crazy corner cases that are far more complex than what we're
788 # already dealing with.
790 # Note that the wording of the rule ("We don't do directory rename
791 # detection if the directory still exists on both sides of the merge.")
792 # also excludes "renaming" of a directory into a subdirectory of itself
793 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
794 # out an exception for "renaming"-beneath-itself cases without opening
795 # weird edge/corner cases for other partial directory renames, but for now
796 # we are keeping the rule simple.
798 # This section contains a test for a partially-renamed-directory case.
799 ###########################################################################
801 # Testcase 4a, Directory split, with original directory still present
802 # (Related to testcase 1f)
803 # Commit O: z/{b,c,d,e}
804 # Commit A: y/{b,c,d}, z/e
805 # Commit B: z/{b,c,d,e,f}
806 # Expected: y/{b,c,d}, z/{e,f}
807 # NOTE: Even though most files from z moved to y, we don't want f to follow.
810 test_create_repo
4a
&&
843 test_expect_success
'4a: Directory split, with original directory still present' '
850 git -c merge.directoryRenames=true merge -s recursive B^0 &&
852 git ls-files -s >out &&
853 test_line_count = 5 out &&
854 git ls-files -u >out &&
855 test_line_count = 0 out &&
856 git ls-files -o >out &&
857 test_line_count = 1 out &&
859 git rev-parse >actual \
860 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
861 git rev-parse >expect \
862 O:z/b O:z/c O:z/d O:z/e B:z/f &&
863 test_cmp expect actual
867 ###########################################################################
868 # Rules suggested by section 4:
870 # Directory-rename-detection should be turned off for any directories (as
871 # a source for renames) that exist on both sides of the merge. (The "as
872 # a source for renames" clarification is due to cases like 1c where
873 # the target directory exists on both sides and we do want the rename
874 # detection.) But, sadly, see testcase 8b.
875 ###########################################################################
878 ###########################################################################
879 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
881 # Implicitly renaming files due to a detected directory rename could run
882 # into problems if there are files or directories in the way of the paths
883 # we want to rename. Explore such cases in this section.
884 ###########################################################################
886 # Testcase 5a, Merge directories, other side adds files to original and target
887 # Commit O: z/{b,c}, y/d
888 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
889 # Commit B: y/{b,c,d}
890 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
891 # NOTE: While directory rename detection is active here causing z/f to
892 # become y/f, we did not apply this for z/e_1 because that would
893 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
894 # this add/add, is that both versions of y/e are from the same side
895 # of history, giving us no way to represent this conflict in the
899 test_create_repo
5a
&&
920 git add z
/e z
/f y
/e
&&
933 test_expect_success
'5a: Merge directories, other side adds files to original and target' '
940 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
941 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
943 git ls-files -s >out &&
944 test_line_count = 6 out &&
945 git ls-files -u >out &&
946 test_line_count = 0 out &&
947 git ls-files -o >out &&
948 test_line_count = 1 out &&
950 git rev-parse >actual \
951 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
952 git rev-parse >expect \
953 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
954 test_cmp expect actual
958 # Testcase 5b, Rename/delete in order to get add/add/add conflict
959 # (Related to testcase 8d; these may appear slightly inconsistent to users;
960 # Also related to testcases 7d and 7e)
961 # Commit O: z/{b,c,d_1}
962 # Commit A: y/{b,c,d_2}
963 # Commit B: z/{b,c,d_1,e}, y/d_3
964 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
965 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
966 # we normally would since z/ is being renamed to y/, then this would be
967 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
968 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
969 # representable in the index, so the existence of y/d_3 needs to
970 # cause us to bail on directory rename detection for that path, falling
971 # back to git behavior without the directory rename detection.
974 test_create_repo
5b
&&
1008 test_expect_success
'5b: Rename/delete in order to get add/add/add conflict' '
1015 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1016 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1018 git ls-files -s >out &&
1019 test_line_count = 5 out &&
1020 git ls-files -u >out &&
1021 test_line_count = 2 out &&
1022 git ls-files -o >out &&
1023 test_line_count = 1 out &&
1025 git rev-parse >actual \
1026 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1027 git rev-parse >expect \
1028 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1029 test_cmp expect actual &&
1031 test_must_fail git rev-parse :1:y/d &&
1032 test_path_is_file y/d
1036 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1037 # (Directory rename detection would result in transitive rename vs.
1038 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1039 # rename paths conflict with separate adds on the other side)
1040 # (Related to testcases 3b and 7c)
1041 # Commit O: z/{b,c}, x/d_1
1042 # Commit A: y/{b,c,d_2}, w/d_1
1043 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1044 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1045 # presence of y/d_4 in B to avoid doing transitive rename of
1046 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1047 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1048 # though, because it doesn't have anything in the way.
1051 test_create_repo
5c
&&
1062 git commit
-m "O" &&
1074 git commit
-m "A" &&
1083 git add w
/ y
/ z
/e
&&
1089 test_expect_success
'5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1096 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1097 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1098 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1100 git ls-files -s >out &&
1101 test_line_count = 9 out &&
1102 git ls-files -u >out &&
1103 test_line_count = 6 out &&
1104 git ls-files -o >out &&
1105 test_line_count = 1 out &&
1107 git rev-parse >actual \
1108 :0:y/b :0:y/c :0:y/e &&
1109 git rev-parse >expect \
1110 O:z/b O:z/c B:z/e &&
1111 test_cmp expect actual &&
1113 test_must_fail git rev-parse :1:y/d &&
1114 git rev-parse >actual \
1115 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1116 git rev-parse >expect \
1117 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1118 test_cmp expect actual &&
1120 git hash-object >actual \
1122 git rev-parse >expect \
1124 test_cmp expect actual &&
1125 test_path_is_missing x/d &&
1126 test_path_is_file y/d &&
1127 grep -q "<<<<" y/d # conflict markers should be present
1131 # Testcase 5d, Directory/file/file conflict due to directory rename
1133 # Commit A: y/{b,c,d_1}
1134 # Commit B: z/{b,c,d_2,f}, y/d/e
1135 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1136 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1137 # detection for z/d_2, but that doesn't prevent us from applying the
1138 # directory rename detection for z/f -> y/f.
1141 test_create_repo
5d
&&
1150 git commit
-m "O" &&
1161 git commit
-m "A" &&
1168 git add y
/d
/e z
/d z
/f
&&
1174 test_expect_success
'5d: Directory/file/file conflict due to directory rename' '
1181 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1182 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1184 git ls-files -s >out &&
1185 test_line_count = 6 out &&
1186 git ls-files -u >out &&
1187 test_line_count = 1 out &&
1188 git ls-files -o >out &&
1189 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1191 test_line_count = 1 out &&
1193 git rev-parse >actual \
1194 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e
1196 test_line_count = 2 out &&
1198 git rev-parse >actual \
1199 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e
1201 git rev-parse >expect \
1202 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1203 test_cmp expect actual &&
1205 git hash-object y/d~HEAD >actual &&
1206 git rev-parse A:y/d >expect &&
1207 test_cmp expect actual
1211 ###########################################################################
1212 # Rules suggested by section 5:
1214 # If a subset of to-be-renamed files have a file or directory in the way,
1215 # "turn off" the directory rename for those specific sub-paths, falling
1216 # back to old handling. But, sadly, see testcases 8a and 8b.
1217 ###########################################################################
1220 ###########################################################################
1221 # SECTION 6: Same side of the merge was the one that did the rename
1223 # It may sound obvious that you only want to apply implicit directory
1224 # renames to directories if the _other_ side of history did the renaming.
1225 # If you did make an implementation that didn't explicitly enforce this
1226 # rule, the majority of cases that would fall under this section would
1227 # also be solved by following the rules from the above sections. But
1228 # there are still a few that stick out, so this section covers them just
1229 # to make sure we also get them right.
1230 ###########################################################################
1232 # Testcase 6a, Tricky rename/delete
1233 # Commit O: z/{b,c,d}
1235 # Commit B: y/{b,c}, z/d
1236 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1237 # Note: We're just checking here that the rename of z/b and z/c to put
1238 # them under y/ doesn't accidentally catch z/d and make it look like
1239 # it is also involved in a rename/delete conflict.
1242 test_create_repo
6a
&&
1252 git commit
-m "O" &&
1262 git commit
-m "A" &&
1273 test_expect_success
'6a: Tricky rename/delete' '
1280 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1281 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1283 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1285 git ls-files -s >out &&
1286 test_line_count = 3 out &&
1287 git ls-files -u >out &&
1288 test_line_count = 2 out &&
1289 git ls-files -o >out &&
1290 test_line_count = 1 out &&
1292 git rev-parse >actual \
1293 :0:y/b :1:y/c :3:y/c &&
1294 git rev-parse >expect \
1297 git ls-files -s >out &&
1298 test_line_count = 2 out &&
1299 git ls-files -u >out &&
1300 test_line_count = 1 out &&
1301 git ls-files -o >out &&
1302 test_line_count = 1 out &&
1304 git rev-parse >actual \
1306 git rev-parse >expect \
1309 test_cmp expect actual
1313 # Testcase 6b1, Same rename done on both sides
1314 # (Related to testcase 6b2 and 8e)
1315 # Commit O: z/{b,c,d,e}
1316 # Commit A: y/{b,c,d}, x/e
1317 # Commit B: y/{b,c,d}, z/{e,f}
1318 # Expected: y/{b,c,d,f}, x/e
1319 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1320 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1321 # should be moved to 'y/f'.
1323 # This is a bit of an edge case where any behavior might surprise users,
1324 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1325 # z/ -> x/, or treating A as not doing any directory rename. However, I
1326 # think this answer is the least confusing and most consistent with the
1329 # A note about z/ -> x/, since it may not be clear how that could come
1330 # about: If we were to ignore files renamed by both sides
1331 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1332 # at least git-2.28, then we would note there are no renames from z/ to
1333 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1334 # A renamed z/ -> x/. This seems more confusing for end users than a
1335 # rename of z/ to y/, it makes directory rename detection behavior
1336 # harder for them to predict. As such, we modified the rule, changed
1337 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1340 test_create_repo
6b1
&&
1351 git commit
-m "O" &&
1362 git commit
-m "A" &&
1375 test_expect_merge_algorithm failure success
'6b1: Same renames done on both sides, plus another rename' '
1382 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1384 git ls-files -s >out &&
1385 test_line_count = 5 out &&
1386 git ls-files -u >out &&
1387 test_line_count = 0 out &&
1388 git ls-files -o >out &&
1389 test_line_count = 1 out &&
1391 git rev-parse >actual \
1392 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1393 git rev-parse >expect \
1394 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1395 test_cmp expect actual
1399 # Testcase 6b2, Same rename done on both sides
1400 # (Related to testcases 6c and 8e)
1403 # Commit B: y/{b,c}, z/d
1404 # Expected: y/{b,c,d}
1405 # Alternate: y/{b,c}, z/d
1406 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1407 # file 'z/d' in B should be moved to 'y/d'.
1409 # We could potentially ignore the renames of z/{b,c} on side A since
1410 # those were renamed on both sides. However, it's a bit of a corner
1411 # case because what if there was also a z/e that side A moved to x/e
1412 # and side B left alone? If we used the "ignore renames done on both
1413 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1414 # z/d to x/d. That seems more surprising and uglier than allowing
1415 # the z/ -> y/ rename.
1418 test_create_repo
6b2
&&
1427 git commit
-m "O" &&
1436 git commit
-m "A" &&
1448 test_expect_merge_algorithm failure success
'6b2: Same rename done on both sides' '
1455 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1457 git ls-files -s >out &&
1458 test_line_count = 3 out &&
1459 git ls-files -u >out &&
1460 test_line_count = 0 out &&
1461 git ls-files -o >out &&
1462 test_line_count = 1 out &&
1464 git rev-parse >actual \
1465 HEAD:y/b HEAD:y/c HEAD:y/d &&
1466 git rev-parse >expect \
1467 O:z/b O:z/c B:z/d &&
1468 test_cmp expect actual
1472 # Testcase 6c, Rename only done on same side
1473 # (Related to testcases 6b1, 6b2, and 8e)
1475 # Commit A: z/{b,c} (no change)
1476 # Commit B: y/{b,c}, z/d
1477 # Expected: y/{b,c}, z/d
1478 # NOTE: Seems obvious, but just checking that the implementation doesn't
1479 # "accidentally detect a rename" and give us y/{b,c,d}.
1482 test_create_repo
6c
&&
1491 git commit
-m "O" &&
1499 git commit
--allow-empty -m "A" &&
1511 test_expect_success
'6c: Rename only done on same side' '
1518 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1520 git ls-files -s >out &&
1521 test_line_count = 3 out &&
1522 git ls-files -u >out &&
1523 test_line_count = 0 out &&
1524 git ls-files -o >out &&
1525 test_line_count = 1 out &&
1527 git rev-parse >actual \
1528 HEAD:y/b HEAD:y/c HEAD:z/d &&
1529 git rev-parse >expect \
1530 O:z/b O:z/c B:z/d &&
1531 test_cmp expect actual
1535 # Testcase 6d, We don't always want transitive renaming
1536 # (Related to testcase 1c)
1537 # Commit O: z/{b,c}, x/d
1538 # Commit A: z/{b,c}, x/d (no change)
1539 # Commit B: y/{b,c}, z/d
1540 # Expected: y/{b,c}, z/d
1541 # NOTE: Again, this seems obvious but just checking that the implementation
1542 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1545 test_create_repo
6d
&&
1556 git commit
-m "O" &&
1564 git commit
--allow-empty -m "A" &&
1574 test_expect_success
'6d: We do not always want transitive renaming' '
1581 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1583 git ls-files -s >out &&
1584 test_line_count = 3 out &&
1585 git ls-files -u >out &&
1586 test_line_count = 0 out &&
1587 git ls-files -o >out &&
1588 test_line_count = 1 out &&
1590 git rev-parse >actual \
1591 HEAD:y/b HEAD:y/c HEAD:z/d &&
1592 git rev-parse >expect \
1593 O:z/b O:z/c O:x/d &&
1594 test_cmp expect actual
1598 # Testcase 6e, Add/add from one-side
1600 # Commit A: z/{b,c} (no change)
1601 # Commit B: y/{b,c,d_1}, z/d_2
1602 # Expected: y/{b,c,d_1}, z/d_2
1603 # NOTE: Again, this seems obvious but just checking that the implementation
1604 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1605 # add/add conflict on y/d_1 vs y/d_2.
1608 test_create_repo
6e
&&
1617 git commit
-m "O" &&
1625 git commit
--allow-empty -m "A" &&
1638 test_expect_success
'6e: Add/add from one side' '
1645 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1647 git ls-files -s >out &&
1648 test_line_count = 4 out &&
1649 git ls-files -u >out &&
1650 test_line_count = 0 out &&
1651 git ls-files -o >out &&
1652 test_line_count = 1 out &&
1654 git rev-parse >actual \
1655 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1656 git rev-parse >expect \
1657 O:z/b O:z/c B:y/d B:z/d &&
1658 test_cmp expect actual
1662 ###########################################################################
1663 # Rules suggested by section 6:
1665 # Only apply implicit directory renames to directories if the other
1666 # side of history is the one doing the renaming.
1667 ###########################################################################
1670 ###########################################################################
1671 # SECTION 7: More involved Edge/Corner cases
1673 # The ruleset we have generated in the above sections seems to provide
1674 # well-defined merges. But can we find edge/corner cases that either (a)
1675 # are harder for users to understand, or (b) have a resolution that is
1676 # non-intuitive or suboptimal?
1678 # The testcases in this section dive into cases that I've tried to craft in
1679 # a way to find some that might be surprising to users or difficult for
1680 # them to understand (the next section will look at non-intuitive or
1681 # suboptimal merge results). Some of the testcases are similar to ones
1682 # from past sections, but have been simplified to try to highlight error
1683 # messages using a "modified" path (due to the directory rename). Are
1684 # users okay with these?
1686 # In my opinion, testcases that are difficult to understand from this
1687 # section is due to difficulty in the testcase rather than the directory
1688 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1689 # to the problem setup itself being complex). And I don't think the
1690 # error messages are a problem.
1692 # On the other hand, the testcases in section 8 worry me slightly more...
1693 ###########################################################################
1695 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1698 # Commit B: w/b, x/c, z/d
1699 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1700 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1703 test_create_repo
7a
&&
1712 git commit
-m "O" &&
1721 git commit
-m "A" &&
1735 test_expect_success
'7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1742 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1743 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1744 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1746 git ls-files -s >out &&
1747 test_line_count = 7 out &&
1748 git ls-files -u >out &&
1749 test_line_count = 6 out &&
1750 git ls-files -o >out &&
1751 test_line_count = 1 out &&
1753 git rev-parse >actual \
1754 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1755 git rev-parse >expect \
1756 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1757 test_cmp expect actual &&
1759 git hash-object >actual \
1761 git rev-parse >expect \
1762 O:z/b O:z/b O:z/c O:z/c &&
1763 test_cmp expect actual
1767 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1768 # (Related to testcase 1d)
1769 # Commit O: z/{b,c}, x/d_1, w/d_2
1770 # Commit A: y/{b,c,d_2}, x/d_1
1771 # Commit B: z/{b,c,d_1}, w/d_2
1772 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1775 test_create_repo
7b
&&
1788 git commit
-m "O" &&
1798 git commit
-m "A" &&
1808 test_expect_success
'7b: rename/rename(2to1), but only due to transitive rename' '
1815 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1816 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
1818 git ls-files -s >out &&
1819 test_line_count = 4 out &&
1820 git ls-files -u >out &&
1821 test_line_count = 2 out &&
1822 git ls-files -o >out &&
1823 test_line_count = 1 out &&
1825 git rev-parse >actual \
1826 :0:y/b :0:y/c :2:y/d :3:y/d &&
1827 git rev-parse >expect \
1828 O:z/b O:z/c O:w/d O:x/d &&
1829 test_cmp expect actual &&
1831 # Test that the two-way merge in y/d is as expected
1832 git cat-file -p :2:y/d >expect &&
1833 git cat-file -p :3:y/d >other &&
1835 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1837 test_must_fail git merge-file \
1843 test_must_fail git merge-file \
1853 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1854 # (Related to testcases 3b and 5c)
1855 # Commit O: z/{b,c}, x/d
1856 # Commit A: y/{b,c}, w/d
1857 # Commit B: z/{b,c,d}
1858 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1859 # NOTE: z/ was renamed to y/ so we do want to report
1860 # neither CONFLICT(x/d -> w/d vs. z/d)
1861 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1864 test_create_repo
7c
&&
1875 git commit
-m "O" &&
1885 git commit
-m "A" &&
1895 test_expect_success
'7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1902 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1903 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1905 git ls-files -s >out &&
1906 test_line_count = 5 out &&
1907 git ls-files -u >out &&
1908 test_line_count = 3 out &&
1909 git ls-files -o >out &&
1910 test_line_count = 1 out &&
1912 git rev-parse >actual \
1913 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1914 git rev-parse >expect \
1915 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1916 test_cmp expect actual
1920 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1921 # (Related somewhat to testcases 5b and 8d)
1922 # Commit O: z/{b,c}, x/d
1924 # Commit B: z/{b,c,d}
1925 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1926 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1929 test_create_repo
7d
&&
1940 git commit
-m "O" &&
1950 git commit
-m "A" &&
1960 test_expect_success
'7d: transitive rename involved in rename/delete; how is it reported?' '
1967 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1968 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1970 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1972 git ls-files -s >out &&
1973 test_line_count = 4 out &&
1974 git ls-files -u >out &&
1975 test_line_count = 2 out &&
1976 git ls-files -o >out &&
1977 test_line_count = 1 out &&
1979 git rev-parse >actual \
1980 :0:y/b :0:y/c :1:y/d :3:y/d &&
1981 git rev-parse >expect \
1982 O:z/b O:z/c O:x/d O:x/d
1984 git ls-files -s >out &&
1985 test_line_count = 3 out &&
1986 git ls-files -u >out &&
1987 test_line_count = 1 out &&
1988 git ls-files -o >out &&
1989 test_line_count = 1 out &&
1991 git rev-parse >actual \
1992 :0:y/b :0:y/c :3:y/d &&
1993 git rev-parse >expect \
1996 test_cmp expect actual
2000 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
2001 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
2002 # (Also related to testcases 9c and 9d)
2003 # Commit O: z/{b,c}, x/d_1
2004 # Commit A: y/{b,c,d/g}, x/d/f
2005 # Commit B: z/{b,c,d_1}
2006 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
2007 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
2009 # NOTE: The main path of interest here is d_1 and where it ends up, but
2010 # this is actually a case that has two potential directory renames
2011 # involved and D/F conflict(s), so it makes sense to walk through
2014 # Commit A renames z/ -> y/. Thus everything that B adds to z/
2015 # should be instead moved to y/. This gives us the D/F conflict on
2016 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
2018 # Further, commit B renames x/ -> z/, thus everything A adds to x/
2019 # should instead be moved to z/...BUT we removed z/ and renamed it
2020 # to y/, so maybe everything should move not from x/ to z/, but
2021 # from x/ to z/ to y/. Doing so might make sense from the logic so
2022 # far, but note that commit A had both an x/ and a y/; it did the
2023 # renaming of z/ to y/ and created x/d/f and it clearly made these
2024 # things separate, so it doesn't make much sense to push these
2025 # together. Doing so is what I'd call a doubly transitive rename;
2026 # see testcases 9c and 9d for further discussion of this issue and
2027 # how it's resolved.
2030 test_create_repo
7e
&&
2041 git commit
-m "O" &&
2054 git add x
/d
/f y
/d
/g
&&
2056 git commit
-m "A" &&
2066 test_expect_success
'7e: transitive rename in rename/delete AND dirs in the way' '
2073 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2074 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2076 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
2078 git ls-files -s >out &&
2079 test_line_count = 6 out &&
2080 git ls-files -u >out &&
2081 test_line_count = 2 out &&
2082 git ls-files -o >out &&
2083 test_line_count = 1 out &&
2085 git rev-parse >actual \
2086 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
2087 git rev-parse >expect \
2088 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d
2090 git ls-files -s >out &&
2091 test_line_count = 5 out &&
2092 git ls-files -u >out &&
2093 test_line_count = 1 out &&
2094 git ls-files -o >out &&
2095 test_line_count = 2 out &&
2097 git rev-parse >actual \
2098 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2099 git rev-parse >expect \
2100 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d
2102 test_cmp expect actual &&
2104 git hash-object y/d~B^0 >actual &&
2105 git rev-parse O:x/d >expect &&
2106 test_cmp expect actual
2110 ###########################################################################
2111 # SECTION 8: Suboptimal merges
2113 # As alluded to in the last section, the ruleset we have built up for
2114 # detecting directory renames unfortunately has some special cases where it
2115 # results in slightly suboptimal or non-intuitive behavior. This section
2116 # explores these cases.
2118 # To be fair, we already had non-intuitive or suboptimal behavior for most
2119 # of these cases in git before introducing implicit directory rename
2120 # detection, but it'd be nice if there was a modified ruleset out there
2121 # that handled these cases a bit better.
2122 ###########################################################################
2124 # Testcase 8a, Dual-directory rename, one into the others' way
2125 # Commit O. x/{a,b}, y/{c,d}
2126 # Commit A. x/{a,b,e}, y/{c,d,f}
2127 # Commit B. y/{a,b}, z/{c,d}
2129 # Possible Resolutions:
2130 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2131 # Currently expected: y/{a,b,e,f}, z/{c,d}
2132 # Optimal: y/{a,b,e}, z/{c,d,f}
2134 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2135 # better with directory rename detection than git did without, but the
2136 # simple rule from section 5 prevents me from handling this as optimally as
2137 # we potentially could.
2140 test_create_repo
8a
&&
2152 git commit
-m "O" &&
2163 git commit
-m "A" &&
2173 test_expect_success
'8a: Dual-directory rename, one into the others way' '
2180 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2182 git ls-files -s >out &&
2183 test_line_count = 6 out &&
2184 git ls-files -u >out &&
2185 test_line_count = 0 out &&
2186 git ls-files -o >out &&
2187 test_line_count = 1 out &&
2189 git rev-parse >actual \
2190 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2191 git rev-parse >expect \
2192 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2193 test_cmp expect actual
2197 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2198 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2199 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2200 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2202 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2203 # Currently expected: <same>
2204 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2205 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2207 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2208 # y, both are named 'e'. Without directory rename detection, neither file
2209 # moves directories. Implement directory rename detection suboptimally, and
2210 # you get an add/add conflict, but both files were added in commit A, so this
2211 # is an add/add conflict where one side of history added both files --
2212 # something we can't represent in the index. Obviously, we'd prefer the last
2213 # resolution, but our previous rules are too coarse to allow it. Using both
2214 # the rules from section 4 and section 5 save us from the Scary resolution,
2215 # making us fall back to pre-directory-rename-detection behavior for both
2219 test_create_repo
8b
&&
2231 git commit
-m "O" &&
2242 git commit
-m "A" &&
2252 test_expect_success
'8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2259 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2261 git ls-files -s >out &&
2262 test_line_count = 6 out &&
2263 git ls-files -u >out &&
2264 test_line_count = 0 out &&
2265 git ls-files -o >out &&
2266 test_line_count = 1 out &&
2268 git rev-parse >actual \
2269 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2270 git rev-parse >expect \
2271 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2272 test_cmp expect actual
2276 # Testcase 8c, modify/delete or rename+modify/delete?
2277 # (Related to testcases 5b, 8d, and 9h)
2278 # Commit O: z/{b,c,d}
2280 # Commit B: z/{b,c,d_modified,e}
2281 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2283 # Note: It could easily be argued that the correct resolution here is
2284 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2285 # and that the modified version of d should be present in y/ after
2286 # the merge, just marked as conflicted. Indeed, I previously did
2287 # argue that. But applying directory renames to the side of
2288 # history where a file is merely modified results in spurious
2289 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2293 test_create_repo
8c
&&
2300 test_seq
1 10 >z
/d
&&
2303 git commit
-m "O" &&
2313 git commit
-m "A" &&
2317 test_chmod
+x z
/d
&&
2325 test_expect_success
'8c: modify/delete or rename+modify/delete' '
2332 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2333 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2335 git ls-files -s >out &&
2336 test_line_count = 5 out &&
2337 git ls-files -u >out &&
2338 test_line_count = 2 out &&
2339 git ls-files -o >out &&
2340 test_line_count = 1 out &&
2342 git rev-parse >actual \
2343 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2344 git rev-parse >expect \
2345 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2346 test_cmp expect actual &&
2348 test_must_fail git rev-parse :2:z/d &&
2349 git ls-files -s z/d | grep ^100755 &&
2350 test_path_is_file z/d &&
2351 test_path_is_missing y/d
2355 # Testcase 8d, rename/delete...or not?
2356 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2357 # Also related to testcases 7d and 7e)
2358 # Commit O: z/{b,c,d}
2360 # Commit B: z/{b,c,d,e}
2361 # Expected: y/{b,c,e}
2363 # Note: It would also be somewhat reasonable to resolve this as
2364 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2366 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2367 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2368 # delete) are both coming from commit A, which is illogical. Conflicts
2369 # during merging are supposed to be about opposite sides doing things
2373 test_create_repo
8d
&&
2380 test_seq
1 10 >z
/d
&&
2383 git commit
-m "O" &&
2393 git commit
-m "A" &&
2403 test_expect_success
'8d: rename/delete...or not?' '
2410 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2412 git ls-files -s >out &&
2413 test_line_count = 3 out &&
2415 git rev-parse >actual \
2416 HEAD:y/b HEAD:y/c HEAD:y/e &&
2417 git rev-parse >expect \
2418 O:z/b O:z/c B:z/e &&
2419 test_cmp expect actual
2423 # Testcase 8e, Both sides rename, one side adds to original directory
2426 # Commit B: w/{b,c}, z/d
2428 # Possible Resolutions:
2429 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2430 # CONFLICT(z/c -> y/c vs. w/c)
2431 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2432 # CONFLICT(z/c -> y/c vs. w/c)
2435 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2436 # did NOT get renamed; the directory is still present; instead it is
2437 # considered to have just renamed a subset of paths in directory z
2438 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2439 # the original paths out of z/ but opted to keep d within z/).
2441 # It was not clear in the past what should be done with this testcase;
2442 # in fact, I noted that I "just picked one" previously. However,
2443 # following the new logic for testcase 6b2, we should take the rename
2444 # and move z/d to y/d.
2446 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2447 # whether they are optimal for end users, but (a) the default for
2448 # directory rename detection is to mark these all as conflicts
2449 # anyway, (b) it feels like this is less prone to higher order corner
2450 # case confusion, and (c) the current algorithm requires less global
2451 # knowledge (i.e. less coupling in the algorithm between renames done
2452 # on both sides) which thus means users are better able to predict
2453 # the behavior, and predict it without computing as many details.
2456 test_create_repo
8e
&&
2465 git commit
-m "O" &&
2474 git commit
-m "A" &&
2486 test_expect_success
'8e: Both sides rename, one side adds to original directory' '
2493 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2494 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2495 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2497 git ls-files -s >out &&
2498 test_line_count = 7 out &&
2499 git ls-files -u >out &&
2500 test_line_count = 6 out &&
2501 git ls-files -o >out &&
2502 test_line_count = 2 out &&
2504 git rev-parse >actual \
2505 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2506 git rev-parse >expect \
2507 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2508 test_cmp expect actual &&
2510 git hash-object >actual \
2512 git rev-parse >expect \
2513 O:z/b O:z/b O:z/c O:z/c &&
2514 test_cmp expect actual &&
2516 test_path_is_missing z/b &&
2517 test_path_is_missing z/c
2521 ###########################################################################
2522 # SECTION 9: Other testcases
2524 # This section consists of miscellaneous testcases I thought of during
2525 # the implementation which round out the testing.
2526 ###########################################################################
2528 # Testcase 9a, Inner renamed directory within outer renamed directory
2529 # (Related to testcase 1f)
2530 # Commit O: z/{b,c,d/{e,f,g}}
2531 # Commit A: y/{b,c}, x/w/{e,f,g}
2532 # Commit B: z/{b,c,d/{e,f,g,h},i}
2533 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2534 # NOTE: The only reason this one is interesting is because when a directory
2535 # is split into multiple other directories, we determine by the weight
2536 # of which one had the most paths going to it. A naive implementation
2537 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2540 test_create_repo
9a
&&
2552 git commit
-m "O" &&
2563 git commit
-m "A" &&
2574 test_expect_success
'9a: Inner renamed directory within outer renamed directory' '
2581 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2583 git ls-files -s >out &&
2584 test_line_count = 7 out &&
2585 git ls-files -u >out &&
2586 test_line_count = 0 out &&
2587 git ls-files -o >out &&
2588 test_line_count = 1 out &&
2590 git rev-parse >actual \
2591 HEAD:y/b HEAD:y/c HEAD:y/i &&
2592 git rev-parse >expect \
2593 O:z/b O:z/c B:z/i &&
2594 test_cmp expect actual &&
2596 git rev-parse >actual \
2597 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2598 git rev-parse >expect \
2599 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2600 test_cmp expect actual
2604 # Testcase 9b, Transitive rename with content merge
2605 # (Related to testcase 1c)
2606 # Commit O: z/{b,c}, x/d_1
2607 # Commit A: y/{b,c}, x/d_2
2608 # Commit B: z/{b,c,d_3}
2609 # Expected: y/{b,c,d_merged}
2612 test_create_repo
9b
&&
2620 test_seq
1 10 >x
/d
&&
2623 git commit
-m "O" &&
2631 test_seq
1 11 >x
/d
&&
2634 git commit
-m "A" &&
2637 test_seq
0 10 >x
/d
&&
2645 test_expect_success
'9b: Transitive rename with content merge' '
2652 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2654 git ls-files -s >out &&
2655 test_line_count = 3 out &&
2657 test_seq 0 11 >expected &&
2658 test_cmp expected y/d &&
2660 git rev-parse >actual \
2661 HEAD:y/b HEAD:y/c HEAD:y/d &&
2662 git rev-parse >expect \
2663 O:z/b O:z/c :0:expected &&
2664 test_cmp expect actual &&
2665 test_must_fail git rev-parse HEAD:x/d &&
2666 test_must_fail git rev-parse HEAD:z/d &&
2667 test_path_is_missing z/d &&
2669 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2670 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2671 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2675 # Testcase 9c, Doubly transitive rename?
2676 # (Related to testcase 1c, 7e, and 9d)
2677 # Commit O: z/{b,c}, x/{d,e}, w/f
2678 # Commit A: y/{b,c}, x/{d,e,f,g}
2679 # Commit B: z/{b,c,d,e}, w/f
2680 # Expected: y/{b,c,d,e}, x/{f,g}
2682 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2683 # x/f is clear. Let's look beyond that. Here's the logic:
2684 # Commit B renamed x/ -> z/
2685 # Commit A renamed z/ -> y/
2686 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2687 # transient rename. However, where does it end? We can chain these
2688 # indefinitely (see testcase 9d). What if there is a D/F conflict
2689 # at z/f/ or y/f/? Or just another file conflict at one of those
2690 # paths? In the case of an N-long chain of transient renamings,
2691 # where do we "abort" the rename at? Can the user make sense of
2692 # the resulting conflict and resolve it?
2694 # To avoid this confusion I use the simple rule that if the other side
2695 # of history did a directory rename to a path that your side renamed
2696 # away, then ignore that particular rename from the other side of
2697 # history for any implicit directory renames.
2700 test_create_repo
9c
&&
2714 git commit
-m "O" &&
2726 git commit
-m "A" &&
2736 test_expect_success
'9c: Doubly transitive rename?' '
2743 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2744 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2746 git ls-files -s >out &&
2747 test_line_count = 6 out &&
2748 git ls-files -o >out &&
2749 test_line_count = 1 out &&
2751 git rev-parse >actual \
2752 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2753 git rev-parse >expect \
2754 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2755 test_cmp expect actual
2759 # Testcase 9d, N-fold transitive rename?
2760 # (Related to testcase 9c...and 1c and 7e)
2761 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2762 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2763 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2764 # Expected: <see NOTE first>
2766 # NOTE: z/ -> y/ (in commit A)
2767 # y/ -> x/ (in commit B)
2768 # x/ -> w/ (in commit A)
2769 # w/ -> v/ (in commit B)
2770 # v/ -> u/ (in commit A)
2771 # So, if we add a file to z, say z/t, where should it end up? In u?
2772 # What if there's another file or directory named 't' in one of the
2773 # intervening directories and/or in u itself? Also, shouldn't the
2774 # same logic that places 't' in u/ also move ALL other files to u/?
2775 # What if there are file or directory conflicts in any of them? If
2776 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2777 # like this, would the user have any hope of understanding any
2778 # conflicts or how their working tree ended up? I think not, so I'm
2779 # ruling out N-ary transitive renames for N>1.
2781 # Therefore our expected result is:
2782 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2783 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2784 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2785 # simple rules that are consistent with what we need for all the other
2786 # testcases and simplifies things for the user.
2789 test_create_repo
9d
&&
2793 mkdir z y x w v u
&&
2800 git add z y x w v u
&&
2802 git commit
-m "O" &&
2813 git commit
-m "A" &&
2825 test_expect_success
'9d: N-way transitive rename?' '
2832 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2833 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2834 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2835 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2836 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2838 git ls-files -s >out &&
2839 test_line_count = 7 out &&
2840 git ls-files -o >out &&
2841 test_line_count = 1 out &&
2843 git rev-parse >actual \
2845 HEAD:y/a HEAD:x/b HEAD:w/c \
2846 HEAD:u/d HEAD:u/e HEAD:u/f &&
2847 git rev-parse >expect \
2850 O:w/d O:v/e A:u/f &&
2851 test_cmp expect actual
2855 # Testcase 9e, N-to-1 whammo
2856 # (Related to testcase 9c...and 1c and 7e)
2857 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2858 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2859 # Commit B: combined/{a,b,d,e,g,h,j,k}
2860 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2861 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2864 test_create_repo
9e
&&
2868 mkdir dir1 dir2 dir3 dirN
&&
2879 git commit
-m "O" &&
2896 git commit
-m "A" &&
2899 git
mv dir1 combined
&&
2900 git
mv dir
2/* combined
/ &&
2901 git
mv dir
3/* combined
/ &&
2902 git
mv dirN
/* combined
/ &&
2908 test_expect_success C_LOCALE_OUTPUT
'9e: N-to-1 whammo' '
2915 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2916 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2917 grep -q dir1/yo error_line &&
2918 grep -q dir2/yo error_line &&
2919 grep -q dir3/yo error_line &&
2920 grep -q dirN/yo error_line &&
2922 git ls-files -s >out &&
2923 test_line_count = 16 out &&
2924 git ls-files -u >out &&
2925 test_line_count = 0 out &&
2926 git ls-files -o >out &&
2927 test_line_count = 2 out &&
2929 git rev-parse >actual \
2930 :0:combined/a :0:combined/b :0:combined/c \
2931 :0:combined/d :0:combined/e :0:combined/f \
2932 :0:combined/g :0:combined/h :0:combined/i \
2933 :0:combined/j :0:combined/k :0:combined/l &&
2934 git rev-parse >expect \
2935 O:dir1/a O:dir1/b A:dir1/c \
2936 O:dir2/d O:dir2/e A:dir2/f \
2937 O:dir3/g O:dir3/h A:dir3/i \
2938 O:dirN/j O:dirN/k A:dirN/l &&
2939 test_cmp expect actual &&
2941 git rev-parse >actual \
2942 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2943 git rev-parse >expect \
2944 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2945 test_cmp expect actual
2949 # Testcase 9f, Renamed directory that only contained immediate subdirs
2950 # (Related to testcases 1e & 9g)
2951 # Commit O: goal/{a,b}/$more_files
2952 # Commit A: priority/{a,b}/$more_files
2953 # Commit B: goal/{a,b}/$more_files, goal/c
2954 # Expected: priority/{a,b}/$more_files, priority/c
2957 test_create_repo
9f
&&
2963 echo foo
>goal
/a
/foo
&&
2964 echo bar
>goal
/b
/bar
&&
2965 echo baz
>goal
/b
/baz
&&
2968 git commit
-m "O" &&
2975 git
mv goal
/ priority
&&
2977 git commit
-m "A" &&
2987 test_expect_success
'9f: Renamed directory that only contained immediate subdirs' '
2994 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2996 git ls-files -s >out &&
2997 test_line_count = 4 out &&
2999 git rev-parse >actual \
3000 HEAD:priority/a/foo \
3001 HEAD:priority/b/bar \
3002 HEAD:priority/b/baz \
3004 git rev-parse >expect \
3009 test_cmp expect actual &&
3010 test_must_fail git rev-parse HEAD:goal/c
3014 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
3015 # (Related to testcases 1e & 9f)
3016 # Commit O: goal/{a,b}/$more_files
3017 # Commit A: priority/{alpha,bravo}/$more_files
3018 # Commit B: goal/{a,b}/$more_files, goal/c
3019 # Expected: priority/{alpha,bravo}/$more_files, priority/c
3020 # We currently fail this test because the directory renames we detect are
3021 # goal/a/ -> priority/alpha/
3022 # goal/b/ -> priority/bravo/
3024 # goal/ -> priority/
3025 # because of no files found within goal/, and the fact that "a" != "alpha"
3026 # and "b" != "bravo". But I'm not sure it's really a failure given that
3030 test_create_repo
9g
&&
3036 echo foo
>goal
/a
/foo
&&
3037 echo bar
>goal
/b
/bar
&&
3038 echo baz
>goal
/b
/baz
&&
3041 git commit
-m "O" &&
3049 git
mv goal
/a
/ priority
/alpha
&&
3050 git
mv goal
/b
/ priority
/beta
&&
3053 git commit
-m "A" &&
3063 test_expect_failure
'9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
3070 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3072 git ls-files -s >out &&
3073 test_line_count = 4 out &&
3075 git rev-parse >actual \
3076 HEAD:priority/alpha/foo \
3077 HEAD:priority/beta/bar \
3078 HEAD:priority/beta/baz \
3080 git rev-parse >expect \
3085 test_cmp expect actual &&
3086 test_must_fail git rev-parse HEAD:goal/c
3090 # Testcase 9h, Avoid implicit rename if involved as source on other side
3091 # (Extremely closely related to testcase 3a)
3092 # Commit O: z/{b,c,d_1}
3093 # Commit A: z/{b,c,d_2}
3094 # Commit B: y/{b,c}, x/d_1
3095 # Expected: y/{b,c}, x/d_2
3096 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3097 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3099 test_create_repo
9h
&&
3106 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z
/d
&&
3109 git commit
-m "O" &&
3119 git commit
-m "A" &&
3133 test_expect_success
'9h: Avoid dir rename on merely modified path' '
3140 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3142 git ls-files -s >out &&
3143 test_line_count = 3 out &&
3145 git rev-parse >actual \
3146 HEAD:y/b HEAD:y/c HEAD:x/d &&
3147 git rev-parse >expect \
3148 O:z/b O:z/c A:z/d &&
3149 test_cmp expect actual
3153 ###########################################################################
3154 # Rules suggested by section 9:
3156 # If the other side of history did a directory rename to a path that your
3157 # side renamed away, then ignore that particular rename from the other
3158 # side of history for any implicit directory renames.
3159 ###########################################################################
3161 ###########################################################################
3162 # SECTION 10: Handling untracked files
3164 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3165 # the operation if untracked or dirty files would be deleted or overwritten
3166 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3167 # and if it doesn't abort, then it muddies up the working directory before
3168 # we even get to the point of detecting renames, so we need some special
3169 # handling, at least in the case of directory renames.
3170 ###########################################################################
3172 # Testcase 10a, Overwrite untracked: normal rename/delete
3173 # Commit O: z/{b,c_1}
3174 # Commit A: z/b + untracked z/c + untracked z/d
3175 # Commit B: z/{b,d_1}
3176 # Expected: Aborted Merge +
3177 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3180 test_create_repo
10a
&&
3189 git commit
-m "O" &&
3198 git commit
-m "A" &&
3207 test_expect_success
'10a: Overwrite untracked with normal rename/delete' '
3214 echo important >z/d &&
3216 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3217 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3219 git ls-files -s >out &&
3220 test_line_count = 1 out &&
3221 git ls-files -o >out &&
3222 test_line_count = 4 out &&
3224 echo very >expect &&
3225 test_cmp expect z/c &&
3227 echo important >expect &&
3228 test_cmp expect z/d &&
3230 git rev-parse HEAD:z/b >actual &&
3231 git rev-parse O:z/b >expect &&
3232 test_cmp expect actual
3236 # Testcase 10b, Overwrite untracked: dir rename + delete
3237 # Commit O: z/{b,c_1}
3238 # Commit A: y/b + untracked y/{c,d,e}
3239 # Commit B: z/{b,d_1,e}
3240 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3241 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3242 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3245 test_create_repo
10b
&&
3254 git commit
-m "O" &&
3264 git commit
-m "A" &&
3275 test_expect_success
'10b: Overwrite untracked with dir rename + delete' '
3282 echo important >y/d &&
3283 echo contents >y/e &&
3285 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3286 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3287 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3289 git ls-files -s >out &&
3290 test_line_count = 3 out &&
3291 git ls-files -u >out &&
3292 test_line_count = 2 out &&
3293 git ls-files -o >out &&
3294 test_line_count = 5 out &&
3296 git rev-parse >actual \
3297 :0:y/b :3:y/d :3:y/e &&
3298 git rev-parse >expect \
3299 O:z/b O:z/c B:z/e &&
3300 test_cmp expect actual &&
3302 echo very >expect &&
3303 test_cmp expect y/c &&
3305 echo important >expect &&
3306 test_cmp expect y/d &&
3308 echo contents >expect &&
3313 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3314 # Commit O: z/{a,b}, x/{c,d}
3315 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3316 # Commit B: z/{a,b,c}, x/d
3317 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3318 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3320 # ERROR_MSG(Refusing to lose untracked file at y/c)
3323 test_create_repo
10c_
$1 &&
3334 git commit
-m "O" &&
3345 git commit
-m "A" &&
3354 test_expect_success
'10c1: Overwrite untracked with dir rename/rename(1to2)' '
3360 echo important >y/c &&
3362 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3363 test_i18ngrep "CONFLICT (rename/rename)" out &&
3364 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3366 git ls-files -s >out &&
3367 test_line_count = 6 out &&
3368 git ls-files -u >out &&
3369 test_line_count = 3 out &&
3370 git ls-files -o >out &&
3371 test_line_count = 3 out &&
3373 git rev-parse >actual \
3374 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3375 git rev-parse >expect \
3376 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3377 test_cmp expect actual &&
3379 git hash-object y/c~B^0 >actual &&
3380 git rev-parse O:x/c >expect &&
3381 test_cmp expect actual &&
3383 echo important >expect &&
3388 test_expect_success
'10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3398 echo important >y/c &&
3400 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3401 test_i18ngrep "CONFLICT (rename/rename)" out &&
3402 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3404 git ls-files -s >out &&
3405 test_line_count = 6 out &&
3406 git ls-files -u >out &&
3407 test_line_count = 3 out &&
3408 git ls-files -o >out &&
3409 test_line_count = 3 out &&
3411 git rev-parse >actual \
3412 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3413 git rev-parse >expect \
3414 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3415 test_cmp expect actual &&
3417 git hash-object y/c~HEAD >actual &&
3418 git rev-parse O:x/c >expect &&
3419 test_cmp expect actual &&
3421 echo important >expect &&
3426 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3427 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3428 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3429 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3430 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3431 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3432 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3435 test_create_repo
10d
&&
3448 git commit
-m "O" &&
3455 git
mv z
/c x
/wham
&&
3458 git commit
-m "A" &&
3461 git
mv x
/f z
/wham
&&
3468 test_expect_success
'10d: Delete untracked with dir rename/rename(2to1)' '
3474 echo important >y/wham &&
3476 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3477 test_i18ngrep "CONFLICT (rename/rename)" out &&
3478 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3480 git ls-files -s >out &&
3481 test_line_count = 6 out &&
3482 git ls-files -u >out &&
3483 test_line_count = 2 out &&
3484 git ls-files -o >out &&
3485 test_line_count = 3 out &&
3487 git rev-parse >actual \
3488 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3489 git rev-parse >expect \
3490 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3491 test_cmp expect actual &&
3493 test_must_fail git rev-parse :1:y/wham &&
3495 echo important >expect &&
3496 test_cmp expect y/wham &&
3498 # Test that the two-way merge in y/wham~merged is as expected
3499 git cat-file -p :2:y/wham >expect &&
3500 git cat-file -p :3:y/wham >other &&
3502 test_must_fail git merge-file \
3506 expect empty other &&
3507 test_cmp expect y/wham~merged
3511 # Testcase 10e, Does git complain about untracked file that's not in the way?
3513 # Commit A: y/{a,b} + untracked z/c
3514 # Commit B: z/{a,b,c}
3515 # Expected: y/{a,b,c} + untracked z/c
3518 test_create_repo
10e
&&
3527 git commit
-m "O" &&
3536 git commit
-m "A" &&
3546 test_expect_merge_algorithm failure success
'10e: Does git complain about untracked file that is not really in the way?' '
3555 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3556 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3558 git ls-files -s >out &&
3559 test_line_count = 3 out &&
3560 git ls-files -u >out &&
3561 test_line_count = 0 out &&
3562 git ls-files -o >out &&
3563 test_line_count = 3 out &&
3565 git rev-parse >actual \
3566 :0:y/a :0:y/b :0:y/c &&
3567 git rev-parse >expect \
3568 O:z/a O:z/b B:z/c &&
3569 test_cmp expect actual &&
3571 echo random >expect &&
3576 ###########################################################################
3577 # SECTION 11: Handling dirty (not up-to-date) files
3579 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3580 # the operation if untracked or dirty files would be deleted or overwritten
3581 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3582 # and if it doesn't abort, then it muddies up the working directory before
3583 # we even get to the point of detecting renames, so we need some special
3584 # handling. This was true even of normal renames, but there are additional
3585 # codepaths that need special handling with directory renames. Add
3586 # testcases for both renamed-by-directory-rename-detection and standard
3588 ###########################################################################
3590 # Testcase 11a, Avoid losing dirty contents with simple rename
3591 # Commit O: z/{a,b_v1},
3592 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3593 # Commit B: z/{a,b_v2}
3594 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3595 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3596 # z/c~HEAD with contents of B:z/b_v2,
3597 # z/c with uncommitted mods on top of A:z/c_v1
3600 test_create_repo
11a
&&
3606 test_seq
1 10 >z
/b
&&
3609 git commit
-m "O" &&
3618 git commit
-m "A" &&
3628 test_expect_success
'11a: Avoid losing dirty contents with simple rename' '
3636 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3637 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3639 test_seq 1 10 >expected &&
3640 echo stuff >>expected &&
3641 test_cmp expected z/c &&
3643 git ls-files -s >out &&
3644 test_line_count = 2 out &&
3645 git ls-files -u >out &&
3646 test_line_count = 1 out &&
3647 git ls-files -o >out &&
3648 test_line_count = 4 out &&
3650 git rev-parse >actual \
3652 git rev-parse >expect \
3654 test_cmp expect actual &&
3656 git hash-object z/c~HEAD >actual &&
3657 git rev-parse B:z/b >expect &&
3658 test_cmp expect actual
3662 # Testcase 11b, Avoid losing dirty file involved in directory rename
3663 # Commit O: z/a, x/{b,c_v1}
3664 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3665 # Commit B: y/a, x/{b,c_v2}
3666 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3667 # ERROR_MSG(Refusing to lose dirty file at z/c)
3671 test_create_repo
11b
&&
3678 test_seq
1 10 >x
/c
&&
3681 git commit
-m "O" &&
3690 git commit
-m "A" &&
3701 test_expect_success
'11b: Avoid losing dirty file involved in directory rename' '
3709 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3710 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3712 grep -q stuff z/c &&
3713 test_seq 1 10 >expected &&
3714 echo stuff >>expected &&
3715 test_cmp expected z/c &&
3717 git ls-files -s >out &&
3718 test_line_count = 3 out &&
3719 git ls-files -u >out &&
3720 test_line_count = 0 out &&
3721 git ls-files -m >out &&
3722 test_line_count = 0 out &&
3723 git ls-files -o >out &&
3724 test_line_count = 4 out &&
3726 git rev-parse >actual \
3727 :0:x/b :0:y/a :0:y/c &&
3728 git rev-parse >expect \
3729 O:x/b O:z/a B:x/c &&
3730 test_cmp expect actual &&
3732 git hash-object y/c >actual &&
3733 git rev-parse B:x/c >expect &&
3734 test_cmp expect actual
3738 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3739 # Commit O: y/a, x/{b,c_v1}
3740 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3741 # Commit B: y/{a,c/d}, x/{b,c_v2}
3742 # Expected: Abort_msg("following files would be overwritten by merge") +
3743 # y/c left untouched (still has uncommitted mods)
3746 test_create_repo
11c
&&
3753 test_seq
1 10 >x
/c
&&
3756 git commit
-m "O" &&
3765 git commit
-m "A" &&
3771 git add x
/c y
/c
/d
&&
3777 test_expect_success
'11c: Avoid losing not-uptodate with rename + D/F conflict' '
3785 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3786 test_i18ngrep "following files would be overwritten by merge" err &&
3788 grep -q stuff y/c &&
3789 test_seq 1 10 >expected &&
3790 echo stuff >>expected &&
3791 test_cmp expected y/c &&
3793 git ls-files -s >out &&
3794 test_line_count = 3 out &&
3795 git ls-files -u >out &&
3796 test_line_count = 0 out &&
3797 git ls-files -m >out &&
3798 test_line_count = 1 out &&
3799 git ls-files -o >out &&
3800 test_line_count = 3 out
3804 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3805 # Commit O: z/a, x/{b,c_v1}
3806 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3807 # Commit B: y/{a,c/d}, x/{b,c_v2}
3808 # Expected: D/F: y/c_v2 vs y/c/d) +
3809 # Warning_Msg("Refusing to lose dirty file at z/c) +
3810 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3813 test_create_repo
11d
&&
3820 test_seq
1 10 >x
/c
&&
3823 git commit
-m "O" &&
3832 git commit
-m "A" &&
3839 git add x
/c y
/c
/d
&&
3845 test_expect_success
'11d: Avoid losing not-uptodate with rename + D/F conflict' '
3853 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3854 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3856 grep -q stuff z/c &&
3857 test_seq 1 10 >expected &&
3858 echo stuff >>expected &&
3859 test_cmp expected z/c &&
3861 git ls-files -s >out &&
3862 test_line_count = 4 out &&
3863 git ls-files -u >out &&
3864 test_line_count = 1 out &&
3865 git ls-files -o >out &&
3866 test_line_count = 5 out &&
3868 git rev-parse >actual \
3869 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3870 git rev-parse >expect \
3871 O:x/b O:z/a B:y/c/d B:x/c &&
3872 test_cmp expect actual &&
3874 git hash-object y/c~HEAD >actual &&
3875 git rev-parse B:x/c >expect &&
3876 test_cmp expect actual
3880 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3881 # Commit O: z/{a,b}, x/{c_1,d}
3882 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3883 # Commit B: z/{a,b,c_1}, x/d
3884 # Expected: Failed Merge; y/{a,b} + x/d +
3885 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3886 # ERROR_MSG(Refusing to lose dirty file at y/c)
3887 # y/c~B^0 has O:x/c_1 contents
3888 # y/c~HEAD has A:y/c_2 contents
3889 # y/c has dirty file from before merge
3892 test_create_repo
11e
&&
3903 git commit
-m "O" &&
3911 echo different
>y
/c
&&
3916 git commit
-m "A" &&
3925 test_expect_success
'11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3933 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3934 test_i18ngrep "CONFLICT (rename/rename)" out &&
3935 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3937 git ls-files -s >out &&
3938 test_line_count = 7 out &&
3939 git ls-files -u >out &&
3940 test_line_count = 4 out &&
3941 git ls-files -o >out &&
3942 test_line_count = 3 out &&
3944 echo different >expected &&
3945 echo mods >>expected &&
3946 test_cmp expected y/c &&
3948 git rev-parse >actual \
3949 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3950 git rev-parse >expect \
3951 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3952 test_cmp expect actual &&
3954 # See if y/c~merged has expected contents; requires manually
3955 # doing the expected file merge
3956 git cat-file -p A:y/c >c1 &&
3957 git cat-file -p B:z/c >c2 &&
3959 test_must_fail git merge-file \
3964 test_cmp c1 y/c~merged
3968 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3969 # Commit O: z/{a,b}, x/{c_1,d_2}
3970 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3971 # Commit B: z/{a,b,wham_2}, x/c_1
3972 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3973 # y/wham with dirty changes from before merge +
3974 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3975 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3978 test_create_repo
11f
&&
3985 test_seq
1 10 >x
/c
&&
3989 git commit
-m "O" &&
3997 git
mv x
/c y
/wham
&&
3999 git commit
-m "A" &&
4002 git
mv x
/d z
/wham
&&
4008 test_expect_success
'11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
4014 echo important >>y/wham &&
4016 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4017 test_i18ngrep "CONFLICT (rename/rename)" out &&
4018 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
4020 git ls-files -s >out &&
4021 test_line_count = 4 out &&
4022 git ls-files -u >out &&
4023 test_line_count = 2 out &&
4024 git ls-files -o >out &&
4025 test_line_count = 3 out &&
4027 test_seq 1 10 >expected &&
4028 echo important >>expected &&
4029 test_cmp expected y/wham &&
4031 test_must_fail git rev-parse :1:y/wham &&
4033 git rev-parse >actual \
4034 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4035 git rev-parse >expect \
4036 O:z/a O:z/b O:x/c O:x/d &&
4037 test_cmp expect actual &&
4039 # Test that the two-way merge in y/wham~merged is as expected
4040 git cat-file -p :2:y/wham >expect &&
4041 git cat-file -p :3:y/wham >other &&
4043 test_must_fail git merge-file \
4047 expect empty other &&
4048 test_cmp expect y/wham~merged
4052 ###########################################################################
4053 # SECTION 12: Everything else
4055 # Tests suggested by others. Tests added after implementation completed
4056 # and submitted. Grab bag.
4057 ###########################################################################
4059 # Testcase 12a, Moving one directory hierarchy into another
4060 # (Related to testcase 9a)
4061 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
4062 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
4063 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
4064 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
4067 test_create_repo
12a
&&
4071 mkdir
-p node1 node2
&&
4072 echo leaf1
>node
1/leaf1
&&
4073 echo leaf2
>node
1/leaf2
&&
4074 echo leaf3
>node
2/leaf3
&&
4075 echo leaf4
>node
2/leaf4
&&
4076 git add node1 node2
&&
4078 git commit
-m "O" &&
4085 git
mv node
2/ node
1/ &&
4087 git commit
-m "A" &&
4090 echo leaf5
>node
1/leaf5
&&
4091 echo leaf6
>node
2/leaf6
&&
4092 git add node1 node2
&&
4098 test_expect_success
'12a: Moving one directory hierarchy into another' '
4105 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4107 git ls-files -s >out &&
4108 test_line_count = 6 out &&
4110 git rev-parse >actual \
4111 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4112 HEAD:node1/node2/leaf3 \
4113 HEAD:node1/node2/leaf4 \
4114 HEAD:node1/node2/leaf6 &&
4115 git rev-parse >expect \
4116 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4120 test_cmp expect actual
4124 # Testcase 12b1, Moving two directory hierarchies into each other
4125 # (Related to testcases 1c and 12c)
4126 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4127 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4128 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4129 # Expected: node1/node2/{leaf3, leaf4}
4130 # node2/node1/{leaf1, leaf2}
4131 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4132 # then we would need to detect renames for those directories and would
4134 # commit A renames node2/ -> node1/node2/
4135 # commit B renames node1/ -> node2/node1/
4136 # Applying those directory renames to the initial result (making all
4137 # four paths experience a transitive renaming), yields
4138 # node1/node2/node1/{leaf1, leaf2}
4139 # node2/node1/node2/{leaf3, leaf4}
4140 # as the result. It may be really weird to have two directories
4141 # rename each other, but simple rules give weird results when given
4142 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4143 # false; there were no new files added and thus there is no directory
4144 # rename detection to perform. As such, we just have simple renames
4145 # and the expected answer is:
4146 # node1/node2/{leaf3, leaf4}
4147 # node2/node1/{leaf1, leaf2}
4149 test_setup_12b1
() {
4150 test_create_repo
12b1
&&
4154 mkdir
-p node1 node2
&&
4155 echo leaf1
>node
1/leaf1
&&
4156 echo leaf2
>node
1/leaf2
&&
4157 echo leaf3
>node
2/leaf3
&&
4158 echo leaf4
>node
2/leaf4
&&
4159 git add node1 node2
&&
4161 git commit
-m "O" &&
4168 git
mv node
2/ node
1/ &&
4170 git commit
-m "A" &&
4173 git
mv node
1/ node
2/ &&
4179 test_expect_merge_algorithm failure success
'12b1: Moving two directory hierarchies into each other' '
4186 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4188 git ls-files -s >out &&
4189 test_line_count = 4 out &&
4191 git rev-parse >actual \
4192 HEAD:node2/node1/leaf1 \
4193 HEAD:node2/node1/leaf2 \
4194 HEAD:node1/node2/leaf3 \
4195 HEAD:node1/node2/leaf4 &&
4196 git rev-parse >expect \
4201 test_cmp expect actual
4205 # Testcase 12b2, Moving two directory hierarchies into each other
4206 # (Related to testcases 1c and 12c)
4207 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4208 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4209 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4210 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4211 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4212 # NOTE: Without directory renames, we would expect
4213 # A: node2/leaf3 -> node1/node2/leaf3
4214 # A: node2/leaf1 -> node1/node2/leaf4
4215 # A: Adds node1/leaf5
4216 # B: node1/leaf1 -> node2/node1/leaf1
4217 # B: node1/leaf2 -> node2/node1/leaf2
4218 # B: Adds node2/leaf6
4219 # with directory rename detection, we note that
4220 # commit A renames node2/ -> node1/node2/
4221 # commit B renames node1/ -> node2/node1/
4222 # therefore, applying A's directory rename to the paths added in B gives:
4223 # B: node1/leaf1 -> node1/node2/node1/leaf1
4224 # B: node1/leaf2 -> node1/node2/node1/leaf2
4225 # B: Adds node1/node2/leaf6
4226 # and applying B's directory rename to the paths added in A gives:
4227 # A: node2/leaf3 -> node2/node1/node2/leaf3
4228 # A: node2/leaf1 -> node2/node1/node2/leaf4
4229 # A: Adds node2/node1/leaf5
4230 # resulting in the expected
4231 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4232 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4234 # You may ask, is it weird to have two directories rename each other?
4235 # To which, I can do no more than shrug my shoulders and say that
4236 # even simple rules give weird results when given weird inputs.
4238 test_setup_12b2
() {
4239 test_create_repo
12b2
&&
4243 mkdir
-p node1 node2
&&
4244 echo leaf1
>node
1/leaf1
&&
4245 echo leaf2
>node
1/leaf2
&&
4246 echo leaf3
>node
2/leaf3
&&
4247 echo leaf4
>node
2/leaf4
&&
4248 git add node1 node2
&&
4250 git commit
-m "O" &&
4257 git
mv node
2/ node
1/ &&
4258 echo leaf5
>node
1/leaf5
&&
4259 git add node
1/leaf5
&&
4261 git commit
-m "A" &&
4264 git
mv node
1/ node
2/ &&
4265 echo leaf6
>node
2/leaf6
&&
4266 git add node
2/leaf6
&&
4272 test_expect_success
'12b2: Moving two directory hierarchies into each other' '
4279 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4281 git ls-files -s >out &&
4282 test_line_count = 6 out &&
4284 git rev-parse >actual \
4285 HEAD:node1/node2/node1/leaf1 \
4286 HEAD:node1/node2/node1/leaf2 \
4287 HEAD:node2/node1/node2/leaf3 \
4288 HEAD:node2/node1/node2/leaf4 \
4289 HEAD:node2/node1/leaf5 \
4290 HEAD:node1/node2/leaf6 &&
4291 git rev-parse >expect \
4298 test_cmp expect actual
4302 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4303 # (Related to testcase 12b)
4304 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4305 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4306 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4307 # Expected: Content merge conflicts for each of:
4308 # node1/node2/node1/{leaf1, leaf2},
4309 # node2/node1/node2/{leaf3, leaf4}
4310 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4311 # each side of the merge.
4313 test_setup_12c1
() {
4314 test_create_repo
12c1
&&
4318 mkdir
-p node1 node2
&&
4319 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4320 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4321 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4322 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4323 git add node1 node2
&&
4325 git commit
-m "O" &&
4332 git
mv node
2/ node
1/ &&
4333 for i
in `git ls-files`; do echo side A
>>$i; done &&
4336 git commit
-m "A" &&
4339 git
mv node
1/ node
2/ &&
4340 for i
in `git ls-files`; do echo side B
>>$i; done &&
4347 test_expect_merge_algorithm failure success
'12c1: Moving one directory hierarchy into another w/ content merge' '
4354 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4356 git ls-files -u >out &&
4357 test_line_count = 12 out &&
4359 git rev-parse >actual \
4360 :1:node2/node1/leaf1 \
4361 :1:node2/node1/leaf2 \
4362 :1:node1/node2/leaf3 \
4363 :1:node1/node2/leaf4 \
4364 :2:node2/node1/leaf1 \
4365 :2:node2/node1/leaf2 \
4366 :2:node1/node2/leaf3 \
4367 :2:node1/node2/leaf4 \
4368 :3:node2/node1/leaf1 \
4369 :3:node2/node1/leaf2 \
4370 :3:node1/node2/leaf3 \
4371 :3:node1/node2/leaf4 &&
4372 git rev-parse >expect \
4379 A:node1/node2/leaf3 \
4380 A:node1/node2/leaf4 \
4381 B:node2/node1/leaf1 \
4382 B:node2/node1/leaf2 \
4385 test_cmp expect actual
4389 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4390 # (Related to testcase 12b)
4391 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4392 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4393 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4394 # Expected: Content merge conflicts for each of:
4395 # node1/node2/node1/{leaf1, leaf2}
4396 # node2/node1/node2/{leaf3, leaf4}
4400 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4401 # on each side of the merge.
4403 test_setup_12c2
() {
4404 test_create_repo
12c2
&&
4408 mkdir
-p node1 node2
&&
4409 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4410 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4411 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4412 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4413 git add node1 node2
&&
4415 git commit
-m "O" &&
4422 git
mv node
2/ node
1/ &&
4423 for i
in `git ls-files`; do echo side A
>>$i; done &&
4425 echo leaf5
>node
1/leaf5
&&
4426 git add node
1/leaf5
&&
4428 git commit
-m "A" &&
4431 git
mv node
1/ node
2/ &&
4432 for i
in `git ls-files`; do echo side B
>>$i; done &&
4434 echo leaf6
>node
2/leaf6
&&
4435 git add node
2/leaf6
&&
4441 test_expect_success
'12c2: Moving one directory hierarchy into another w/ content merge' '
4448 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4450 git ls-files -s >out &&
4451 test_line_count = 14 out &&
4452 git ls-files -u >out &&
4453 test_line_count = 12 out &&
4455 git rev-parse >actual \
4456 :1:node1/node2/node1/leaf1 \
4457 :1:node1/node2/node1/leaf2 \
4458 :1:node2/node1/node2/leaf3 \
4459 :1:node2/node1/node2/leaf4 \
4460 :2:node1/node2/node1/leaf1 \
4461 :2:node1/node2/node1/leaf2 \
4462 :2:node2/node1/node2/leaf3 \
4463 :2:node2/node1/node2/leaf4 \
4464 :3:node1/node2/node1/leaf1 \
4465 :3:node1/node2/node1/leaf2 \
4466 :3:node2/node1/node2/leaf3 \
4467 :3:node2/node1/node2/leaf4 \
4468 :0:node2/node1/leaf5 \
4469 :0:node1/node2/leaf6 &&
4470 git rev-parse >expect \
4477 A:node1/node2/leaf3 \
4478 A:node1/node2/leaf4 \
4479 B:node2/node1/leaf1 \
4480 B:node2/node1/leaf2 \
4485 test_cmp expect actual
4489 # Testcase 12d, Rename/merge of subdirectory into the root
4490 # Commit O: a/b/subdir/foo
4491 # Commit A: subdir/foo
4492 # Commit B: a/b/subdir/foo, a/b/bar
4493 # Expected: subdir/foo, bar
4496 test_create_repo
12d
&&
4500 mkdir
-p a
/b
/subdir
&&
4501 test_commit a
/b
/subdir
/foo
&&
4509 git
mv a
/b
/subdir
/foo.t subdir
/foo.t
&&
4511 git commit
-m "A" &&
4518 test_expect_success
'12d: Rename/merge subdir into the root, variant 1' '
4525 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4527 git ls-files -s >out &&
4528 test_line_count = 2 out &&
4530 git rev-parse >actual \
4531 HEAD:subdir/foo.t HEAD:bar.t &&
4532 git rev-parse >expect \
4533 O:a/b/subdir/foo.t B:a/b/bar.t &&
4534 test_cmp expect actual &&
4536 git hash-object bar.t >actual &&
4537 git rev-parse B:a/b/bar.t >expect &&
4538 test_cmp expect actual &&
4540 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4541 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4542 test_path_is_missing a/ &&
4543 test_path_is_file bar.t
4547 # Testcase 12e, Rename/merge of subdirectory into the root
4550 # Commit B: a/b/foo, a/b/bar
4551 # Expected: foo, bar
4554 test_create_repo
12e
&&
4559 test_commit a
/b
/foo
&&
4567 git
mv a
/b
/foo.t foo.t
&&
4569 git commit
-m "A" &&
4576 test_expect_success
'12e: Rename/merge subdir into the root, variant 2' '
4583 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4585 git ls-files -s >out &&
4586 test_line_count = 2 out &&
4588 git rev-parse >actual \
4589 HEAD:foo.t HEAD:bar.t &&
4590 git rev-parse >expect \
4591 O:a/b/foo.t B:a/b/bar.t &&
4592 test_cmp expect actual &&
4594 git hash-object bar.t >actual &&
4595 git rev-parse B:a/b/bar.t >expect &&
4596 test_cmp expect actual &&
4598 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4599 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4600 test_path_is_missing a/ &&
4601 test_path_is_file bar.t
4605 # Testcase 12f, Rebase of patches with big directory rename
4607 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4608 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4609 # dir/unchanged/<LOTS OF FILES>
4611 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4612 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4613 # folder/subdir/newsubdir/e_A
4614 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4615 # folder/unchanged/<LOTS OF FILES>
4617 # (add newfile.{c,py}, modify underscored files)
4618 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4619 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4620 # dir/unchanged/<LOTS OF FILES>
4622 # (Modify e further, add newfile.rs)
4623 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4624 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4625 # dir/unchanged/<LOTS OF FILES>
4628 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4629 # folder/subdir/newsubdir/e_Merge1
4630 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4631 # folder/unchanged/<LOTS OF FILES>
4633 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4634 # folder/subdir/newsubdir/e_Merge2
4635 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4636 # folder/unchanged/<LOTS OF FILES>
4638 # Notes: This testcase happens to exercise lots of the
4639 # optimization-specific codepaths in merge-ort, and also
4640 # demonstrated a failing of the directory rename detection algorithm
4641 # in merge-recursive; newfile.c should not get pushed into
4642 # folder/subdir/newsubdir/, yet merge-recursive put it there because
4643 # the rename of dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d}
4646 # whereas the rename of dir/subdir/e -> folder/subdir/newsubdir/e
4648 # dir/subdir/ -> folder/subdir/newsubdir/
4649 # and if we note that newfile.c is found in dir/subdir/, we might
4650 # overlook the dir/ -> folder/ rule that has more weight.
4653 test_create_repo
12f
&&
4657 mkdir
-p dir
/unchanged
&&
4658 mkdir
-p dir
/subdir
/tweaked
&&
4659 echo a
>dir
/subdir
/a
&&
4660 echo b
>dir
/subdir
/b
&&
4661 echo c
>dir
/subdir
/c
&&
4662 echo d
>dir
/subdir
/d
&&
4663 test_seq
1 10 >dir
/subdir
/e
&&
4664 test_seq
10 20 >dir
/subdir
/Makefile
&&
4665 echo f
>dir
/subdir
/tweaked
/f
&&
4666 echo g
>dir
/subdir
/tweaked
/g
&&
4667 echo h
>dir
/subdir
/tweaked
/h
&&
4668 test_seq
20 30 >dir
/subdir
/tweaked
/Makefile
&&
4669 for i
in `test_seq 1 88`; do
4670 echo content
$i >dir
/unchanged
/file_
$i
4673 git commit
-m "O" &&
4680 git
rm dir
/subdir
/tweaked
/f dir
/subdir
/tweaked
/g
&&
4681 test_seq
2 10 >dir
/subdir
/e
&&
4682 test_seq
11 20 >dir
/subdir
/Makefile
&&
4683 test_seq
21 30 >dir
/subdir
/tweaked
/Makefile
&&
4684 mkdir dir
/subdir
/newsubdir
&&
4685 git
mv dir
/subdir
/e dir
/subdir
/newsubdir
/ &&
4686 git
mv dir folder
&&
4688 git commit
-m "A" &&
4691 mkdir dir
/subdir
/newsubdir
/ &&
4692 echo c code
>dir
/subdir
/newfile.c
&&
4693 echo python code
>dir
/subdir
/newsubdir
/newfile.py
&&
4694 test_seq
1 11 >dir
/subdir
/e
&&
4695 test_seq
10 21 >dir
/subdir
/Makefile
&&
4696 test_seq
20 31 >dir
/subdir
/tweaked
/Makefile
&&
4698 git commit
-m "B1" &&
4700 echo rust code
>dir
/subdir
/newfile.rs
&&
4701 test_seq
1 12 >dir
/subdir
/e
&&
4707 test_expect_merge_algorithm failure success
'12f: Trivial directory resolve, caching, all kinds of fun' '
4713 git branch Bmod B &&
4715 git -c merge.directoryRenames=true rebase A Bmod &&
4717 echo Checking the pick of B1... &&
4719 test_must_fail git rev-parse Bmod~1:dir &&
4721 git ls-tree -r Bmod~1 >out &&
4722 test_line_count = 98 out &&
4724 git diff --name-status A Bmod~1 >actual &&
4725 q_to_tab >expect <<-\EOF &&
4726 MQfolder/subdir/Makefile
4727 AQfolder/subdir/newfile.c
4728 MQfolder/subdir/newsubdir/e
4729 AQfolder/subdir/newsubdir/newfile.py
4730 MQfolder/subdir/tweaked/Makefile
4732 test_cmp expect actual &&
4734 # Three-way merged files
4735 test_seq 2 11 >e_Merge1 &&
4736 test_seq 11 21 >Makefile_TOP &&
4737 test_seq 21 31 >Makefile_SUB &&
4738 git hash-object >expect \
4742 git rev-parse >actual \
4743 Bmod~1:folder/subdir/newsubdir/e \
4744 Bmod~1:folder/subdir/Makefile \
4745 Bmod~1:folder/subdir/tweaked/Makefile &&
4746 test_cmp expect actual &&
4748 # New files showed up at the right location with right contents
4749 git rev-parse >expect \
4750 B~1:dir/subdir/newfile.c \
4751 B~1:dir/subdir/newsubdir/newfile.py &&
4752 git rev-parse >actual \
4753 Bmod~1:folder/subdir/newfile.c \
4754 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4755 test_cmp expect actual &&
4758 test_path_is_missing folder/subdir/tweaked/f &&
4759 test_path_is_missing folder/subdir/tweaked/g &&
4761 # Unchanged files or directories
4762 git rev-parse >actual \
4763 Bmod~1:folder/subdir/a \
4764 Bmod~1:folder/subdir/b \
4765 Bmod~1:folder/subdir/c \
4766 Bmod~1:folder/subdir/d \
4767 Bmod~1:folder/unchanged \
4768 Bmod~1:folder/subdir/tweaked/h &&
4769 git rev-parse >expect \
4775 O:dir/subdir/tweaked/h &&
4776 test_cmp expect actual &&
4778 echo Checking the pick of B2... &&
4780 test_must_fail git rev-parse Bmod:dir &&
4782 git ls-tree -r Bmod >out &&
4783 test_line_count = 99 out &&
4785 git diff --name-status Bmod~1 Bmod >actual &&
4786 q_to_tab >expect <<-\EOF &&
4787 AQfolder/subdir/newfile.rs
4788 MQfolder/subdir/newsubdir/e
4790 test_cmp expect actual &&
4792 # Three-way merged file
4793 test_seq 2 12 >e_Merge2 &&
4794 git hash-object e_Merge2 >expect &&
4795 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4796 test_cmp expect actual
4800 ###########################################################################
4801 # SECTION 13: Checking informational and conflict messages
4803 # A year after directory rename detection became the default, it was
4804 # instead decided to report conflicts on the pathname on the basis that
4805 # some users may expect the new files added or moved into a directory to
4806 # be unrelated to all the other files in that directory, and thus that
4807 # directory rename detection is unexpected. Test that the messages printed
4808 # match our expectation.
4809 ###########################################################################
4811 # Testcase 13a, Basic directory rename with newly added files
4814 # Commit B: z/{b,c,d,e/f}
4815 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4818 test_create_repo
13a_
$1 &&
4827 git commit
-m "O" &&
4836 git commit
-m "A" &&
4842 git add z
/d z
/e
/f
&&
4848 test_expect_success
'13a(conflict): messages for newly added files' '
4849 test_setup_13a conflict &&
4855 test_must_fail git merge -s recursive B^0 >out 2>err &&
4857 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4858 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4860 git ls-files >paths &&
4862 grep "y/[de]" paths &&
4864 test_path_is_missing z/d &&
4865 test_path_is_file y/d &&
4866 test_path_is_missing z/e/f &&
4867 test_path_is_file y/e/f
4871 test_expect_success
'13a(info): messages for newly added files' '
4872 test_setup_13a info &&
4879 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4881 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4882 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4884 git ls-files >paths &&
4886 grep "y/[de]" paths &&
4888 test_path_is_missing z/d &&
4889 test_path_is_file y/d &&
4890 test_path_is_missing z/e/f &&
4891 test_path_is_file y/e/f
4895 # Testcase 13b, Transitive rename with conflicted content merge and default
4896 # "conflict" setting
4897 # (Related to testcase 1c, 9b)
4898 # Commit O: z/{b,c}, x/d_1
4899 # Commit A: y/{b,c}, x/d_2
4900 # Commit B: z/{b,c,d_3}
4901 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4902 # one about content, and one about file location
4905 test_create_repo
13b_
$1 &&
4911 test_seq
1 10 >x
/d
&&
4916 git commit
-m "O" &&
4927 git commit
-m "A" &&
4930 echo eleven
>>x
/d
&&
4938 test_expect_success
'13b(conflict): messages for transitive rename with conflicted content' '
4939 test_setup_13b conflict &&
4945 test_must_fail git merge -s recursive B^0 >out 2>err &&
4947 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4948 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4950 git ls-files >paths &&
4954 test_path_is_missing z/d &&
4955 test_path_is_file y/d
4959 test_expect_success
'13b(info): messages for transitive rename with conflicted content' '
4960 test_setup_13b info &&
4967 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4969 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4970 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4972 git ls-files >paths &&
4976 test_path_is_missing z/d &&
4977 test_path_is_file y/d
4981 # Testcase 13c, Rename/rename(1to1) due to directory rename
4982 # Commit O: z/{b,c}, x/{d,e}
4983 # Commit A: y/{b,c,d}, x/e
4984 # Commit B: z/{b,c,d}, x/e
4985 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
4986 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4987 # One could argue A had partial knowledge of what was done with
4988 # d and B had full knowledge, but that's a slippery slope as
4989 # shown in testcase 13d.
4992 test_create_repo
13c_
$1 &&
4998 test_seq
1 10 >x
/d
&&
5004 git commit
-m "O" &&
5014 git commit
-m "A" &&
5024 test_expect_success
'13c(conflict): messages for rename/rename(1to1) via transitive rename' '
5025 test_setup_13c conflict &&
5031 test_must_fail git merge -s recursive B^0 >out 2>err &&
5033 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5035 git ls-files >paths &&
5039 test_path_is_missing z/d &&
5040 test_path_is_file y/d
5044 test_expect_success
'13c(info): messages for rename/rename(1to1) via transitive rename' '
5045 test_setup_13c info &&
5052 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5054 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5056 git ls-files >paths &&
5060 test_path_is_missing z/d &&
5061 test_path_is_file y/d
5065 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
5066 # Commit O: a/{z,y}, b/x, c/w
5067 # Commit A: a/z, b/{y,x}, d/w
5068 # Commit B: a/z, d/x, c/{y,w}
5069 # Expected: a/z, d/{y,x,w} with no file location conflict for x
5071 # * z is always in a; so it stays in a.
5072 # * x starts in b, only modified on one side to move into d/
5073 # * w starts in c, only modified on one side to move into d/
5075 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5076 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5077 # No conflict in where a/y ends up, so put it in d/y.
5080 test_create_repo
13d_
$1 &&
5093 git commit
-m "O" &&
5103 git commit
-m "A" &&
5113 test_expect_success
'13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5114 test_setup_13d conflict &&
5120 test_must_fail git merge -s recursive B^0 >out 2>err &&
5122 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5123 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5125 git ls-files >paths &&
5130 test_path_is_missing b/y &&
5131 test_path_is_missing c/y &&
5132 test_path_is_file d/y
5136 test_expect_success
'13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5137 test_setup_13d info &&
5144 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5146 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5147 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5149 git ls-files >paths &&
5154 test_path_is_missing b/y &&
5155 test_path_is_missing c/y &&
5156 test_path_is_file d/y
5160 # Testcase 13e, directory rename in virtual merge base
5162 # This testcase has a slightly different setup than all the above cases, in
5163 # order to include a recursive case:
5175 # Commit B: a/{z,y,x}
5176 # Commit C: b/{z,y,x}
5177 # Commit D: b/{z,y}, a/x
5178 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5180 # NOTES: 'X' represents a virtual merge base. With the default of
5181 # directory rename detection yielding conflicts, merging A and B
5182 # results in a conflict complaining about whether 'x' should be
5183 # under 'a/' or 'b/'. However, when creating the virtual merge
5184 # base 'X', since virtual merge bases need to be written out as a
5185 # tree, we cannot have a conflict, so some resolution has to be
5188 # In choosing the right resolution, it's worth noting here that
5189 # commits C & D are merges of A & B that choose different
5190 # locations for 'x' (i.e. they resolve the conflict differently),
5191 # and so it would be nice when merging C & D if git could detect
5192 # this difference of opinion and report a conflict. But the only
5193 # way to do so that I can think of would be to have the virtual
5194 # merge base place 'x' in some directory other than either 'a/' or
5195 # 'b/', which seems a little weird -- especially since it'd result
5196 # in a rename/rename(1to2) conflict with a source path that never
5197 # existed in any version.
5199 # So, for now, when directory rename detection is set to
5200 # 'conflict' just avoid doing directory rename detection at all in
5201 # the recursive case. This will not allow us to detect a conflict
5202 # in the outer merge for this special kind of setup, but it at
5203 # least avoids hitting a BUG().
5206 test_create_repo
13e
&&
5215 git commit
-m "O" &&
5224 git commit
-m "A" &&
5230 git commit
-m "B" &&
5236 test_must_fail git
-c merge.directoryRenames
=conflict merge B
&&
5239 git commit
-m "C" &&
5243 test_must_fail git
-c merge.directoryRenames
=conflict merge A
&&
5252 test_expect_success
'13e: directory rename detection in recursive case' '
5257 git checkout --quiet D^0 &&
5259 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5261 test_i18ngrep ! CONFLICT out &&
5262 test_i18ngrep ! BUG: err &&
5263 test_i18ngrep ! core.dumped err &&
5264 test_must_be_empty err &&
5266 git ls-files >paths &&