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.)
28 TEST_PASSES_SANITIZE_LEAK
=true
30 .
"$TEST_DIRECTORY"/lib-merge.sh
33 ###########################################################################
34 # SECTION 1: Basic cases we should be able to handle
35 ###########################################################################
37 # Testcase 1a, Basic directory rename.
40 # Commit B: z/{b,c,d,e/f}
41 # Expected: y/{b,c,d,e/f}
74 test_expect_success
'1a: Simple directory rename detection' '
81 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
83 git ls-files -s >out &&
84 test_line_count = 4 out &&
86 git rev-parse >actual \
87 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
88 git rev-parse >expect \
89 O:z/b O:z/c B:z/d B:z/e/f &&
90 test_cmp expect actual &&
92 git hash-object y/d >actual &&
93 git rev-parse B:z/d >expect &&
94 test_cmp expect actual &&
96 test_must_fail git rev-parse HEAD:z/d &&
97 test_must_fail git rev-parse HEAD:z/e/f &&
98 test_path_is_missing z/d &&
99 test_path_is_missing z/e/f
103 # Testcase 1b, Merge a directory with another
104 # Commit O: z/{b,c}, y/d
105 # Commit A: z/{b,c,e}, y/d
106 # Commit B: y/{b,c,d}
107 # Expected: y/{b,c,d,e}
142 test_expect_success
'1b: Merge a directory with another' '
149 git -c merge.directoryRenames=true merge -s recursive B^0 &&
151 git ls-files -s >out &&
152 test_line_count = 4 out &&
154 git rev-parse >actual \
155 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
156 git rev-parse >expect \
157 O:z/b O:z/c O:y/d A:z/e &&
158 test_cmp expect actual &&
159 test_must_fail git rev-parse HEAD:z/e
163 # Testcase 1c, Transitive renaming
164 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
165 # (Related to testcases 9c and 9d -- can transitivity repeat?)
166 # (Related to testcase 12b -- joint-transitivity?)
167 # Commit O: z/{b,c}, x/d
168 # Commit A: y/{b,c}, x/d
169 # Commit B: z/{b,c,d}
170 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
202 test_expect_success
'1c: Transitive renaming' '
209 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
211 git ls-files -s >out &&
212 test_line_count = 3 out &&
214 git rev-parse >actual \
215 HEAD:y/b HEAD:y/c HEAD:y/d &&
216 git rev-parse >expect \
218 test_cmp expect actual &&
219 test_must_fail git rev-parse HEAD:x/d &&
220 test_must_fail git rev-parse HEAD:z/d &&
221 test_path_is_missing z/d
225 # Testcase 1d, Directory renames (merging two directories into one new one)
226 # cause a rename/rename(2to1) conflict
227 # (Related to testcases 1c and 7b)
228 # Commit O. z/{b,c}, y/{d,e}
229 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
230 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
231 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
232 # Note: y/m & z/n should definitely move into x. By the same token, both
233 # y/wham_1 & z/wham_2 should too...giving us a conflict.
257 echo wham1
>y
/wham
&&
265 echo wham2
>z
/wham
&&
272 test_expect_success
'1d: Directory renames cause a rename/rename(2to1) conflict' '
279 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
280 test_grep "CONFLICT (\(.*\)/\1)" out &&
282 git ls-files -s >out &&
283 test_line_count = 8 out &&
284 git ls-files -u >out &&
285 test_line_count = 2 out &&
286 git ls-files -o >out &&
287 test_line_count = 1 out &&
289 git rev-parse >actual \
290 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
291 git rev-parse >expect \
292 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
293 test_cmp expect actual &&
295 test_must_fail git rev-parse :0:x/wham &&
296 git rev-parse >actual \
297 :2:x/wham :3:x/wham &&
298 git rev-parse >expect \
300 test_cmp expect actual &&
302 # Test that the two-way merge in x/wham is as expected
303 git cat-file -p :2:x/wham >expect &&
304 git cat-file -p :3:x/wham >other &&
306 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
308 test_must_fail git merge-file \
314 test_must_fail git merge-file \
320 test_cmp expect x/wham
324 # Testcase 1e, Renamed directory, with all filenames being renamed too
325 # (Related to testcases 9f & 9g)
326 # Commit O: z/{oldb,oldc}
327 # Commit A: y/{newb,newc}
328 # Commit B: z/{oldb,oldc,d}
329 # Expected: y/{newb,newc,d}
349 git
mv z
/oldb y
/newb
&&
350 git
mv z
/oldc y
/newc
&&
362 test_expect_success
'1e: Renamed directory, with all files being renamed too' '
369 git -c merge.directoryRenames=true merge -s recursive B^0 &&
371 git ls-files -s >out &&
372 test_line_count = 3 out &&
374 git rev-parse >actual \
375 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
376 git rev-parse >expect \
377 O:z/oldb O:z/oldc B:z/d &&
378 test_cmp expect actual &&
379 test_must_fail git rev-parse HEAD:z/d
383 # Testcase 1f, Split a directory into two other directories
384 # (Related to testcases 3a, all of section 2, and all of section 4)
385 # Commit O: z/{b,c,d,e,f}
386 # Commit A: z/{b,c,d,e,f,g}
387 # Commit B: y/{b,c}, x/{d,e,f}
388 # Expected: y/{b,c}, x/{d,e,f,g}
429 test_expect_success
'1f: Split a directory into two other directories' '
436 git -c merge.directoryRenames=true merge -s recursive B^0 &&
438 git ls-files -s >out &&
439 test_line_count = 6 out &&
441 git rev-parse >actual \
442 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
443 git rev-parse >expect \
444 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
445 test_cmp expect actual &&
446 test_path_is_missing z/g &&
447 test_must_fail git rev-parse HEAD:z/g
451 ###########################################################################
452 # Rules suggested by testcases in section 1:
454 # We should still detect the directory rename even if it wasn't just
455 # the directory renamed, but the files within it. (see 1b)
457 # If renames split a directory into two or more others, the directory
458 # with the most renames, "wins" (see 1f). However, see the testcases
459 # in section 2, plus testcases 3a and 4a.
460 ###########################################################################
463 ###########################################################################
464 # SECTION 2: Split into multiple directories, with equal number of paths
466 # Explore the splitting-a-directory rules a bit; what happens in the
469 # Note that there is a closely related case of a directory not being
470 # split on either side of history, but being renamed differently on
471 # each side. See testcase 8e for that.
472 ###########################################################################
474 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
477 # Commit B: z/{b,c,d}
478 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
511 test_expect_success
'2a: Directory split into two on one side, with equal numbers of paths' '
518 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
519 test_grep "CONFLICT.*directory rename split" out &&
521 git ls-files -s >out &&
522 test_line_count = 3 out &&
523 git ls-files -u >out &&
524 test_line_count = 0 out &&
525 git ls-files -o >out &&
526 test_line_count = 1 out &&
528 git rev-parse >actual \
529 :0:y/b :0:w/c :0:z/d &&
530 git rev-parse >expect \
532 test_cmp expect actual
536 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
539 # Commit B: z/{b,c}, x/d
540 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
574 test_expect_success
'2b: Directory split into two on one side, with equal numbers of paths' '
581 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
583 git ls-files -s >out &&
584 test_line_count = 3 out &&
585 git ls-files -u >out &&
586 test_line_count = 0 out &&
587 git ls-files -o >out &&
588 test_line_count = 1 out &&
590 git rev-parse >actual \
591 :0:y/b :0:w/c :0:x/d &&
592 git rev-parse >expect \
594 test_cmp expect actual &&
595 test_grep ! "CONFLICT.*directory rename split" out
599 ###########################################################################
600 # Rules suggested by section 2:
602 # None; the rule was already covered in section 1. These testcases are
603 # here just to make sure the conflict resolution and necessary warning
604 # messages are handled correctly.
605 ###########################################################################
608 ###########################################################################
609 # SECTION 3: Path in question is the source path for some rename already
611 # Combining cases from Section 1 and trying to handle them could lead to
612 # directory renaming detection being over-applied. So, this section
613 # provides some good testcases to check that the implementation doesn't go
615 ###########################################################################
617 # Testcase 3a, Avoid implicit rename if involved as source on other side
618 # (Related to testcases 1c, 1f, and 9h)
619 # Commit O: z/{b,c,d}
620 # Commit A: z/{b,c,d} (no change)
621 # Commit B: y/{b,c}, x/d
622 # Expected: y/{b,c}, x/d
642 git commit
--allow-empty -m "A" &&
656 test_expect_success
'3a: Avoid implicit rename if involved as source on other side' '
663 git -c merge.directoryRenames=true merge -s recursive B^0 &&
665 git ls-files -s >out &&
666 test_line_count = 3 out &&
668 git rev-parse >actual \
669 HEAD:y/b HEAD:y/c HEAD:x/d &&
670 git rev-parse >expect \
672 test_cmp expect actual
676 # Testcase 3b, Avoid implicit rename if involved as source on other side
677 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
678 # Commit O: z/{b,c,d}
679 # Commit A: y/{b,c}, x/d
680 # Commit B: z/{b,c}, w/d
681 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
682 # NOTE: We're particularly checking that since z/d is already involved as
683 # a source in a file rename on the same side of history, that we don't
684 # get it involved in directory rename detection. If it were, we might
685 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
686 # rename/rename/rename(1to3) conflict, which is just weird.
722 test_expect_success
'3b: Avoid implicit rename if involved as source on current side' '
729 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
730 test_grep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
731 test_grep ! CONFLICT.*rename/rename.*y/d out &&
733 git ls-files -s >out &&
734 test_line_count = 5 out &&
735 git ls-files -u >out &&
736 test_line_count = 3 out &&
737 git ls-files -o >out &&
738 test_line_count = 1 out &&
740 git rev-parse >actual \
741 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
742 git rev-parse >expect \
743 O:z/b O:z/c O:z/d O:z/d O:z/d &&
744 test_cmp expect actual &&
746 test_path_is_missing z/d &&
747 git hash-object >actual \
749 git rev-parse >expect \
751 test_cmp expect actual
755 ###########################################################################
756 # Rules suggested by section 3:
758 # Avoid directory-rename-detection for a path, if that path is the source
759 # of a rename on either side of a merge.
760 ###########################################################################
763 ###########################################################################
764 # SECTION 4: Partially renamed directory; still exists on both sides of merge
766 # What if we were to attempt to do directory rename detection when someone
767 # "mostly" moved a directory but still left some files around, or,
768 # equivalently, fully renamed a directory in one commit and then recreated
769 # that directory in a later commit adding some new files and then tried to
772 # It's hard to divine user intent in these cases, because you can make an
773 # argument that, depending on the intermediate history of the side being
774 # merged, that some users will want files in that directory to
775 # automatically be detected and renamed, while users with a different
776 # intermediate history wouldn't want that rename to happen.
778 # I think that it is best to simply not have directory rename detection
779 # apply to such cases. My reasoning for this is four-fold: (1) it's
780 # easiest for users in general to figure out what happened if we don't
781 # apply directory rename detection in any such case, (2) it's an easy rule
782 # to explain ["We don't do directory rename detection if the directory
783 # still exists on both sides of the merge"], (3) we can get some hairy
784 # edge/corner cases that would be really confusing and possibly not even
785 # representable in the index if we were to even try, and [related to 3] (4)
786 # attempting to resolve this issue of divining user intent by examining
787 # intermediate history goes against the spirit of three-way merges and is a
788 # path towards crazy corner cases that are far more complex than what we're
789 # already dealing with.
791 # Note that the wording of the rule ("We don't do directory rename
792 # detection if the directory still exists on both sides of the merge.")
793 # also excludes "renaming" of a directory into a subdirectory of itself
794 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
795 # out an exception for "renaming"-beneath-itself cases without opening
796 # weird edge/corner cases for other partial directory renames, but for now
797 # we are keeping the rule simple.
799 # This section contains a test for a partially-renamed-directory case.
800 ###########################################################################
802 # Testcase 4a, Directory split, with original directory still present
803 # (Related to testcase 1f)
804 # Commit O: z/{b,c,d,e}
805 # Commit A: y/{b,c,d}, z/e
806 # Commit B: z/{b,c,d,e,f}
807 # Expected: y/{b,c,d}, z/{e,f}
808 # NOTE: Even though most files from z moved to y, we don't want f to follow.
844 test_expect_success
'4a: Directory split, with original directory still present' '
851 git -c merge.directoryRenames=true merge -s recursive B^0 &&
853 git ls-files -s >out &&
854 test_line_count = 5 out &&
855 git ls-files -u >out &&
856 test_line_count = 0 out &&
857 git ls-files -o >out &&
858 test_line_count = 1 out &&
860 git rev-parse >actual \
861 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
862 git rev-parse >expect \
863 O:z/b O:z/c O:z/d O:z/e B:z/f &&
864 test_cmp expect actual
868 ###########################################################################
869 # Rules suggested by section 4:
871 # Directory-rename-detection should be turned off for any directories (as
872 # a source for renames) that exist on both sides of the merge. (The "as
873 # a source for renames" clarification is due to cases like 1c where
874 # the target directory exists on both sides and we do want the rename
875 # detection.) But, sadly, see testcase 8b.
876 ###########################################################################
879 ###########################################################################
880 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
882 # Implicitly renaming files due to a detected directory rename could run
883 # into problems if there are files or directories in the way of the paths
884 # we want to rename. Explore such cases in this section.
885 ###########################################################################
887 # Testcase 5a, Merge directories, other side adds files to original and target
888 # Commit O: z/{b,c}, y/d
889 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
890 # Commit B: y/{b,c,d}
891 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
892 # NOTE: While directory rename detection is active here causing z/f to
893 # become y/f, we did not apply this for z/e_1 because that would
894 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
895 # this add/add, is that both versions of y/e are from the same side
896 # of history, giving us no way to represent this conflict in the
921 git add z
/e z
/f y
/e
&&
934 test_expect_success
'5a: Merge directories, other side adds files to original and target' '
941 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
942 test_grep "CONFLICT.*implicit dir rename" out &&
944 git ls-files -s >out &&
945 test_line_count = 6 out &&
946 git ls-files -u >out &&
947 test_line_count = 0 out &&
948 git ls-files -o >out &&
949 test_line_count = 1 out &&
951 git rev-parse >actual \
952 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
953 git rev-parse >expect \
954 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
955 test_cmp expect actual
959 # Testcase 5b, Rename/delete in order to get add/add/add conflict
960 # (Related to testcase 8d; these may appear slightly inconsistent to users;
961 # Also related to testcases 7d and 7e)
962 # Commit O: z/{b,c,d_1}
963 # Commit A: y/{b,c,d_2}
964 # Commit B: z/{b,c,d_1,e}, y/d_3
965 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
966 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
967 # we normally would since z/ is being renamed to y/, then this would be
968 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
969 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
970 # representable in the index, so the existence of y/d_3 needs to
971 # cause us to bail on directory rename detection for that path, falling
972 # back to git behavior without the directory rename detection.
1009 test_expect_success
'5b: Rename/delete in order to get add/add/add conflict' '
1016 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1017 test_grep "CONFLICT (add/add).* y/d" out &&
1019 git ls-files -s >out &&
1020 test_line_count = 5 out &&
1021 git ls-files -u >out &&
1022 test_line_count = 2 out &&
1023 git ls-files -o >out &&
1024 test_line_count = 1 out &&
1026 git rev-parse >actual \
1027 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1028 git rev-parse >expect \
1029 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1030 test_cmp expect actual &&
1032 test_must_fail git rev-parse :1:y/d &&
1033 test_path_is_file y/d
1037 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1038 # (Directory rename detection would result in transitive rename vs.
1039 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1040 # rename paths conflict with separate adds on the other side)
1041 # (Related to testcases 3b and 7c)
1042 # Commit O: z/{b,c}, x/d_1
1043 # Commit A: y/{b,c,d_2}, w/d_1
1044 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1045 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1046 # presence of y/d_4 in B to avoid doing transitive rename of
1047 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1048 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1049 # though, because it doesn't have anything in the way.
1063 git commit
-m "O" &&
1075 git commit
-m "A" &&
1084 git add w
/ y
/ z
/e
&&
1090 test_expect_success
'5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1097 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1098 test_grep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1099 test_grep "CONFLICT (add/add).* y/d" out &&
1101 git ls-files -s >out &&
1102 test_line_count = 9 out &&
1103 git ls-files -u >out &&
1104 test_line_count = 6 out &&
1105 git ls-files -o >out &&
1106 test_line_count = 1 out &&
1108 git rev-parse >actual \
1109 :0:y/b :0:y/c :0:y/e &&
1110 git rev-parse >expect \
1111 O:z/b O:z/c B:z/e &&
1112 test_cmp expect actual &&
1114 test_must_fail git rev-parse :1:y/d &&
1115 git rev-parse >actual \
1116 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1117 git rev-parse >expect \
1118 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1119 test_cmp expect actual &&
1121 git hash-object >actual \
1123 git rev-parse >expect \
1125 test_cmp expect actual &&
1126 test_path_is_missing x/d &&
1127 test_path_is_file y/d &&
1128 grep -q "<<<<" y/d # conflict markers should be present
1132 # Testcase 5d, Directory/file/file conflict due to directory rename
1134 # Commit A: y/{b,c,d_1}
1135 # Commit B: z/{b,c,d_2,f}, y/d/e
1136 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1137 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1138 # detection for z/d_2, but that doesn't prevent us from applying the
1139 # directory rename detection for z/f -> y/f.
1151 git commit
-m "O" &&
1162 git commit
-m "A" &&
1169 git add y
/d
/e z
/d z
/f
&&
1175 test_expect_success
'5d: Directory/file/file conflict due to directory rename' '
1182 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1183 test_grep "CONFLICT (file/directory).*y/d" out &&
1185 git ls-files -s >out &&
1186 test_line_count = 6 out &&
1187 git ls-files -u >out &&
1188 test_line_count = 1 out &&
1189 git ls-files -o >out &&
1190 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1192 test_line_count = 1 out &&
1194 git rev-parse >actual \
1195 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e
1197 test_line_count = 2 out &&
1199 git rev-parse >actual \
1200 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e
1202 git rev-parse >expect \
1203 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1204 test_cmp expect actual &&
1206 git hash-object y/d~HEAD >actual &&
1207 git rev-parse A:y/d >expect &&
1208 test_cmp expect actual
1212 ###########################################################################
1213 # Rules suggested by section 5:
1215 # If a subset of to-be-renamed files have a file or directory in the way,
1216 # "turn off" the directory rename for those specific sub-paths, falling
1217 # back to old handling. But, sadly, see testcases 8a and 8b.
1218 ###########################################################################
1221 ###########################################################################
1222 # SECTION 6: Same side of the merge was the one that did the rename
1224 # It may sound obvious that you only want to apply implicit directory
1225 # renames to directories if the _other_ side of history did the renaming.
1226 # If you did make an implementation that didn't explicitly enforce this
1227 # rule, the majority of cases that would fall under this section would
1228 # also be solved by following the rules from the above sections. But
1229 # there are still a few that stick out, so this section covers them just
1230 # to make sure we also get them right.
1231 ###########################################################################
1233 # Testcase 6a, Tricky rename/delete
1234 # Commit O: z/{b,c,d}
1236 # Commit B: y/{b,c}, z/d
1237 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1238 # Note: We're just checking here that the rename of z/b and z/c to put
1239 # them under y/ doesn't accidentally catch z/d and make it look like
1240 # it is also involved in a rename/delete conflict.
1253 git commit
-m "O" &&
1263 git commit
-m "A" &&
1274 test_expect_success
'6a: Tricky rename/delete' '
1281 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1282 test_grep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1284 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1286 git ls-files -s >out &&
1287 test_line_count = 3 out &&
1288 git ls-files -u >out &&
1289 test_line_count = 2 out &&
1290 git ls-files -o >out &&
1291 test_line_count = 1 out &&
1293 git rev-parse >actual \
1294 :0:y/b :1:y/c :3:y/c &&
1295 git rev-parse >expect \
1298 git ls-files -s >out &&
1299 test_line_count = 2 out &&
1300 git ls-files -u >out &&
1301 test_line_count = 1 out &&
1302 git ls-files -o >out &&
1303 test_line_count = 1 out &&
1305 git rev-parse >actual \
1307 git rev-parse >expect \
1310 test_cmp expect actual
1314 # Testcase 6b1, Same rename done on both sides
1315 # (Related to testcase 6b2 and 8e)
1316 # Commit O: z/{b,c,d,e}
1317 # Commit A: y/{b,c,d}, x/e
1318 # Commit B: y/{b,c,d}, z/{e,f}
1319 # Expected: y/{b,c,d,f}, x/e
1320 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1321 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1322 # should be moved to 'y/f'.
1324 # This is a bit of an edge case where any behavior might surprise users,
1325 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1326 # z/ -> x/, or treating A as not doing any directory rename. However, I
1327 # think this answer is the least confusing and most consistent with the
1330 # A note about z/ -> x/, since it may not be clear how that could come
1331 # about: If we were to ignore files renamed by both sides
1332 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1333 # at least git-2.28, then we would note there are no renames from z/ to
1334 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1335 # A renamed z/ -> x/. This seems more confusing for end users than a
1336 # rename of z/ to y/, it makes directory rename detection behavior
1337 # harder for them to predict. As such, we modified the rule, changed
1338 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1352 git commit
-m "O" &&
1363 git commit
-m "A" &&
1376 test_expect_merge_algorithm failure success
'6b1: Same renames done on both sides, plus another rename' '
1383 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1385 git ls-files -s >out &&
1386 test_line_count = 5 out &&
1387 git ls-files -u >out &&
1388 test_line_count = 0 out &&
1389 git ls-files -o >out &&
1390 test_line_count = 1 out &&
1392 git rev-parse >actual \
1393 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1394 git rev-parse >expect \
1395 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1396 test_cmp expect actual
1400 # Testcase 6b2, Same rename done on both sides
1401 # (Related to testcases 6c and 8e)
1404 # Commit B: y/{b,c}, z/d
1405 # Expected: y/{b,c,d}
1406 # Alternate: y/{b,c}, z/d
1407 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1408 # file 'z/d' in B should be moved to 'y/d'.
1410 # We could potentially ignore the renames of z/{b,c} on side A since
1411 # those were renamed on both sides. However, it's a bit of a corner
1412 # case because what if there was also a z/e that side A moved to x/e
1413 # and side B left alone? If we used the "ignore renames done on both
1414 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1415 # z/d to x/d. That seems more surprising and uglier than allowing
1416 # the z/ -> y/ rename.
1428 git commit
-m "O" &&
1437 git commit
-m "A" &&
1449 test_expect_merge_algorithm failure success
'6b2: Same rename done on both sides' '
1456 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1458 git ls-files -s >out &&
1459 test_line_count = 3 out &&
1460 git ls-files -u >out &&
1461 test_line_count = 0 out &&
1462 git ls-files -o >out &&
1463 test_line_count = 1 out &&
1465 git rev-parse >actual \
1466 HEAD:y/b HEAD:y/c HEAD:y/d &&
1467 git rev-parse >expect \
1468 O:z/b O:z/c B:z/d &&
1469 test_cmp expect actual
1473 # Testcase 6c, Rename only done on same side
1474 # (Related to testcases 6b1, 6b2, and 8e)
1476 # Commit A: z/{b,c} (no change)
1477 # Commit B: y/{b,c}, z/d
1478 # Expected: y/{b,c}, z/d
1479 # NOTE: Seems obvious, but just checking that the implementation doesn't
1480 # "accidentally detect a rename" and give us y/{b,c,d}.
1492 git commit
-m "O" &&
1500 git commit
--allow-empty -m "A" &&
1512 test_expect_success
'6c: Rename only done on same side' '
1519 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1521 git ls-files -s >out &&
1522 test_line_count = 3 out &&
1523 git ls-files -u >out &&
1524 test_line_count = 0 out &&
1525 git ls-files -o >out &&
1526 test_line_count = 1 out &&
1528 git rev-parse >actual \
1529 HEAD:y/b HEAD:y/c HEAD:z/d &&
1530 git rev-parse >expect \
1531 O:z/b O:z/c B:z/d &&
1532 test_cmp expect actual
1536 # Testcase 6d, We don't always want transitive renaming
1537 # (Related to testcase 1c)
1538 # Commit O: z/{b,c}, x/d
1539 # Commit A: z/{b,c}, x/d (no change)
1540 # Commit B: y/{b,c}, z/d
1541 # Expected: y/{b,c}, z/d
1542 # NOTE: Again, this seems obvious but just checking that the implementation
1543 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1557 git commit
-m "O" &&
1565 git commit
--allow-empty -m "A" &&
1575 test_expect_success
'6d: We do not always want transitive renaming' '
1582 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1584 git ls-files -s >out &&
1585 test_line_count = 3 out &&
1586 git ls-files -u >out &&
1587 test_line_count = 0 out &&
1588 git ls-files -o >out &&
1589 test_line_count = 1 out &&
1591 git rev-parse >actual \
1592 HEAD:y/b HEAD:y/c HEAD:z/d &&
1593 git rev-parse >expect \
1594 O:z/b O:z/c O:x/d &&
1595 test_cmp expect actual
1599 # Testcase 6e, Add/add from one-side
1601 # Commit A: z/{b,c} (no change)
1602 # Commit B: y/{b,c,d_1}, z/d_2
1603 # Expected: y/{b,c,d_1}, z/d_2
1604 # NOTE: Again, this seems obvious but just checking that the implementation
1605 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1606 # add/add conflict on y/d_1 vs y/d_2.
1618 git commit
-m "O" &&
1626 git commit
--allow-empty -m "A" &&
1639 test_expect_success
'6e: Add/add from one side' '
1646 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1648 git ls-files -s >out &&
1649 test_line_count = 4 out &&
1650 git ls-files -u >out &&
1651 test_line_count = 0 out &&
1652 git ls-files -o >out &&
1653 test_line_count = 1 out &&
1655 git rev-parse >actual \
1656 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1657 git rev-parse >expect \
1658 O:z/b O:z/c B:y/d B:z/d &&
1659 test_cmp expect actual
1663 ###########################################################################
1664 # Rules suggested by section 6:
1666 # Only apply implicit directory renames to directories if the other
1667 # side of history is the one doing the renaming.
1668 ###########################################################################
1671 ###########################################################################
1672 # SECTION 7: More involved Edge/Corner cases
1674 # The ruleset we have generated in the above sections seems to provide
1675 # well-defined merges. But can we find edge/corner cases that either (a)
1676 # are harder for users to understand, or (b) have a resolution that is
1677 # non-intuitive or suboptimal?
1679 # The testcases in this section dive into cases that I've tried to craft in
1680 # a way to find some that might be surprising to users or difficult for
1681 # them to understand (the next section will look at non-intuitive or
1682 # suboptimal merge results). Some of the testcases are similar to ones
1683 # from past sections, but have been simplified to try to highlight error
1684 # messages using a "modified" path (due to the directory rename). Are
1685 # users okay with these?
1687 # In my opinion, testcases that are difficult to understand from this
1688 # section is due to difficulty in the testcase rather than the directory
1689 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1690 # to the problem setup itself being complex). And I don't think the
1691 # error messages are a problem.
1693 # On the other hand, the testcases in section 8 worry me slightly more...
1694 ###########################################################################
1696 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1699 # Commit B: w/b, x/c, z/d
1700 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1701 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1713 git commit
-m "O" &&
1722 git commit
-m "A" &&
1736 test_expect_success
'7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1743 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1744 test_grep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1745 test_grep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1747 git ls-files -s >out &&
1748 test_line_count = 7 out &&
1749 git ls-files -u >out &&
1750 test_line_count = 6 out &&
1751 git ls-files -o >out &&
1752 test_line_count = 1 out &&
1754 git rev-parse >actual \
1755 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1756 git rev-parse >expect \
1757 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1758 test_cmp expect actual &&
1760 git hash-object >actual \
1762 git rev-parse >expect \
1763 O:z/b O:z/b O:z/c O:z/c &&
1764 test_cmp expect actual
1768 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1769 # (Related to testcase 1d)
1770 # Commit O: z/{b,c}, x/d_1, w/d_2
1771 # Commit A: y/{b,c,d_2}, x/d_1
1772 # Commit B: z/{b,c,d_1}, w/d_2
1773 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1789 git commit
-m "O" &&
1799 git commit
-m "A" &&
1809 test_expect_success
'7b: rename/rename(2to1), but only due to transitive rename' '
1816 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1817 test_grep "CONFLICT (\(.*\)/\1)" out &&
1819 git ls-files -s >out &&
1820 test_line_count = 4 out &&
1821 git ls-files -u >out &&
1822 test_line_count = 2 out &&
1823 git ls-files -o >out &&
1824 test_line_count = 1 out &&
1826 git rev-parse >actual \
1827 :0:y/b :0:y/c :2:y/d :3:y/d &&
1828 git rev-parse >expect \
1829 O:z/b O:z/c O:w/d O:x/d &&
1830 test_cmp expect actual &&
1832 # Test that the two-way merge in y/d is as expected
1833 git cat-file -p :2:y/d >expect &&
1834 git cat-file -p :3:y/d >other &&
1836 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1838 test_must_fail git merge-file \
1844 test_must_fail git merge-file \
1854 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1855 # (Related to testcases 3b and 5c)
1856 # Commit O: z/{b,c}, x/d
1857 # Commit A: y/{b,c}, w/d
1858 # Commit B: z/{b,c,d}
1859 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1860 # NOTE: z/ was renamed to y/ so we do want to report
1861 # neither CONFLICT(x/d -> w/d vs. z/d)
1862 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1876 git commit
-m "O" &&
1886 git commit
-m "A" &&
1896 test_expect_success
'7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1903 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1904 test_grep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1906 git ls-files -s >out &&
1907 test_line_count = 5 out &&
1908 git ls-files -u >out &&
1909 test_line_count = 3 out &&
1910 git ls-files -o >out &&
1911 test_line_count = 1 out &&
1913 git rev-parse >actual \
1914 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1915 git rev-parse >expect \
1916 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1917 test_cmp expect actual
1921 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1922 # (Related somewhat to testcases 5b and 8d)
1923 # Commit O: z/{b,c}, x/d
1925 # Commit B: z/{b,c,d}
1926 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1927 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1941 git commit
-m "O" &&
1951 git commit
-m "A" &&
1961 test_expect_success
'7d: transitive rename involved in rename/delete; how is it reported?' '
1968 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1969 test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1971 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1973 git ls-files -s >out &&
1974 test_line_count = 4 out &&
1975 git ls-files -u >out &&
1976 test_line_count = 2 out &&
1977 git ls-files -o >out &&
1978 test_line_count = 1 out &&
1980 git rev-parse >actual \
1981 :0:y/b :0:y/c :1:y/d :3:y/d &&
1982 git rev-parse >expect \
1983 O:z/b O:z/c O:x/d O:x/d
1985 git ls-files -s >out &&
1986 test_line_count = 3 out &&
1987 git ls-files -u >out &&
1988 test_line_count = 1 out &&
1989 git ls-files -o >out &&
1990 test_line_count = 1 out &&
1992 git rev-parse >actual \
1993 :0:y/b :0:y/c :3:y/d &&
1994 git rev-parse >expect \
1997 test_cmp expect actual
2001 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
2002 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
2003 # (Also related to testcases 9c and 9d)
2004 # Commit O: z/{b,c}, x/d_1
2005 # Commit A: y/{b,c,d/g}, x/d/f
2006 # Commit B: z/{b,c,d_1}
2007 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
2008 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
2010 # NOTE: The main path of interest here is d_1 and where it ends up, but
2011 # this is actually a case that has two potential directory renames
2012 # involved and D/F conflict(s), so it makes sense to walk through
2015 # Commit A renames z/ -> y/. Thus everything that B adds to z/
2016 # should be instead moved to y/. This gives us the D/F conflict on
2017 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
2019 # Further, commit B renames x/ -> z/, thus everything A adds to x/
2020 # should instead be moved to z/...BUT we removed z/ and renamed it
2021 # to y/, so maybe everything should move not from x/ to z/, but
2022 # from x/ to z/ to y/. Doing so might make sense from the logic so
2023 # far, but note that commit A had both an x/ and a y/; it did the
2024 # renaming of z/ to y/ and created x/d/f and it clearly made these
2025 # things separate, so it doesn't make much sense to push these
2026 # together. Doing so is what I'd call a doubly transitive rename;
2027 # see testcases 9c and 9d for further discussion of this issue and
2028 # how it's resolved.
2042 git commit
-m "O" &&
2055 git add x
/d
/f y
/d
/g
&&
2057 git commit
-m "A" &&
2067 test_expect_success
'7e: transitive rename in rename/delete AND dirs in the way' '
2074 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2075 test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2077 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
2079 git ls-files -s >out &&
2080 test_line_count = 6 out &&
2081 git ls-files -u >out &&
2082 test_line_count = 2 out &&
2083 git ls-files -o >out &&
2084 test_line_count = 1 out &&
2086 git rev-parse >actual \
2087 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
2088 git rev-parse >expect \
2089 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d
2091 git ls-files -s >out &&
2092 test_line_count = 5 out &&
2093 git ls-files -u >out &&
2094 test_line_count = 1 out &&
2095 git ls-files -o >out &&
2096 test_line_count = 2 out &&
2098 git rev-parse >actual \
2099 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2100 git rev-parse >expect \
2101 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d
2103 test_cmp expect actual &&
2105 git hash-object y/d~B^0 >actual &&
2106 git rev-parse O:x/d >expect &&
2107 test_cmp expect actual
2111 ###########################################################################
2112 # SECTION 8: Suboptimal merges
2114 # As alluded to in the last section, the ruleset we have built up for
2115 # detecting directory renames unfortunately has some special cases where it
2116 # results in slightly suboptimal or non-intuitive behavior. This section
2117 # explores these cases.
2119 # To be fair, we already had non-intuitive or suboptimal behavior for most
2120 # of these cases in git before introducing implicit directory rename
2121 # detection, but it'd be nice if there was a modified ruleset out there
2122 # that handled these cases a bit better.
2123 ###########################################################################
2125 # Testcase 8a, Dual-directory rename, one into the others' way
2126 # Commit O. x/{a,b}, y/{c,d}
2127 # Commit A. x/{a,b,e}, y/{c,d,f}
2128 # Commit B. y/{a,b}, z/{c,d}
2130 # Possible Resolutions:
2131 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2132 # Currently expected: y/{a,b,e,f}, z/{c,d}
2133 # Optimal: y/{a,b,e}, z/{c,d,f}
2135 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2136 # better with directory rename detection than git did without, but the
2137 # simple rule from section 5 prevents me from handling this as optimally as
2138 # we potentially could.
2153 git commit
-m "O" &&
2164 git commit
-m "A" &&
2174 test_expect_success
'8a: Dual-directory rename, one into the others way' '
2181 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2183 git ls-files -s >out &&
2184 test_line_count = 6 out &&
2185 git ls-files -u >out &&
2186 test_line_count = 0 out &&
2187 git ls-files -o >out &&
2188 test_line_count = 1 out &&
2190 git rev-parse >actual \
2191 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2192 git rev-parse >expect \
2193 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2194 test_cmp expect actual
2198 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2199 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2200 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2201 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2203 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2204 # Currently expected: <same>
2205 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2206 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2208 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2209 # y, both are named 'e'. Without directory rename detection, neither file
2210 # moves directories. Implement directory rename detection suboptimally, and
2211 # you get an add/add conflict, but both files were added in commit A, so this
2212 # is an add/add conflict where one side of history added both files --
2213 # something we can't represent in the index. Obviously, we'd prefer the last
2214 # resolution, but our previous rules are too coarse to allow it. Using both
2215 # the rules from section 4 and section 5 save us from the Scary resolution,
2216 # making us fall back to pre-directory-rename-detection behavior for both
2232 git commit
-m "O" &&
2243 git commit
-m "A" &&
2253 test_expect_success
'8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2260 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2262 git ls-files -s >out &&
2263 test_line_count = 6 out &&
2264 git ls-files -u >out &&
2265 test_line_count = 0 out &&
2266 git ls-files -o >out &&
2267 test_line_count = 1 out &&
2269 git rev-parse >actual \
2270 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2271 git rev-parse >expect \
2272 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2273 test_cmp expect actual
2277 # Testcase 8c, modify/delete or rename+modify/delete?
2278 # (Related to testcases 5b, 8d, and 9h)
2279 # Commit O: z/{b,c,d}
2281 # Commit B: z/{b,c,d_modified,e}
2282 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2284 # Note: It could easily be argued that the correct resolution here is
2285 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2286 # and that the modified version of d should be present in y/ after
2287 # the merge, just marked as conflicted. Indeed, I previously did
2288 # argue that. But applying directory renames to the side of
2289 # history where a file is merely modified results in spurious
2290 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2301 test_seq
1 10 >z
/d
&&
2304 git commit
-m "O" &&
2314 git commit
-m "A" &&
2318 test_chmod
+x z
/d
&&
2326 test_expect_success
'8c: modify/delete or rename+modify/delete' '
2333 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2334 test_grep "CONFLICT (modify/delete).* z/d" out &&
2336 git ls-files -s >out &&
2337 test_line_count = 5 out &&
2338 git ls-files -u >out &&
2339 test_line_count = 2 out &&
2340 git ls-files -o >out &&
2341 test_line_count = 1 out &&
2343 git rev-parse >actual \
2344 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2345 git rev-parse >expect \
2346 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2347 test_cmp expect actual &&
2349 test_must_fail git rev-parse :2:z/d &&
2350 git ls-files -s z/d | grep ^100755 &&
2351 test_path_is_file z/d &&
2352 test_path_is_missing y/d
2356 # Testcase 8d, rename/delete...or not?
2357 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2358 # Also related to testcases 7d and 7e)
2359 # Commit O: z/{b,c,d}
2361 # Commit B: z/{b,c,d,e}
2362 # Expected: y/{b,c,e}
2364 # Note: It would also be somewhat reasonable to resolve this as
2365 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2367 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2368 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2369 # delete) are both coming from commit A, which is illogical. Conflicts
2370 # during merging are supposed to be about opposite sides doing things
2381 test_seq
1 10 >z
/d
&&
2384 git commit
-m "O" &&
2394 git commit
-m "A" &&
2404 test_expect_success
'8d: rename/delete...or not?' '
2411 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2413 git ls-files -s >out &&
2414 test_line_count = 3 out &&
2416 git rev-parse >actual \
2417 HEAD:y/b HEAD:y/c HEAD:y/e &&
2418 git rev-parse >expect \
2419 O:z/b O:z/c B:z/e &&
2420 test_cmp expect actual
2424 # Testcase 8e, Both sides rename, one side adds to original directory
2427 # Commit B: w/{b,c}, z/d
2429 # Possible Resolutions:
2430 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2431 # CONFLICT(z/c -> y/c vs. w/c)
2432 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2433 # CONFLICT(z/c -> y/c vs. w/c)
2436 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2437 # did NOT get renamed; the directory is still present; instead it is
2438 # considered to have just renamed a subset of paths in directory z
2439 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2440 # the original paths out of z/ but opted to keep d within z/).
2442 # It was not clear in the past what should be done with this testcase;
2443 # in fact, I noted that I "just picked one" previously. However,
2444 # following the new logic for testcase 6b2, we should take the rename
2445 # and move z/d to y/d.
2447 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2448 # whether they are optimal for end users, but (a) the default for
2449 # directory rename detection is to mark these all as conflicts
2450 # anyway, (b) it feels like this is less prone to higher order corner
2451 # case confusion, and (c) the current algorithm requires less global
2452 # knowledge (i.e. less coupling in the algorithm between renames done
2453 # on both sides) which thus means users are better able to predict
2454 # the behavior, and predict it without computing as many details.
2466 git commit
-m "O" &&
2475 git commit
-m "A" &&
2487 test_expect_success
'8e: Both sides rename, one side adds to original directory' '
2494 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2495 test_grep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2496 test_grep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2498 git ls-files -s >out &&
2499 test_line_count = 7 out &&
2500 git ls-files -u >out &&
2501 test_line_count = 6 out &&
2502 git ls-files -o >out &&
2503 test_line_count = 2 out &&
2505 git rev-parse >actual \
2506 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2507 git rev-parse >expect \
2508 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2509 test_cmp expect actual &&
2511 git hash-object >actual \
2513 git rev-parse >expect \
2514 O:z/b O:z/b O:z/c O:z/c &&
2515 test_cmp expect actual &&
2517 test_path_is_missing z/b &&
2518 test_path_is_missing z/c
2522 ###########################################################################
2523 # SECTION 9: Other testcases
2525 # This section consists of miscellaneous testcases I thought of during
2526 # the implementation which round out the testing.
2527 ###########################################################################
2529 # Testcase 9a, Inner renamed directory within outer renamed directory
2530 # (Related to testcase 1f)
2531 # Commit O: z/{b,c,d/{e,f,g}}
2532 # Commit A: y/{b,c}, x/w/{e,f,g}
2533 # Commit B: z/{b,c,d/{e,f,g,h},i}
2534 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2535 # NOTE: The only reason this one is interesting is because when a directory
2536 # is split into multiple other directories, we determine by the weight
2537 # of which one had the most paths going to it. A naive implementation
2538 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2553 git commit
-m "O" &&
2564 git commit
-m "A" &&
2575 test_expect_success
'9a: Inner renamed directory within outer renamed directory' '
2582 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2584 git ls-files -s >out &&
2585 test_line_count = 7 out &&
2586 git ls-files -u >out &&
2587 test_line_count = 0 out &&
2588 git ls-files -o >out &&
2589 test_line_count = 1 out &&
2591 git rev-parse >actual \
2592 HEAD:y/b HEAD:y/c HEAD:y/i &&
2593 git rev-parse >expect \
2594 O:z/b O:z/c B:z/i &&
2595 test_cmp expect actual &&
2597 git rev-parse >actual \
2598 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2599 git rev-parse >expect \
2600 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2601 test_cmp expect actual
2605 # Testcase 9b, Transitive rename with content merge
2606 # (Related to testcase 1c)
2607 # Commit O: z/{b,c}, x/d_1
2608 # Commit A: y/{b,c}, x/d_2
2609 # Commit B: z/{b,c,d_3}
2610 # Expected: y/{b,c,d_merged}
2621 test_seq
1 10 >x
/d
&&
2624 git commit
-m "O" &&
2632 test_seq
1 11 >x
/d
&&
2635 git commit
-m "A" &&
2638 test_seq
0 10 >x
/d
&&
2646 test_expect_success
'9b: Transitive rename with content merge' '
2653 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2655 git ls-files -s >out &&
2656 test_line_count = 3 out &&
2658 test_seq 0 11 >expected &&
2659 test_cmp expected y/d &&
2661 git rev-parse >actual \
2662 HEAD:y/b HEAD:y/c HEAD:y/d &&
2663 git rev-parse >expect \
2664 O:z/b O:z/c :0:expected &&
2665 test_cmp expect actual &&
2666 test_must_fail git rev-parse HEAD:x/d &&
2667 test_must_fail git rev-parse HEAD:z/d &&
2668 test_path_is_missing z/d &&
2670 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2671 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2672 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2676 # Testcase 9c, Doubly transitive rename?
2677 # (Related to testcase 1c, 7e, and 9d)
2678 # Commit O: z/{b,c}, x/{d,e}, w/f
2679 # Commit A: y/{b,c}, x/{d,e,f,g}
2680 # Commit B: z/{b,c,d,e}, w/f
2681 # Expected: y/{b,c,d,e}, x/{f,g}
2683 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2684 # x/f is clear. Let's look beyond that. Here's the logic:
2685 # Commit B renamed x/ -> z/
2686 # Commit A renamed z/ -> y/
2687 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2688 # transient rename. However, where does it end? We can chain these
2689 # indefinitely (see testcase 9d). What if there is a D/F conflict
2690 # at z/f/ or y/f/? Or just another file conflict at one of those
2691 # paths? In the case of an N-long chain of transient renamings,
2692 # where do we "abort" the rename at? Can the user make sense of
2693 # the resulting conflict and resolve it?
2695 # To avoid this confusion I use the simple rule that if the other side
2696 # of history did a directory rename to a path that your side renamed
2697 # away, then ignore that particular rename from the other side of
2698 # history for any implicit directory renames.
2715 git commit
-m "O" &&
2727 git commit
-m "A" &&
2737 test_expect_success
'9c: Doubly transitive rename?' '
2744 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2745 test_grep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2747 git ls-files -s >out &&
2748 test_line_count = 6 out &&
2749 git ls-files -o >out &&
2750 test_line_count = 1 out &&
2752 git rev-parse >actual \
2753 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2754 git rev-parse >expect \
2755 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2756 test_cmp expect actual
2760 # Testcase 9d, N-fold transitive rename?
2761 # (Related to testcase 9c...and 1c and 7e)
2762 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2763 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2764 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2765 # Expected: <see NOTE first>
2767 # NOTE: z/ -> y/ (in commit A)
2768 # y/ -> x/ (in commit B)
2769 # x/ -> w/ (in commit A)
2770 # w/ -> v/ (in commit B)
2771 # v/ -> u/ (in commit A)
2772 # So, if we add a file to z, say z/t, where should it end up? In u?
2773 # What if there's another file or directory named 't' in one of the
2774 # intervening directories and/or in u itself? Also, shouldn't the
2775 # same logic that places 't' in u/ also move ALL other files to u/?
2776 # What if there are file or directory conflicts in any of them? If
2777 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2778 # like this, would the user have any hope of understanding any
2779 # conflicts or how their working tree ended up? I think not, so I'm
2780 # ruling out N-ary transitive renames for N>1.
2782 # Therefore our expected result is:
2783 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2784 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2785 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2786 # simple rules that are consistent with what we need for all the other
2787 # testcases and simplifies things for the user.
2794 mkdir z y x w v u
&&
2801 git add z y x w v u
&&
2803 git commit
-m "O" &&
2814 git commit
-m "A" &&
2826 test_expect_success
'9d: N-way transitive rename?' '
2833 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2834 test_grep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2835 test_grep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2836 test_grep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2837 test_grep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2839 git ls-files -s >out &&
2840 test_line_count = 7 out &&
2841 git ls-files -o >out &&
2842 test_line_count = 1 out &&
2844 git rev-parse >actual \
2846 HEAD:y/a HEAD:x/b HEAD:w/c \
2847 HEAD:u/d HEAD:u/e HEAD:u/f &&
2848 git rev-parse >expect \
2851 O:w/d O:v/e A:u/f &&
2852 test_cmp expect actual
2856 # Testcase 9e, N-to-1 whammo
2857 # (Related to testcase 9c...and 1c and 7e)
2858 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2859 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2860 # Commit B: combined/{a,b,d,e,g,h,j,k}
2861 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2862 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2869 mkdir dir1 dir2 dir3 dirN
&&
2880 git commit
-m "O" &&
2897 git commit
-m "A" &&
2900 git
mv dir1 combined
&&
2901 git
mv dir
2/* combined
/ &&
2902 git
mv dir
3/* combined
/ &&
2903 git
mv dirN
/* combined
/ &&
2909 test_expect_success
'9e: N-to-1 whammo' '
2916 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2917 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2918 grep -q dir1/yo error_line &&
2919 grep -q dir2/yo error_line &&
2920 grep -q dir3/yo error_line &&
2921 grep -q dirN/yo error_line &&
2923 git ls-files -s >out &&
2924 test_line_count = 16 out &&
2925 git ls-files -u >out &&
2926 test_line_count = 0 out &&
2927 git ls-files -o >out &&
2928 test_line_count = 2 out &&
2930 git rev-parse >actual \
2931 :0:combined/a :0:combined/b :0:combined/c \
2932 :0:combined/d :0:combined/e :0:combined/f \
2933 :0:combined/g :0:combined/h :0:combined/i \
2934 :0:combined/j :0:combined/k :0:combined/l &&
2935 git rev-parse >expect \
2936 O:dir1/a O:dir1/b A:dir1/c \
2937 O:dir2/d O:dir2/e A:dir2/f \
2938 O:dir3/g O:dir3/h A:dir3/i \
2939 O:dirN/j O:dirN/k A:dirN/l &&
2940 test_cmp expect actual &&
2942 git rev-parse >actual \
2943 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2944 git rev-parse >expect \
2945 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2946 test_cmp expect actual
2950 # Testcase 9f, Renamed directory that only contained immediate subdirs
2951 # (Related to testcases 1e & 9g)
2952 # Commit O: goal/{a,b}/$more_files
2953 # Commit A: priority/{a,b}/$more_files
2954 # Commit B: goal/{a,b}/$more_files, goal/c
2955 # Expected: priority/{a,b}/$more_files, priority/c
2964 echo foo
>goal
/a
/foo
&&
2965 echo bar
>goal
/b
/bar
&&
2966 echo baz
>goal
/b
/baz
&&
2969 git commit
-m "O" &&
2976 git
mv goal
/ priority
&&
2978 git commit
-m "A" &&
2988 test_expect_success
'9f: Renamed directory that only contained immediate subdirs' '
2995 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2997 git ls-files -s >out &&
2998 test_line_count = 4 out &&
3000 git rev-parse >actual \
3001 HEAD:priority/a/foo \
3002 HEAD:priority/b/bar \
3003 HEAD:priority/b/baz \
3005 git rev-parse >expect \
3010 test_cmp expect actual &&
3011 test_must_fail git rev-parse HEAD:goal/c
3015 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
3016 # (Related to testcases 1e & 9f)
3017 # Commit O: goal/{a,b}/$more_files
3018 # Commit A: priority/{alpha,bravo}/$more_files
3019 # Commit B: goal/{a,b}/$more_files, goal/c
3020 # Expected: priority/{alpha,bravo}/$more_files, priority/c
3021 # We currently fail this test because the directory renames we detect are
3022 # goal/a/ -> priority/alpha/
3023 # goal/b/ -> priority/bravo/
3025 # goal/ -> priority/
3026 # because of no files found within goal/, and the fact that "a" != "alpha"
3027 # and "b" != "bravo". But I'm not sure it's really a failure given that
3037 echo foo
>goal
/a
/foo
&&
3038 echo bar
>goal
/b
/bar
&&
3039 echo baz
>goal
/b
/baz
&&
3042 git commit
-m "O" &&
3050 git
mv goal
/a
/ priority
/alpha
&&
3051 git
mv goal
/b
/ priority
/beta
&&
3054 git commit
-m "A" &&
3064 test_expect_failure
'9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
3071 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3073 git ls-files -s >out &&
3074 test_line_count = 4 out &&
3076 git rev-parse >actual \
3077 HEAD:priority/alpha/foo \
3078 HEAD:priority/beta/bar \
3079 HEAD:priority/beta/baz \
3081 git rev-parse >expect \
3086 test_cmp expect actual &&
3087 test_must_fail git rev-parse HEAD:goal/c
3091 # Testcase 9h, Avoid implicit rename if involved as source on other side
3092 # (Extremely closely related to testcase 3a)
3093 # Commit O: z/{b,c,d_1}
3094 # Commit A: z/{b,c,d_2}
3095 # Commit B: y/{b,c}, x/d_1
3096 # Expected: y/{b,c}, x/d_2
3097 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3098 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3107 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z
/d
&&
3110 git commit
-m "O" &&
3120 git commit
-m "A" &&
3134 test_expect_success
'9h: Avoid dir rename on merely modified path' '
3141 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3143 git ls-files -s >out &&
3144 test_line_count = 3 out &&
3146 git rev-parse >actual \
3147 HEAD:y/b HEAD:y/c HEAD:x/d &&
3148 git rev-parse >expect \
3149 O:z/b O:z/c A:z/d &&
3150 test_cmp expect actual
3154 ###########################################################################
3155 # Rules suggested by section 9:
3157 # If the other side of history did a directory rename to a path that your
3158 # side renamed away, then ignore that particular rename from the other
3159 # side of history for any implicit directory renames.
3160 ###########################################################################
3162 ###########################################################################
3163 # SECTION 10: Handling untracked files
3165 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3166 # the operation if untracked or dirty files would be deleted or overwritten
3167 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3168 # and if it doesn't abort, then it muddies up the working directory before
3169 # we even get to the point of detecting renames, so we need some special
3170 # handling, at least in the case of directory renames.
3171 ###########################################################################
3173 # Testcase 10a, Overwrite untracked: normal rename/delete
3174 # Commit O: z/{b,c_1}
3175 # Commit A: z/b + untracked z/c + untracked z/d
3176 # Commit B: z/{b,d_1}
3177 # Expected: Aborted Merge +
3178 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3190 git commit
-m "O" &&
3199 git commit
-m "A" &&
3208 test_expect_success
'10a: Overwrite untracked with normal rename/delete' '
3215 echo important >z/d &&
3217 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3218 test_path_is_missing .git/MERGE_HEAD &&
3219 test_grep "The following untracked working tree files would be overwritten by merge" err &&
3221 git ls-files -s >out &&
3222 test_line_count = 1 out &&
3223 git ls-files -o >out &&
3224 test_line_count = 4 out &&
3226 echo very >expect &&
3227 test_cmp expect z/c &&
3229 echo important >expect &&
3230 test_cmp expect z/d &&
3232 git rev-parse HEAD:z/b >actual &&
3233 git rev-parse O:z/b >expect &&
3234 test_cmp expect actual
3238 # Testcase 10b, Overwrite untracked: dir rename + delete
3239 # Commit O: z/{b,c_1}
3240 # Commit A: y/b + untracked y/{c,d,e}
3241 # Commit B: z/{b,d_1,e}
3242 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3243 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3244 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3256 git commit
-m "O" &&
3266 git commit
-m "A" &&
3277 test_expect_success
'10b: Overwrite untracked with dir rename + delete' '
3284 echo important >y/d &&
3285 echo contents >y/e &&
3287 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3288 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3290 test_path_is_missing .git/MERGE_HEAD &&
3291 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3293 git ls-files -s >out &&
3294 test_line_count = 1 out &&
3295 git ls-files -u >out &&
3296 test_line_count = 0 out &&
3297 git ls-files -o >out &&
3298 test_line_count = 5 out
3300 test_grep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3301 test_grep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3303 git ls-files -s >out &&
3304 test_line_count = 3 out &&
3305 git ls-files -u >out &&
3306 test_line_count = 2 out &&
3307 git ls-files -o >out &&
3308 test_line_count = 5 out &&
3310 git rev-parse >actual \
3311 :0:y/b :3:y/d :3:y/e &&
3312 git rev-parse >expect \
3313 O:z/b O:z/c B:z/e &&
3314 test_cmp expect actual
3317 echo very >expect &&
3318 test_cmp expect y/c &&
3320 echo important >expect &&
3321 test_cmp expect y/d &&
3323 echo contents >expect &&
3328 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3329 # Commit O: z/{a,b}, x/{c,d}
3330 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3331 # Commit B: z/{a,b,c}, x/d
3332 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3333 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3335 # ERROR_MSG(Refusing to lose untracked file at y/c)
3349 git commit
-m "O" &&
3360 git commit
-m "A" &&
3369 test_expect_success
'10c1: Overwrite untracked with dir rename/rename(1to2)' '
3375 echo important >y/c &&
3377 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3378 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3380 test_path_is_missing .git/MERGE_HEAD &&
3381 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3383 git ls-files -s >out &&
3384 test_line_count = 4 out &&
3385 git ls-files -u >out &&
3386 test_line_count = 0 out &&
3387 git ls-files -o >out &&
3388 test_line_count = 3 out
3390 test_grep "CONFLICT (rename/rename)" out &&
3391 test_grep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3393 git ls-files -s >out &&
3394 test_line_count = 6 out &&
3395 git ls-files -u >out &&
3396 test_line_count = 3 out &&
3397 git ls-files -o >out &&
3398 test_line_count = 3 out &&
3400 git rev-parse >actual \
3401 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3402 git rev-parse >expect \
3403 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3404 test_cmp expect actual &&
3406 git hash-object y/c~B^0 >actual &&
3407 git rev-parse O:x/c >expect &&
3408 test_cmp expect actual
3411 echo important >expect &&
3416 test_expect_success
'10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3426 echo important >y/c &&
3428 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3429 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3431 test_path_is_missing .git/MERGE_HEAD &&
3432 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3434 git ls-files -s >out &&
3435 test_line_count = 4 out &&
3436 git ls-files -u >out &&
3437 test_line_count = 0 out &&
3438 git ls-files -o >out &&
3439 test_line_count = 3 out
3441 test_grep "CONFLICT (rename/rename)" out &&
3442 test_grep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3444 git ls-files -s >out &&
3445 test_line_count = 6 out &&
3446 git ls-files -u >out &&
3447 test_line_count = 3 out &&
3448 git ls-files -o >out &&
3449 test_line_count = 3 out &&
3451 git rev-parse >actual \
3452 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3453 git rev-parse >expect \
3454 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3455 test_cmp expect actual &&
3457 git hash-object y/c~HEAD >actual &&
3458 git rev-parse O:x/c >expect &&
3459 test_cmp expect actual
3462 echo important >expect &&
3467 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3468 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3469 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3470 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3471 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3472 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3473 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3489 git commit
-m "O" &&
3496 git
mv z
/c x
/wham
&&
3499 git commit
-m "A" &&
3502 git
mv x
/f z
/wham
&&
3509 test_expect_success
'10d: Delete untracked with dir rename/rename(2to1)' '
3515 echo important >y/wham &&
3517 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3518 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3520 test_path_is_missing .git/MERGE_HEAD &&
3521 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3523 git ls-files -s >out &&
3524 test_line_count = 6 out &&
3525 git ls-files -u >out &&
3526 test_line_count = 0 out &&
3527 git ls-files -o >out &&
3528 test_line_count = 3 out
3530 test_grep "CONFLICT (rename/rename)" out &&
3531 test_grep "Refusing to lose untracked file at y/wham" out &&
3533 git ls-files -s >out &&
3534 test_line_count = 6 out &&
3535 git ls-files -u >out &&
3536 test_line_count = 2 out &&
3537 git ls-files -o >out &&
3538 test_line_count = 3 out &&
3540 git rev-parse >actual \
3541 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3542 git rev-parse >expect \
3543 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3544 test_cmp expect actual &&
3546 test_must_fail git rev-parse :1:y/wham &&
3548 # Test that two-way merge in y/wham~merged is as expected
3549 git cat-file -p :2:y/wham >expect &&
3550 git cat-file -p :3:y/wham >other &&
3552 test_must_fail git merge-file \
3556 expect empty other &&
3557 test_cmp expect y/wham~merged
3560 echo important >expect &&
3561 test_cmp expect y/wham
3565 # Testcase 10e, Does git complain about untracked file that's not in the way?
3567 # Commit A: y/{a,b} + untracked z/c
3568 # Commit B: z/{a,b,c}
3569 # Expected: y/{a,b,c} + untracked z/c
3581 git commit
-m "O" &&
3590 git commit
-m "A" &&
3600 test_expect_merge_algorithm failure success
'10e: Does git complain about untracked file that is not really in the way?' '
3609 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3610 test_grep ! "following untracked working tree files would be overwritten by merge" err &&
3612 git ls-files -s >out &&
3613 test_line_count = 3 out &&
3614 git ls-files -u >out &&
3615 test_line_count = 0 out &&
3616 git ls-files -o >out &&
3617 test_line_count = 3 out &&
3619 git rev-parse >actual \
3620 :0:y/a :0:y/b :0:y/c &&
3621 git rev-parse >expect \
3622 O:z/a O:z/b B:z/c &&
3623 test_cmp expect actual &&
3625 echo random >expect &&
3630 ###########################################################################
3631 # SECTION 11: Handling dirty (not up-to-date) files
3633 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3634 # the operation if untracked or dirty files would be deleted or overwritten
3635 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3636 # and if it doesn't abort, then it muddies up the working directory before
3637 # we even get to the point of detecting renames, so we need some special
3638 # handling. This was true even of normal renames, but there are additional
3639 # codepaths that need special handling with directory renames. Add
3640 # testcases for both renamed-by-directory-rename-detection and standard
3642 ###########################################################################
3644 # Testcase 11a, Avoid losing dirty contents with simple rename
3645 # Commit O: z/{a,b_v1},
3646 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3647 # Commit B: z/{a,b_v2}
3648 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3649 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3650 # z/c~HEAD with contents of B:z/b_v2,
3651 # z/c with uncommitted mods on top of A:z/c_v1
3660 test_seq
1 10 >z
/b
&&
3663 git commit
-m "O" &&
3672 git commit
-m "A" &&
3682 test_expect_success
'11a: Avoid losing dirty contents with simple rename' '
3690 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3691 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3693 test_path_is_missing .git/MERGE_HEAD &&
3694 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3696 test_grep "Refusing to lose dirty file at z/c" out &&
3698 git ls-files -s >out &&
3699 test_line_count = 2 out &&
3700 git ls-files -u >out &&
3701 test_line_count = 1 out &&
3702 git ls-files -o >out &&
3703 test_line_count = 3 out &&
3705 git rev-parse >actual \
3707 git rev-parse >expect \
3709 test_cmp expect actual &&
3711 git hash-object z/c~HEAD >actual &&
3712 git rev-parse B:z/b >expect &&
3713 test_cmp expect actual
3716 test_seq 1 10 >expected &&
3717 echo stuff >>expected &&
3718 test_cmp expected z/c
3723 # Testcase 11b, Avoid losing dirty file involved in directory rename
3724 # Commit O: z/a, x/{b,c_v1}
3725 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3726 # Commit B: y/a, x/{b,c_v2}
3727 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3728 # ERROR_MSG(Refusing to lose dirty file at z/c)
3739 test_seq
1 10 >x
/c
&&
3742 git commit
-m "O" &&
3751 git commit
-m "A" &&
3762 test_expect_success
'11b: Avoid losing dirty file involved in directory rename' '
3770 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3772 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3773 test_path_is_missing .git/MERGE_HEAD &&
3774 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3776 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3777 test_grep "Refusing to lose dirty file at z/c" out &&
3779 git ls-files -s >out &&
3780 test_line_count = 3 out &&
3781 git ls-files -u >out &&
3782 test_line_count = 0 out &&
3783 git ls-files -m >out &&
3784 test_line_count = 0 out &&
3785 git ls-files -o >out &&
3786 test_line_count = 3 out &&
3788 git rev-parse >actual \
3789 :0:x/b :0:y/a :0:y/c &&
3790 git rev-parse >expect \
3791 O:x/b O:z/a B:x/c &&
3792 test_cmp expect actual &&
3794 git hash-object y/c >actual &&
3795 git rev-parse B:x/c >expect &&
3796 test_cmp expect actual
3799 grep -q stuff z/c &&
3800 test_seq 1 10 >expected &&
3801 echo stuff >>expected &&
3802 test_cmp expected z/c
3806 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3807 # Commit O: y/a, x/{b,c_v1}
3808 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3809 # Commit B: y/{a,c/d}, x/{b,c_v2}
3810 # Expected: Abort_msg("following files would be overwritten by merge") +
3811 # y/c left untouched (still has uncommitted mods)
3821 test_seq
1 10 >x
/c
&&
3824 git commit
-m "O" &&
3833 git commit
-m "A" &&
3839 git add x
/c y
/c
/d
&&
3845 test_expect_success
'11c: 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 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3856 test_path_is_missing .git/MERGE_HEAD &&
3857 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3859 test_grep "following files would be overwritten by merge" err
3862 grep -q stuff y/c &&
3863 test_seq 1 10 >expected &&
3864 echo stuff >>expected &&
3865 test_cmp expected y/c &&
3867 git ls-files -s >out &&
3868 test_line_count = 3 out &&
3869 git ls-files -u >out &&
3870 test_line_count = 0 out &&
3871 git ls-files -m >out &&
3872 test_line_count = 1 out &&
3873 git ls-files -o >out &&
3874 test_line_count = 3 out
3878 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3879 # Commit O: z/a, x/{b,c_v1}
3880 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3881 # Commit B: y/{a,c/d}, x/{b,c_v2}
3882 # Expected: D/F: y/c_v2 vs y/c/d) +
3883 # Warning_Msg("Refusing to lose dirty file at z/c) +
3884 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3894 test_seq
1 10 >x
/c
&&
3897 git commit
-m "O" &&
3906 git commit
-m "A" &&
3913 git add x
/c y
/c
/d
&&
3919 test_expect_success
'11d: Avoid losing not-uptodate with rename + D/F conflict' '
3927 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3928 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3930 test_path_is_missing .git/MERGE_HEAD &&
3931 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3933 test_grep "Refusing to lose dirty file at z/c" out &&
3935 git ls-files -s >out &&
3936 test_line_count = 4 out &&
3937 git ls-files -u >out &&
3938 test_line_count = 1 out &&
3939 git ls-files -o >out &&
3940 test_line_count = 4 out &&
3942 git rev-parse >actual \
3943 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3944 git rev-parse >expect \
3945 O:x/b O:z/a B:y/c/d B:x/c &&
3946 test_cmp expect actual &&
3948 git hash-object y/c~HEAD >actual &&
3949 git rev-parse B:x/c >expect &&
3950 test_cmp expect actual
3953 grep -q stuff z/c &&
3954 test_seq 1 10 >expected &&
3955 echo stuff >>expected &&
3956 test_cmp expected z/c
3960 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3961 # Commit O: z/{a,b}, x/{c_1,d}
3962 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3963 # Commit B: z/{a,b,c_1}, x/d
3964 # Expected: Failed Merge; y/{a,b} + x/d +
3965 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3966 # ERROR_MSG(Refusing to lose dirty file at y/c)
3967 # y/c~B^0 has O:x/c_1 contents
3968 # y/c~HEAD has A:y/c_2 contents
3969 # y/c has dirty file from before merge
3983 git commit
-m "O" &&
3991 echo different
>y
/c
&&
3996 git commit
-m "A" &&
4005 test_expect_success
'11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
4013 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4014 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4016 test_path_is_missing .git/MERGE_HEAD &&
4017 test_grep "error: Your local changes to the following files would be overwritten by merge" err
4019 test_grep "CONFLICT (rename/rename)" out &&
4020 test_grep "Refusing to lose dirty file at y/c" out &&
4022 git ls-files -s >out &&
4023 test_line_count = 7 out &&
4024 git ls-files -u >out &&
4025 test_line_count = 4 out &&
4026 git ls-files -o >out &&
4027 test_line_count = 3 out &&
4029 git rev-parse >actual \
4030 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
4031 git rev-parse >expect \
4032 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
4033 test_cmp expect actual &&
4035 # See if y/c~merged has expected contents; requires manually
4036 # doing the expected file merge
4037 git cat-file -p A:y/c >c1 &&
4038 git cat-file -p B:z/c >c2 &&
4040 test_must_fail git merge-file \
4045 test_cmp c1 y/c~merged
4048 echo different >expected &&
4049 echo mods >>expected &&
4050 test_cmp expected y/c
4054 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
4055 # Commit O: z/{a,b}, x/{c_1,d_2}
4056 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
4057 # Commit B: z/{a,b,wham_2}, x/c_1
4058 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
4059 # y/wham with dirty changes from before merge +
4060 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
4061 # ERROR_MSG(Refusing to lose dirty file at y/wham)
4071 test_seq
1 10 >x
/c
&&
4075 git commit
-m "O" &&
4083 git
mv x
/c y
/wham
&&
4085 git commit
-m "A" &&
4088 git
mv x
/d z
/wham
&&
4094 test_expect_success
'11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
4100 echo important >>y/wham &&
4102 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4103 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4105 test_path_is_missing .git/MERGE_HEAD &&
4106 test_grep "error: Your local changes to the following files would be overwritten by merge" err
4108 test_grep "CONFLICT (rename/rename)" out &&
4109 test_grep "Refusing to lose dirty file at y/wham" out &&
4111 git ls-files -s >out &&
4112 test_line_count = 4 out &&
4113 git ls-files -u >out &&
4114 test_line_count = 2 out &&
4115 git ls-files -o >out &&
4116 test_line_count = 3 out &&
4118 test_must_fail git rev-parse :1:y/wham &&
4120 git rev-parse >actual \
4121 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4122 git rev-parse >expect \
4123 O:z/a O:z/b O:x/c O:x/d &&
4124 test_cmp expect actual &&
4126 # Test that two-way merge in y/wham~merged is as expected
4127 git cat-file -p :2:y/wham >expect &&
4128 git cat-file -p :3:y/wham >other &&
4130 test_must_fail git merge-file \
4134 expect empty other &&
4135 test_cmp expect y/wham~merged
4138 test_seq 1 10 >expected &&
4139 echo important >>expected &&
4140 test_cmp expected y/wham
4144 ###########################################################################
4145 # SECTION 12: Everything else
4147 # Tests suggested by others. Tests added after implementation completed
4148 # and submitted. Grab bag.
4149 ###########################################################################
4151 # Testcase 12a, Moving one directory hierarchy into another
4152 # (Related to testcase 9a)
4153 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
4154 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
4155 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
4156 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
4163 mkdir
-p node1 node2
&&
4164 echo leaf1
>node
1/leaf1
&&
4165 echo leaf2
>node
1/leaf2
&&
4166 echo leaf3
>node
2/leaf3
&&
4167 echo leaf4
>node
2/leaf4
&&
4168 git add node1 node2
&&
4170 git commit
-m "O" &&
4177 git
mv node
2/ node
1/ &&
4179 git commit
-m "A" &&
4182 echo leaf5
>node
1/leaf5
&&
4183 echo leaf6
>node
2/leaf6
&&
4184 git add node1 node2
&&
4190 test_expect_success
'12a: Moving one directory hierarchy into another' '
4197 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4199 git ls-files -s >out &&
4200 test_line_count = 6 out &&
4202 git rev-parse >actual \
4203 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4204 HEAD:node1/node2/leaf3 \
4205 HEAD:node1/node2/leaf4 \
4206 HEAD:node1/node2/leaf6 &&
4207 git rev-parse >expect \
4208 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4212 test_cmp expect actual
4216 # Testcase 12b1, Moving two directory hierarchies into each other
4217 # (Related to testcases 1c and 12c)
4218 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4219 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4220 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4221 # Expected: node1/node2/{leaf3, leaf4}
4222 # node2/node1/{leaf1, leaf2}
4223 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4224 # then we would need to detect renames for those directories and would
4226 # commit A renames node2/ -> node1/node2/
4227 # commit B renames node1/ -> node2/node1/
4228 # Applying those directory renames to the initial result (making all
4229 # four paths experience a transitive renaming), yields
4230 # node1/node2/node1/{leaf1, leaf2}
4231 # node2/node1/node2/{leaf3, leaf4}
4232 # as the result. It may be really weird to have two directories
4233 # rename each other, but simple rules give weird results when given
4234 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4235 # false; there were no new files added and thus there is no directory
4236 # rename detection to perform. As such, we just have simple renames
4237 # and the expected answer is:
4238 # node1/node2/{leaf3, leaf4}
4239 # node2/node1/{leaf1, leaf2}
4241 test_setup_12b1
() {
4246 mkdir
-p node1 node2
&&
4247 echo leaf1
>node
1/leaf1
&&
4248 echo leaf2
>node
1/leaf2
&&
4249 echo leaf3
>node
2/leaf3
&&
4250 echo leaf4
>node
2/leaf4
&&
4251 git add node1 node2
&&
4253 git commit
-m "O" &&
4260 git
mv node
2/ node
1/ &&
4262 git commit
-m "A" &&
4265 git
mv node
1/ node
2/ &&
4271 test_expect_merge_algorithm failure success
'12b1: Moving two directory hierarchies into each other' '
4278 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4280 git ls-files -s >out &&
4281 test_line_count = 4 out &&
4283 git rev-parse >actual \
4284 HEAD:node2/node1/leaf1 \
4285 HEAD:node2/node1/leaf2 \
4286 HEAD:node1/node2/leaf3 \
4287 HEAD:node1/node2/leaf4 &&
4288 git rev-parse >expect \
4293 test_cmp expect actual
4297 # Testcase 12b2, Moving two directory hierarchies into each other
4298 # (Related to testcases 1c and 12c)
4299 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4300 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4301 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4302 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4303 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4304 # NOTE: Without directory renames, we would expect
4305 # A: node2/leaf3 -> node1/node2/leaf3
4306 # A: node2/leaf1 -> node1/node2/leaf4
4307 # A: Adds node1/leaf5
4308 # B: node1/leaf1 -> node2/node1/leaf1
4309 # B: node1/leaf2 -> node2/node1/leaf2
4310 # B: Adds node2/leaf6
4311 # with directory rename detection, we note that
4312 # commit A renames node2/ -> node1/node2/
4313 # commit B renames node1/ -> node2/node1/
4314 # therefore, applying A's directory rename to the paths added in B gives:
4315 # B: node1/leaf1 -> node1/node2/node1/leaf1
4316 # B: node1/leaf2 -> node1/node2/node1/leaf2
4317 # B: Adds node1/node2/leaf6
4318 # and applying B's directory rename to the paths added in A gives:
4319 # A: node2/leaf3 -> node2/node1/node2/leaf3
4320 # A: node2/leaf1 -> node2/node1/node2/leaf4
4321 # A: Adds node2/node1/leaf5
4322 # resulting in the expected
4323 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4324 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4326 # You may ask, is it weird to have two directories rename each other?
4327 # To which, I can do no more than shrug my shoulders and say that
4328 # even simple rules give weird results when given weird inputs.
4330 test_setup_12b2
() {
4335 mkdir
-p node1 node2
&&
4336 echo leaf1
>node
1/leaf1
&&
4337 echo leaf2
>node
1/leaf2
&&
4338 echo leaf3
>node
2/leaf3
&&
4339 echo leaf4
>node
2/leaf4
&&
4340 git add node1 node2
&&
4342 git commit
-m "O" &&
4349 git
mv node
2/ node
1/ &&
4350 echo leaf5
>node
1/leaf5
&&
4351 git add node
1/leaf5
&&
4353 git commit
-m "A" &&
4356 git
mv node
1/ node
2/ &&
4357 echo leaf6
>node
2/leaf6
&&
4358 git add node
2/leaf6
&&
4364 test_expect_success
'12b2: Moving two directory hierarchies into each other' '
4371 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4373 git ls-files -s >out &&
4374 test_line_count = 6 out &&
4376 git rev-parse >actual \
4377 HEAD:node1/node2/node1/leaf1 \
4378 HEAD:node1/node2/node1/leaf2 \
4379 HEAD:node2/node1/node2/leaf3 \
4380 HEAD:node2/node1/node2/leaf4 \
4381 HEAD:node2/node1/leaf5 \
4382 HEAD:node1/node2/leaf6 &&
4383 git rev-parse >expect \
4390 test_cmp expect actual
4394 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4395 # (Related to testcase 12b)
4396 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4397 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4398 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4399 # Expected: Content merge conflicts for each of:
4400 # node1/node2/node1/{leaf1, leaf2},
4401 # node2/node1/node2/{leaf3, leaf4}
4402 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4403 # each side of the merge.
4405 test_setup_12c1
() {
4410 mkdir
-p node1 node2
&&
4411 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4412 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4413 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4414 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4415 git add node1 node2
&&
4417 git commit
-m "O" &&
4424 git
mv node
2/ node
1/ &&
4425 for i
in $
(git ls-files
); do echo side A
>>$i; done &&
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 &&
4439 test_expect_merge_algorithm failure success
'12c1: Moving one directory hierarchy into another w/ content merge' '
4446 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4448 git ls-files -u >out &&
4449 test_line_count = 12 out &&
4451 git rev-parse >actual \
4452 :1:node2/node1/leaf1 \
4453 :1:node2/node1/leaf2 \
4454 :1:node1/node2/leaf3 \
4455 :1:node1/node2/leaf4 \
4456 :2:node2/node1/leaf1 \
4457 :2:node2/node1/leaf2 \
4458 :2:node1/node2/leaf3 \
4459 :2:node1/node2/leaf4 \
4460 :3:node2/node1/leaf1 \
4461 :3:node2/node1/leaf2 \
4462 :3:node1/node2/leaf3 \
4463 :3:node1/node2/leaf4 &&
4464 git rev-parse >expect \
4471 A:node1/node2/leaf3 \
4472 A:node1/node2/leaf4 \
4473 B:node2/node1/leaf1 \
4474 B:node2/node1/leaf2 \
4477 test_cmp expect actual
4481 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4482 # (Related to testcase 12b)
4483 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4484 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4485 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4486 # Expected: Content merge conflicts for each of:
4487 # node1/node2/node1/{leaf1, leaf2}
4488 # node2/node1/node2/{leaf3, leaf4}
4492 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4493 # on each side of the merge.
4495 test_setup_12c2
() {
4500 mkdir
-p node1 node2
&&
4501 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4502 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4503 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4504 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4505 git add node1 node2
&&
4507 git commit
-m "O" &&
4514 git
mv node
2/ node
1/ &&
4515 for i
in $
(git ls-files
); do echo side A
>>$i; done &&
4517 echo leaf5
>node
1/leaf5
&&
4518 git add node
1/leaf5
&&
4520 git commit
-m "A" &&
4523 git
mv node
1/ node
2/ &&
4524 for i
in $
(git ls-files
); do echo side B
>>$i; done &&
4526 echo leaf6
>node
2/leaf6
&&
4527 git add node
2/leaf6
&&
4533 test_expect_success
'12c2: Moving one directory hierarchy into another w/ content merge' '
4540 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4542 git ls-files -s >out &&
4543 test_line_count = 14 out &&
4544 git ls-files -u >out &&
4545 test_line_count = 12 out &&
4547 git rev-parse >actual \
4548 :1:node1/node2/node1/leaf1 \
4549 :1:node1/node2/node1/leaf2 \
4550 :1:node2/node1/node2/leaf3 \
4551 :1:node2/node1/node2/leaf4 \
4552 :2:node1/node2/node1/leaf1 \
4553 :2:node1/node2/node1/leaf2 \
4554 :2:node2/node1/node2/leaf3 \
4555 :2:node2/node1/node2/leaf4 \
4556 :3:node1/node2/node1/leaf1 \
4557 :3:node1/node2/node1/leaf2 \
4558 :3:node2/node1/node2/leaf3 \
4559 :3:node2/node1/node2/leaf4 \
4560 :0:node2/node1/leaf5 \
4561 :0:node1/node2/leaf6 &&
4562 git rev-parse >expect \
4569 A:node1/node2/leaf3 \
4570 A:node1/node2/leaf4 \
4571 B:node2/node1/leaf1 \
4572 B:node2/node1/leaf2 \
4577 test_cmp expect actual
4581 # Testcase 12d, Rename/merge of subdirectory into the root
4582 # Commit O: a/b/subdir/foo
4583 # Commit A: subdir/foo
4584 # Commit B: a/b/subdir/foo, a/b/bar
4585 # Expected: subdir/foo, bar
4592 mkdir
-p a
/b
/subdir
&&
4593 test_commit a
/b
/subdir
/foo
&&
4601 git
mv a
/b
/subdir
/foo.t subdir
/foo.t
&&
4603 git commit
-m "A" &&
4610 test_expect_success
'12d: Rename/merge subdir into the root, variant 1' '
4617 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4619 git ls-files -s >out &&
4620 test_line_count = 2 out &&
4622 git rev-parse >actual \
4623 HEAD:subdir/foo.t HEAD:bar.t &&
4624 git rev-parse >expect \
4625 O:a/b/subdir/foo.t B:a/b/bar.t &&
4626 test_cmp expect actual &&
4628 git hash-object bar.t >actual &&
4629 git rev-parse B:a/b/bar.t >expect &&
4630 test_cmp expect actual &&
4632 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4633 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4634 test_path_is_missing a/ &&
4635 test_path_is_file bar.t
4639 # Testcase 12e, Rename/merge of subdirectory into the root
4642 # Commit B: a/b/foo, a/b/bar
4643 # Expected: foo, bar
4651 test_commit a
/b
/foo
&&
4659 git
mv a
/b
/foo.t foo.t
&&
4661 git commit
-m "A" &&
4668 test_expect_success
'12e: Rename/merge subdir into the root, variant 2' '
4675 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4677 git ls-files -s >out &&
4678 test_line_count = 2 out &&
4680 git rev-parse >actual \
4681 HEAD:foo.t HEAD:bar.t &&
4682 git rev-parse >expect \
4683 O:a/b/foo.t B:a/b/bar.t &&
4684 test_cmp expect actual &&
4686 git hash-object bar.t >actual &&
4687 git rev-parse B:a/b/bar.t >expect &&
4688 test_cmp expect actual &&
4690 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4691 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4692 test_path_is_missing a/ &&
4693 test_path_is_file bar.t
4697 # Testcase 12f, Rebase of patches with big directory rename
4699 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4700 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4701 # dir/unchanged/<LOTS OF FILES>
4703 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4704 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4705 # folder/subdir/newsubdir/e_A
4706 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4707 # folder/unchanged/<LOTS OF FILES>
4709 # (add newfile.{c,py}, modify underscored files)
4710 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4711 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4712 # dir/unchanged/<LOTS OF FILES>
4714 # (Modify e further, add newfile.rs)
4715 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4716 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4717 # dir/unchanged/<LOTS OF FILES>
4720 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4721 # folder/subdir/newsubdir/e_Merge1
4722 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4723 # folder/unchanged/<LOTS OF FILES>
4725 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4726 # folder/subdir/newsubdir/e_Merge2
4727 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4728 # folder/unchanged/<LOTS OF FILES>
4729 # Things being checked here:
4730 # 1. dir/subdir/newfile.c does not get pushed into folder/subdir/newsubdir/.
4731 # dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d} looks like
4733 # whereas dir/subdir/e -> folder/subdir/newsubdir/e looks like
4734 # dir/subdir/ -> folder/subdir/newsubdir/
4735 # and if we note that newfile.c is found in dir/subdir/, we might overlook
4736 # the dir/ -> folder/ rule that has more weight. Older git versions did
4738 # 2. The code to do trivial directory resolves. Note that
4739 # dir/subdir/unchanged/ is unchanged and can be deleted, and files in the
4740 # new folder/subdir/unchanged/ are not needed as a target to any renames.
4741 # Thus, in the second collect_merge_info_callback() we can just resolve
4742 # these two directories trivially without recursing.)
4743 # 3. Exercising the codepaths for caching renames and deletes from one cherry
4744 # pick and re-applying them in the subsequent one.
4751 mkdir
-p dir
/unchanged
&&
4752 mkdir
-p dir
/subdir
/tweaked
&&
4753 echo a
>dir
/subdir
/a
&&
4754 echo b
>dir
/subdir
/b
&&
4755 echo c
>dir
/subdir
/c
&&
4756 echo d
>dir
/subdir
/d
&&
4757 test_seq
1 10 >dir
/subdir
/e
&&
4758 test_seq
10 20 >dir
/subdir
/Makefile
&&
4759 echo f
>dir
/subdir
/tweaked
/f
&&
4760 echo g
>dir
/subdir
/tweaked
/g
&&
4761 echo h
>dir
/subdir
/tweaked
/h
&&
4762 test_seq
20 30 >dir
/subdir
/tweaked
/Makefile
&&
4763 for i
in $
(test_seq
1 88); do
4764 echo content
$i >dir
/unchanged
/file_
$i
4767 git commit
-m "O" &&
4774 git
rm dir
/subdir
/tweaked
/f dir
/subdir
/tweaked
/g
&&
4775 test_seq
2 10 >dir
/subdir
/e
&&
4776 test_seq
11 20 >dir
/subdir
/Makefile
&&
4777 test_seq
21 30 >dir
/subdir
/tweaked
/Makefile
&&
4778 mkdir dir
/subdir
/newsubdir
&&
4779 git
mv dir
/subdir
/e dir
/subdir
/newsubdir
/ &&
4780 git
mv dir folder
&&
4782 git commit
-m "A" &&
4785 mkdir dir
/subdir
/newsubdir
/ &&
4786 echo c code
>dir
/subdir
/newfile.c
&&
4787 echo python code
>dir
/subdir
/newsubdir
/newfile.py
&&
4788 test_seq
1 11 >dir
/subdir
/e
&&
4789 test_seq
10 21 >dir
/subdir
/Makefile
&&
4790 test_seq
20 31 >dir
/subdir
/tweaked
/Makefile
&&
4792 git commit
-m "B1" &&
4794 echo rust code
>dir
/subdir
/newfile.rs
&&
4795 test_seq
1 12 >dir
/subdir
/e
&&
4801 test_expect_merge_algorithm failure success
'12f: Trivial directory resolve, caching, all kinds of fun' '
4807 git branch Bmod B &&
4809 GIT_TRACE2_PERF="$(pwd)/trace.output" git -c merge.directoryRenames=true rebase A Bmod &&
4811 echo Checking the pick of B1... &&
4813 test_must_fail git rev-parse Bmod~1:dir &&
4815 git ls-tree -r Bmod~1 >out &&
4816 test_line_count = 98 out &&
4818 git diff --name-status A Bmod~1 >actual &&
4819 q_to_tab >expect <<-\EOF &&
4820 MQfolder/subdir/Makefile
4821 AQfolder/subdir/newfile.c
4822 MQfolder/subdir/newsubdir/e
4823 AQfolder/subdir/newsubdir/newfile.py
4824 MQfolder/subdir/tweaked/Makefile
4826 test_cmp expect actual &&
4828 # Three-way merged files
4829 test_seq 2 11 >e_Merge1 &&
4830 test_seq 11 21 >Makefile_TOP &&
4831 test_seq 21 31 >Makefile_SUB &&
4832 git hash-object >expect \
4836 git rev-parse >actual \
4837 Bmod~1:folder/subdir/newsubdir/e \
4838 Bmod~1:folder/subdir/Makefile \
4839 Bmod~1:folder/subdir/tweaked/Makefile &&
4840 test_cmp expect actual &&
4842 # New files showed up at the right location with right contents
4843 git rev-parse >expect \
4844 B~1:dir/subdir/newfile.c \
4845 B~1:dir/subdir/newsubdir/newfile.py &&
4846 git rev-parse >actual \
4847 Bmod~1:folder/subdir/newfile.c \
4848 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4849 test_cmp expect actual &&
4852 test_path_is_missing folder/subdir/tweaked/f &&
4853 test_path_is_missing folder/subdir/tweaked/g &&
4855 # Unchanged files or directories
4856 git rev-parse >actual \
4857 Bmod~1:folder/subdir/a \
4858 Bmod~1:folder/subdir/b \
4859 Bmod~1:folder/subdir/c \
4860 Bmod~1:folder/subdir/d \
4861 Bmod~1:folder/unchanged \
4862 Bmod~1:folder/subdir/tweaked/h &&
4863 git rev-parse >expect \
4869 O:dir/subdir/tweaked/h &&
4870 test_cmp expect actual &&
4872 echo Checking the pick of B2... &&
4874 test_must_fail git rev-parse Bmod:dir &&
4876 git ls-tree -r Bmod >out &&
4877 test_line_count = 99 out &&
4879 git diff --name-status Bmod~1 Bmod >actual &&
4880 q_to_tab >expect <<-\EOF &&
4881 AQfolder/subdir/newfile.rs
4882 MQfolder/subdir/newsubdir/e
4884 test_cmp expect actual &&
4886 # Three-way merged file
4887 test_seq 2 12 >e_Merge2 &&
4888 git hash-object e_Merge2 >expect &&
4889 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4890 test_cmp expect actual &&
4892 grep region_enter.*collect_merge_info trace.output >collect &&
4893 test_line_count = 4 collect &&
4894 grep region_enter.*process_entries$ trace.output >process &&
4895 test_line_count = 2 process
4899 # Testcase 12g, Testcase with two kinds of "relevant" renames
4900 # Commit O: somefile_O, subdir/{a_O,b_O}
4901 # Commit A: somefile_A, subdir/{a_O,b_O,c_A}
4902 # Commit B: newfile_B, newdir/{a_B,b_B}
4903 # Expected: newfile_{merged}, newdir/{a_B,b_B,c_A}
4911 test_write_lines upon a
time there was a
>somefile
&&
4912 test_write_lines
1 2 3 4 5 6 7 8 9 10 >subdir
/a
&&
4913 test_write_lines one two three four five six
>subdir
/b
&&
4916 git commit
-m "O" &&
4923 test_write_lines once upon a
time there was a
>somefile
&&
4925 git add somefile subdir
/c
&&
4927 git commit
-m "A" &&
4930 git
mv somefile newfile
&&
4931 git
mv subdir newdir
&&
4932 echo repo
>>newfile
&&
4933 test_write_lines
1 2 3 4 5 6 7 8 9 10 11 >newdir
/a
&&
4934 test_write_lines one two three four five six seven
>newdir
/b
&&
4935 git add newfile newdir
&&
4941 test_expect_success
'12g: Testcase with two kinds of "relevant" renames' '
4948 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4950 test_write_lines once upon a time there was a repo >expect &&
4951 test_cmp expect newfile &&
4953 git ls-files -s >out &&
4954 test_line_count = 4 out &&
4956 git rev-parse >actual \
4957 HEAD:newdir/a HEAD:newdir/b HEAD:newdir/c &&
4958 git rev-parse >expect \
4959 B:newdir/a B:newdir/b A:subdir/c &&
4960 test_cmp expect actual &&
4962 test_must_fail git rev-parse HEAD:subdir/a &&
4963 test_must_fail git rev-parse HEAD:subdir/b &&
4964 test_must_fail git rev-parse HEAD:subdir/c &&
4965 test_path_is_missing subdir/ &&
4966 test_path_is_file newdir/c
4970 # Testcase 12h, Testcase with two kinds of "relevant" renames
4971 # Commit O: olddir/{a_1, b}
4972 # Commit A: newdir/{a_2, b}
4973 # Commit B: olddir/{alpha_1, b}
4974 # Expected: newdir/{alpha_2, b}
4982 test_seq
3 8 >olddir
/a
&&
4985 git commit
-m orig
&&
4992 test_seq
3 10 >olddir
/a
&&
4994 git
mv olddir newdir
&&
4999 git
mv olddir
/a olddir
/alpha
&&
5004 test_expect_failure
'12h: renaming a file within a renamed directory' '
5011 test_might_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5013 git ls-files >tracked &&
5014 test_line_count = 2 tracked &&
5016 test_path_is_missing olddir/a &&
5017 test_path_is_file newdir/alpha &&
5018 test_path_is_file newdir/b &&
5020 git rev-parse >actual \
5021 HEAD:newdir/alpha HEAD:newdir/b &&
5022 git rev-parse >expect \
5023 A:newdir/a O:oldir/b &&
5024 test_cmp expect actual
5028 # Testcase 12i, Directory rename causes rename-to-self
5029 # Commit O: source/{subdir/foo, bar, baz_1}
5030 # Commit A: source/{foo, bar, baz_1}
5031 # Commit B: source/{subdir/{foo, bar}, baz_2}
5032 # Expected: source/{foo, bar, baz_2}, with conflicts on
5033 # source/bar vs. source/subdir/bar
5040 mkdir
-p source
/subdir
&&
5041 echo foo
>source
/subdir
/foo
&&
5042 echo bar
>source
/bar
&&
5043 echo baz
>source
/baz
&&
5045 git commit
-m orig
&&
5052 git
mv source
/subdir
/foo source
/foo
&&
5056 git
mv source
/bar source
/subdir
/bar
&&
5057 echo more baz
>>source
/baz
&&
5062 test_expect_success
'12i: Directory rename causes rename-to-self' '
5069 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5071 test_path_is_missing source/subdir &&
5072 test_path_is_file source/bar &&
5073 test_path_is_file source/baz &&
5075 git ls-files | uniq >tracked &&
5076 test_line_count = 3 tracked &&
5078 git status --porcelain -uno >actual &&
5079 cat >expect <<-\EOF &&
5083 test_cmp expect actual
5087 # Testcase 12j, Directory rename to root causes rename-to-self
5088 # Commit O: {subdir/foo, bar, baz_1}
5089 # Commit A: {foo, bar, baz_1}
5090 # Commit B: {subdir/{foo, bar}, baz_2}
5091 # Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar
5099 echo foo
>subdir
/foo
&&
5103 git commit
-m orig
&&
5110 git
mv subdir
/foo foo
&&
5114 git
mv bar subdir
/bar
&&
5115 echo more baz
>>baz
&&
5120 test_expect_success
'12j: Directory rename to root causes rename-to-self' '
5127 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5129 test_path_is_missing subdir &&
5130 test_path_is_file bar &&
5131 test_path_is_file baz &&
5133 git ls-files | uniq >tracked &&
5134 test_line_count = 3 tracked &&
5136 git status --porcelain -uno >actual &&
5137 cat >expect <<-\EOF &&
5141 test_cmp expect actual
5145 # Testcase 12k, Directory rename with sibling causes rename-to-self
5146 # Commit O: dirB/foo, dirA/{bar, baz_1}
5147 # Commit A: dirA/{foo, bar, baz_1}
5148 # Commit B: dirB/{foo, bar}, dirA/baz_2
5149 # Expected: dirA/{foo, bar, baz_2}, with conflicts on dirA/bar vs. dirB/bar
5157 echo foo
>dirB
/foo
&&
5158 echo bar
>dirA
/bar
&&
5159 echo baz
>dirA
/baz
&&
5161 git commit
-m orig
&&
5168 git
mv dirB
/* dirA
/ &&
5172 git
mv dirA
/bar dirB
/bar
&&
5173 echo more baz
>>dirA
/baz
&&
5178 test_expect_success
'12k: Directory rename with sibling causes rename-to-self' '
5185 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5187 test_path_is_missing dirB &&
5188 test_path_is_file dirA/bar &&
5189 test_path_is_file dirA/baz &&
5191 git ls-files | uniq >tracked &&
5192 test_line_count = 3 tracked &&
5194 git status --porcelain -uno >actual &&
5195 cat >expect <<-\EOF &&
5199 test_cmp expect actual
5203 # Testcase 12l, Both sides rename a directory into the other side, both add
5204 # a file which after directory renames are the same filename
5205 # Commit O: sub1/file, sub2/other
5206 # Commit A: sub3/file, sub2/{other, new_add_add_file_1}
5207 # Commit B: sub1/{file, newfile}, sub1/sub2/{other, new_add_add_file_2}
5210 # A: sub1/ -> sub3/, add sub2/new_add_add_file_1
5211 # B: sub2/ -> sub1/sub2, add sub1/newfile, add sub1/sub2/new_add_add_file_2
5213 # Expected: sub3/{file, newfile, sub2/other}
5214 # CONFLICT (add/add): sub1/sub2/new_add_add_file
5216 # Note that sub1/newfile is not extraneous. Directory renames are only
5217 # detected if they are needed, and they are only needed if the old directory
5218 # had a new file added on the opposite side of history. So sub1/newfile
5219 # is needed for there to be a sub1/ -> sub3/ rename.
5227 echo file >sub
1/file &&
5228 echo other
>sub
2/other
&&
5229 git add sub1 sub2
&&
5230 git commit
-m "O" &&
5238 echo conflicting
>sub
2/new_add_add_file
&&
5242 git commit
-m "A" &&
5245 echo dissimilar
>sub
2/new_add_add_file
&&
5246 echo brand
>sub
1/newfile
&&
5247 git add sub1 sub2
&&
5254 test_expect_merge_algorithm failure success
'12l (B into A): Rename into each other + add/add conflict' '
5255 test_setup_12l BintoA &&
5259 git checkout -q A^0 &&
5261 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5263 test_stdout_line_count = 5 git ls-files -s &&
5265 git rev-parse >actual \
5266 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5267 :2:sub1/sub2/new_add_add_file \
5268 :3:sub1/sub2/new_add_add_file &&
5269 git rev-parse >expect \
5270 O:sub1/file B:sub1/newfile O:sub2/other \
5271 A:sub2/new_add_add_file \
5272 B:sub1/sub2/new_add_add_file &&
5273 test_cmp expect actual &&
5275 git ls-files -o >actual &&
5276 test_write_lines actual expect >expect &&
5277 test_cmp expect actual
5281 test_expect_merge_algorithm failure success
'12l (A into B): Rename into each other + add/add conflict' '
5282 test_setup_12l AintoB &&
5286 git checkout -q B^0 &&
5288 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 &&
5290 test_stdout_line_count = 5 git ls-files -s &&
5292 git rev-parse >actual \
5293 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5294 :2:sub1/sub2/new_add_add_file \
5295 :3:sub1/sub2/new_add_add_file &&
5296 git rev-parse >expect \
5297 O:sub1/file B:sub1/newfile O:sub2/other \
5298 B:sub1/sub2/new_add_add_file \
5299 A:sub2/new_add_add_file &&
5300 test_cmp expect actual &&
5302 git ls-files -o >actual &&
5303 test_write_lines actual expect >expect &&
5304 test_cmp expect actual
5308 # Testcase 12m, Directory rename, plus change of parent dir to symlink
5309 # Commit O: dir/subdir/file
5310 # Commit A: renamed-dir/subdir/file
5311 # Commit B: dir/subdir
5313 # A: dir/subdir/ -> renamed-dir/subdir
5314 # B: delete dir/subdir/file, add dir/subdir as symlink
5316 # Expected: CONFLICT (rename/delete): renamed-dir/subdir/file,
5317 # CONFLICT (file location): renamed-dir/subdir vs. dir/subdir
5318 # CONFLICT (directory/file): renamed-dir/subdir symlink has
5319 # renamed-dir/subdir in the way
5326 mkdir
-p dir
/subdir
&&
5327 echo 1 >dir
/subdir
/file &&
5329 git commit
-m "O" &&
5336 git
mv dir
/ renamed-dir
/ &&
5338 git commit
-m "A" &&
5341 git
rm dir
/subdir
/file &&
5343 ln -s /dev
/null dir
/subdir
&&
5349 test_expect_merge_algorithm failure success
'12m: Change parent of renamed-dir to symlink on other side' '
5354 git checkout -q A^0 &&
5356 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5358 test_stdout_line_count = 3 git ls-files -s &&
5359 test_stdout_line_count = 2 ls -1 renamed-dir &&
5360 test_path_is_missing dir
5364 ###########################################################################
5365 # SECTION 13: Checking informational and conflict messages
5367 # A year after directory rename detection became the default, it was
5368 # instead decided to report conflicts on the pathname on the basis that
5369 # some users may expect the new files added or moved into a directory to
5370 # be unrelated to all the other files in that directory, and thus that
5371 # directory rename detection is unexpected. Test that the messages printed
5372 # match our expectation.
5373 ###########################################################################
5375 # Testcase 13a, Basic directory rename with newly added files
5378 # Commit B: z/{b,c,d,e/f}
5379 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
5391 git commit
-m "O" &&
5400 git commit
-m "A" &&
5406 git add z
/d z
/e
/f
&&
5412 test_expect_success
'13a(conflict): messages for newly added files' '
5413 test_setup_13a conflict &&
5419 test_must_fail git merge -s recursive B^0 >out 2>err &&
5421 test_grep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
5422 test_grep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
5424 git ls-files >paths &&
5426 grep "y/[de]" paths &&
5428 test_path_is_missing z/d &&
5429 test_path_is_file y/d &&
5430 test_path_is_missing z/e/f &&
5431 test_path_is_file y/e/f
5435 test_expect_success
'13a(info): messages for newly added files' '
5436 test_setup_13a info &&
5443 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5445 test_grep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
5446 test_grep Path.updated:.*z/d.added.in.B^0.*y/d out &&
5448 git ls-files >paths &&
5450 grep "y/[de]" paths &&
5452 test_path_is_missing z/d &&
5453 test_path_is_file y/d &&
5454 test_path_is_missing z/e/f &&
5455 test_path_is_file y/e/f
5459 # Testcase 13b, Transitive rename with conflicted content merge and default
5460 # "conflict" setting
5461 # (Related to testcase 1c, 9b)
5462 # Commit O: z/{b,c}, x/d_1
5463 # Commit A: y/{b,c}, x/d_2
5464 # Commit B: z/{b,c,d_3}
5465 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
5466 # one about content, and one about file location
5475 test_seq
1 10 >x
/d
&&
5480 git commit
-m "O" &&
5491 git commit
-m "A" &&
5494 echo eleven
>>x
/d
&&
5502 test_expect_success
'13b(conflict): messages for transitive rename with conflicted content' '
5503 test_setup_13b conflict &&
5509 test_must_fail git merge -s recursive B^0 >out 2>err &&
5511 test_grep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5512 test_grep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5514 git ls-files >paths &&
5518 test_path_is_missing z/d &&
5519 test_path_is_file y/d
5523 test_expect_success
'13b(info): messages for transitive rename with conflicted content' '
5524 test_setup_13b info &&
5531 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5533 test_grep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5534 test_grep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5536 git ls-files >paths &&
5540 test_path_is_missing z/d &&
5541 test_path_is_file y/d
5545 # Testcase 13c, Rename/rename(1to1) due to directory rename
5546 # Commit O: z/{b,c}, x/{d,e}
5547 # Commit A: y/{b,c,d}, x/e
5548 # Commit B: z/{b,c,d}, x/e
5549 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
5550 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
5551 # One could argue A had partial knowledge of what was done with
5552 # d and B had full knowledge, but that's a slippery slope as
5553 # shown in testcase 13d.
5562 test_seq
1 10 >x
/d
&&
5568 git commit
-m "O" &&
5578 git commit
-m "A" &&
5588 test_expect_success
'13c(conflict): messages for rename/rename(1to1) via transitive rename' '
5589 test_setup_13c conflict &&
5595 test_must_fail git merge -s recursive B^0 >out 2>err &&
5597 test_grep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5599 git ls-files >paths &&
5603 test_path_is_missing z/d &&
5604 test_path_is_file y/d
5608 test_expect_success
'13c(info): messages for rename/rename(1to1) via transitive rename' '
5609 test_setup_13c info &&
5616 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5618 test_grep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5620 git ls-files >paths &&
5624 test_path_is_missing z/d &&
5625 test_path_is_file y/d
5629 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
5630 # Commit O: a/{z,y}, b/x, c/w
5631 # Commit A: a/z, b/{y,x}, d/w
5632 # Commit B: a/z, d/x, c/{y,w}
5633 # Expected: a/z, d/{y,x,w} with no file location conflict for x
5635 # * z is always in a; so it stays in a.
5636 # * x starts in b, only modified on one side to move into d/
5637 # * w starts in c, only modified on one side to move into d/
5639 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5640 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5641 # No conflict in where a/y ends up, so put it in d/y.
5657 git commit
-m "O" &&
5667 git commit
-m "A" &&
5677 test_expect_success
'13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5678 test_setup_13d conflict &&
5684 test_must_fail git merge -s recursive B^0 >out 2>err &&
5686 test_grep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5687 test_grep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5689 git ls-files >paths &&
5694 test_path_is_missing b/y &&
5695 test_path_is_missing c/y &&
5696 test_path_is_file d/y
5700 test_expect_success
'13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5701 test_setup_13d info &&
5708 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5710 test_grep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5711 test_grep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5713 git ls-files >paths &&
5718 test_path_is_missing b/y &&
5719 test_path_is_missing c/y &&
5720 test_path_is_file d/y
5724 # Testcase 13e, directory rename in virtual merge base
5726 # This testcase has a slightly different setup than all the above cases, in
5727 # order to include a recursive case:
5739 # Commit B: a/{z,y,x}
5740 # Commit C: b/{z,y,x}
5741 # Commit D: b/{z,y}, a/x
5742 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5744 # NOTES: 'X' represents a virtual merge base. With the default of
5745 # directory rename detection yielding conflicts, merging A and B
5746 # results in a conflict complaining about whether 'x' should be
5747 # under 'a/' or 'b/'. However, when creating the virtual merge
5748 # base 'X', since virtual merge bases need to be written out as a
5749 # tree, we cannot have a conflict, so some resolution has to be
5752 # In choosing the right resolution, it's worth noting here that
5753 # commits C & D are merges of A & B that choose different
5754 # locations for 'x' (i.e. they resolve the conflict differently),
5755 # and so it would be nice when merging C & D if git could detect
5756 # this difference of opinion and report a conflict. But the only
5757 # way to do so that I can think of would be to have the virtual
5758 # merge base place 'x' in some directory other than either 'a/' or
5759 # 'b/', which seems a little weird -- especially since it'd result
5760 # in a rename/rename(1to2) conflict with a source path that never
5761 # existed in any version.
5763 # So, for now, when directory rename detection is set to
5764 # 'conflict' just avoid doing directory rename detection at all in
5765 # the recursive case. This will not allow us to detect a conflict
5766 # in the outer merge for this special kind of setup, but it at
5767 # least avoids hitting a BUG().
5779 git commit
-m "O" &&
5788 git commit
-m "A" &&
5794 git commit
-m "B" &&
5800 test_must_fail git
-c merge.directoryRenames
=conflict merge B
&&
5803 git commit
-m "C" &&
5807 test_must_fail git
-c merge.directoryRenames
=conflict merge A
&&
5816 test_expect_success
'13e: directory rename detection in recursive case' '
5821 git checkout --quiet D^0 &&
5823 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5825 test_grep ! CONFLICT out &&
5826 test_grep ! BUG: err &&
5827 test_grep ! core.dumped err &&
5828 test_must_be_empty err &&
5830 git ls-files >paths &&