]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t6043-merge-rename-directories.sh
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.)
31 ###########################################################################
32 # SECTION 1: Basic cases we should be able to handle
33 ###########################################################################
35 # Testcase 1a, Basic directory rename.
38 # Commit B: z/{b,c,d,e/f}
39 # Expected: y/{b,c,d,e/f}
41 test_expect_success
'1a-setup: Simple directory rename detection' '
42 test_create_repo 1a &&
72 test_expect_failure
'1a-check: Simple directory rename detection' '
78 git merge -s recursive B^0 &&
80 git ls-files -s >out &&
81 test_line_count = 4 out &&
83 git rev-parse >actual \
84 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
85 git rev-parse >expect \
86 O:z/b O:z/c B:z/d B:z/e/f &&
87 test_cmp expect actual &&
89 git hash-object y/d >actual &&
90 git rev-parse B:z/d >expect &&
91 test_cmp expect actual &&
93 test_must_fail git rev-parse HEAD:z/d &&
94 test_must_fail git rev-parse HEAD:z/e/f &&
95 test_path_is_missing z/d &&
96 test_path_is_missing z/e/f
100 # Testcase 1b, Merge a directory with another
101 # Commit O: z/{b,c}, y/d
102 # Commit A: z/{b,c,e}, y/d
103 # Commit B: y/{b,c,d}
104 # Expected: y/{b,c,d,e}
106 test_expect_success
'1b-setup: Merge a directory with another' '
107 test_create_repo 1b &&
139 test_expect_failure
'1b-check: Merge a directory with another' '
145 git merge -s recursive B^0 &&
147 git ls-files -s >out &&
148 test_line_count = 4 out &&
150 git rev-parse >actual \
151 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
152 git rev-parse >expect \
153 O:z/b O:z/c O:y/d A:z/e &&
154 test_cmp expect actual &&
155 test_must_fail git rev-parse HEAD:z/e
159 # Testcase 1c, Transitive renaming
160 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
161 # (Related to testcases 9c and 9d -- can transitivity repeat?)
162 # Commit O: z/{b,c}, x/d
163 # Commit A: y/{b,c}, x/d
164 # Commit B: z/{b,c,d}
165 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
167 test_expect_success
'1c-setup: Transitive renaming' '
168 test_create_repo 1c &&
197 test_expect_failure
'1c-check: Transitive renaming' '
203 git merge -s recursive B^0 &&
205 git ls-files -s >out &&
206 test_line_count = 3 out &&
208 git rev-parse >actual \
209 HEAD:y/b HEAD:y/c HEAD:y/d &&
210 git rev-parse >expect \
212 test_cmp expect actual &&
213 test_must_fail git rev-parse HEAD:x/d &&
214 test_must_fail git rev-parse HEAD:z/d &&
215 test_path_is_missing z/d
219 # Testcase 1d, Directory renames (merging two directories into one new one)
220 # cause a rename/rename(2to1) conflict
221 # (Related to testcases 1c and 7b)
222 # Commit O. z/{b,c}, y/{d,e}
223 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
224 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
225 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
226 # Note: y/m & z/n should definitely move into x. By the same token, both
227 # y/wham_1 & z/wham_2 should too...giving us a conflict.
229 test_expect_success
'1d-setup: Directory renames cause a rename/rename(2to1) conflict' '
230 test_create_repo 1d &&
251 echo wham1 >y/wham &&
259 echo wham2 >z/wham &&
266 test_expect_failure
'1d-check: Directory renames cause a rename/rename(2to1) conflict' '
272 test_must_fail git merge -s recursive B^0 >out &&
273 test_i18ngrep "CONFLICT (rename/rename)" out &&
275 git ls-files -s >out &&
276 test_line_count = 8 out &&
277 git ls-files -u >out &&
278 test_line_count = 2 out &&
279 git ls-files -o >out &&
280 test_line_count = 3 out &&
282 git rev-parse >actual \
283 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
284 git rev-parse >expect \
285 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
286 test_cmp expect actual &&
288 test_must_fail git rev-parse :0:x/wham &&
289 git rev-parse >actual \
290 :2:x/wham :3:x/wham &&
291 git rev-parse >expect \
293 test_cmp expect actual &&
295 test_path_is_missing x/wham &&
296 test_path_is_file x/wham~HEAD &&
297 test_path_is_file x/wham~B^0 &&
299 git hash-object >actual \
300 x/wham~HEAD x/wham~B^0 &&
301 git rev-parse >expect \
303 test_cmp expect actual
307 # Testcase 1e, Renamed directory, with all filenames being renamed too
308 # Commit O: z/{oldb,oldc}
309 # Commit A: y/{newb,newc}
310 # Commit B: z/{oldb,oldc,d}
311 # Expected: y/{newb,newc,d}
313 test_expect_success
'1e-setup: Renamed directory, with all files being renamed too' '
314 test_create_repo 1e &&
331 git mv z/oldb y/newb &&
332 git mv z/oldc y/newc &&
344 test_expect_failure
'1e-check: Renamed directory, with all files being renamed too' '
350 git merge -s recursive B^0 &&
352 git ls-files -s >out &&
353 test_line_count = 3 out &&
355 git rev-parse >actual \
356 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
357 git rev-parse >expect \
358 O:z/oldb O:z/oldc B:z/d &&
359 test_cmp expect actual &&
360 test_must_fail git rev-parse HEAD:z/d
364 # Testcase 1f, Split a directory into two other directories
365 # (Related to testcases 3a, all of section 2, and all of section 4)
366 # Commit O: z/{b,c,d,e,f}
367 # Commit A: z/{b,c,d,e,f,g}
368 # Commit B: y/{b,c}, x/{d,e,f}
369 # Expected: y/{b,c}, x/{d,e,f,g}
371 test_expect_success
'1f-setup: Split a directory into two other directories' '
372 test_create_repo 1f &&
410 test_expect_failure
'1f-check: Split a directory into two other directories' '
416 git merge -s recursive B^0 &&
418 git ls-files -s >out &&
419 test_line_count = 6 out &&
421 git rev-parse >actual \
422 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
423 git rev-parse >expect \
424 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
425 test_cmp expect actual &&
426 test_path_is_missing z/g &&
427 test_must_fail git rev-parse HEAD:z/g
431 ###########################################################################
432 # Rules suggested by testcases in section 1:
434 # We should still detect the directory rename even if it wasn't just
435 # the directory renamed, but the files within it. (see 1b)
437 # If renames split a directory into two or more others, the directory
438 # with the most renames, "wins" (see 1c). However, see the testcases
439 # in section 2, plus testcases 3a and 4a.
440 ###########################################################################
443 ###########################################################################
444 # SECTION 2: Split into multiple directories, with equal number of paths
446 # Explore the splitting-a-directory rules a bit; what happens in the
449 # Note that there is a closely related case of a directory not being
450 # split on either side of history, but being renamed differently on
451 # each side. See testcase 8e for that.
452 ###########################################################################
454 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
457 # Commit B: z/{b,c,d}
458 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
459 test_expect_success
'2a-setup: Directory split into two on one side, with equal numbers of paths' '
460 test_create_repo 2a &&
491 test_expect_failure
'2a-check: Directory split into two on one side, with equal numbers of paths' '
497 test_must_fail git merge -s recursive B^0 >out &&
498 test_i18ngrep "CONFLICT.*directory rename split" out &&
500 git ls-files -s >out &&
501 test_line_count = 3 out &&
502 git ls-files -u >out &&
503 test_line_count = 0 out &&
504 git ls-files -o >out &&
505 test_line_count = 1 out &&
507 git rev-parse >actual \
508 :0:y/b :0:w/c :0:z/d &&
509 git rev-parse >expect \
511 test_cmp expect actual
515 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
518 # Commit B: z/{b,c}, x/d
519 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
520 test_expect_success
'2b-setup: Directory split into two on one side, with equal numbers of paths' '
521 test_create_repo 2b &&
553 test_expect_success
'2b-check: Directory split into two on one side, with equal numbers of paths' '
559 git merge -s recursive B^0 >out &&
561 git ls-files -s >out &&
562 test_line_count = 3 out &&
563 git ls-files -u >out &&
564 test_line_count = 0 out &&
565 git ls-files -o >out &&
566 test_line_count = 1 out &&
568 git rev-parse >actual \
569 :0:y/b :0:w/c :0:x/d &&
570 git rev-parse >expect \
572 test_cmp expect actual &&
573 test_i18ngrep ! "CONFLICT.*directory rename split" out
577 ###########################################################################
578 # Rules suggested by section 2:
580 # None; the rule was already covered in section 1. These testcases are
581 # here just to make sure the conflict resolution and necessary warning
582 # messages are handled correctly.
583 ###########################################################################
586 ###########################################################################
587 # SECTION 3: Path in question is the source path for some rename already
589 # Combining cases from Section 1 and trying to handle them could lead to
590 # directory renaming detection being over-applied. So, this section
591 # provides some good testcases to check that the implementation doesn't go
593 ###########################################################################
595 # Testcase 3a, Avoid implicit rename if involved as source on other side
596 # (Related to testcases 1c and 1f)
597 # Commit O: z/{b,c,d}
598 # Commit A: z/{b,c,d} (no change)
599 # Commit B: y/{b,c}, x/d
600 # Expected: y/{b,c}, x/d
601 test_expect_success
'3a-setup: Avoid implicit rename if involved as source on other side' '
602 test_create_repo 3a &&
620 git commit --allow-empty -m "A" &&
634 test_expect_success
'3a-check: Avoid implicit rename if involved as source on other side' '
640 git merge -s recursive B^0 &&
642 git ls-files -s >out &&
643 test_line_count = 3 out &&
645 git rev-parse >actual \
646 HEAD:y/b HEAD:y/c HEAD:x/d &&
647 git rev-parse >expect \
649 test_cmp expect actual
653 # Testcase 3b, Avoid implicit rename if involved as source on other side
654 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
655 # Commit O: z/{b,c,d}
656 # Commit A: y/{b,c}, x/d
657 # Commit B: z/{b,c}, w/d
658 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
659 # NOTE: We're particularly checking that since z/d is already involved as
660 # a source in a file rename on the same side of history, that we don't
661 # get it involved in directory rename detection. If it were, we might
662 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
663 # rename/rename/rename(1to3) conflict, which is just weird.
664 test_expect_success
'3b-setup: Avoid implicit rename if involved as source on current side' '
665 test_create_repo 3b &&
699 test_expect_success
'3b-check: Avoid implicit rename if involved as source on current side' '
705 test_must_fail git merge -s recursive B^0 >out &&
706 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
707 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
709 git ls-files -s >out &&
710 test_line_count = 5 out &&
711 git ls-files -u >out &&
712 test_line_count = 3 out &&
713 git ls-files -o >out &&
714 test_line_count = 1 out &&
716 git rev-parse >actual \
717 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
718 git rev-parse >expect \
719 O:z/b O:z/c O:z/d O:z/d O:z/d &&
720 test_cmp expect actual &&
722 test_path_is_missing z/d &&
723 git hash-object >actual \
725 git rev-parse >expect \
727 test_cmp expect actual
731 ###########################################################################
732 # Rules suggested by section 3:
734 # Avoid directory-rename-detection for a path, if that path is the source
735 # of a rename on either side of a merge.
736 ###########################################################################
739 ###########################################################################
740 # SECTION 4: Partially renamed directory; still exists on both sides of merge
742 # What if we were to attempt to do directory rename detection when someone
743 # "mostly" moved a directory but still left some files around, or,
744 # equivalently, fully renamed a directory in one commmit and then recreated
745 # that directory in a later commit adding some new files and then tried to
748 # It's hard to divine user intent in these cases, because you can make an
749 # argument that, depending on the intermediate history of the side being
750 # merged, that some users will want files in that directory to
751 # automatically be detected and renamed, while users with a different
752 # intermediate history wouldn't want that rename to happen.
754 # I think that it is best to simply not have directory rename detection
755 # apply to such cases. My reasoning for this is four-fold: (1) it's
756 # easiest for users in general to figure out what happened if we don't
757 # apply directory rename detection in any such case, (2) it's an easy rule
758 # to explain ["We don't do directory rename detection if the directory
759 # still exists on both sides of the merge"], (3) we can get some hairy
760 # edge/corner cases that would be really confusing and possibly not even
761 # representable in the index if we were to even try, and [related to 3] (4)
762 # attempting to resolve this issue of divining user intent by examining
763 # intermediate history goes against the spirit of three-way merges and is a
764 # path towards crazy corner cases that are far more complex than what we're
765 # already dealing with.
767 # Note that the wording of the rule ("We don't do directory rename
768 # detection if the directory still exists on both sides of the merge.")
769 # also excludes "renaming" of a directory into a subdirectory of itself
770 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
771 # out an exception for "renaming"-beneath-itself cases without opening
772 # weird edge/corner cases for other partial directory renames, but for now
773 # we are keeping the rule simple.
775 # This section contains a test for a partially-renamed-directory case.
776 ###########################################################################
778 # Testcase 4a, Directory split, with original directory still present
779 # (Related to testcase 1f)
780 # Commit O: z/{b,c,d,e}
781 # Commit A: y/{b,c,d}, z/e
782 # Commit B: z/{b,c,d,e,f}
783 # Expected: y/{b,c,d}, z/{e,f}
784 # NOTE: Even though most files from z moved to y, we don't want f to follow.
786 test_expect_success
'4a-setup: Directory split, with original directory still present' '
787 test_create_repo 4a &&
820 test_expect_success
'4a-check: Directory split, with original directory still present' '
826 git merge -s recursive B^0 &&
828 git ls-files -s >out &&
829 test_line_count = 5 out &&
830 git ls-files -u >out &&
831 test_line_count = 0 out &&
832 git ls-files -o >out &&
833 test_line_count = 1 out &&
835 git rev-parse >actual \
836 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
837 git rev-parse >expect \
838 O:z/b O:z/c O:z/d O:z/e B:z/f &&
839 test_cmp expect actual
843 ###########################################################################
844 # Rules suggested by section 4:
846 # Directory-rename-detection should be turned off for any directories (as
847 # a source for renames) that exist on both sides of the merge. (The "as
848 # a source for renames" clarification is due to cases like 1c where
849 # the target directory exists on both sides and we do want the rename
850 # detection.) But, sadly, see testcase 8b.
851 ###########################################################################
854 ###########################################################################
855 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
857 # Implicitly renaming files due to a detected directory rename could run
858 # into problems if there are files or directories in the way of the paths
859 # we want to rename. Explore such cases in this section.
860 ###########################################################################
862 # Testcase 5a, Merge directories, other side adds files to original and target
863 # Commit O: z/{b,c}, y/d
864 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
865 # Commit B: y/{b,c,d}
866 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
867 # NOTE: While directory rename detection is active here causing z/f to
868 # become y/f, we did not apply this for z/e_1 because that would
869 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
870 # this add/add, is that both versions of y/e are from the same side
871 # of history, giving us no way to represent this conflict in the
874 test_expect_success
'5a-setup: Merge directories, other side adds files to original and target' '
875 test_create_repo 5a &&
896 git add z/e z/f y/e &&
909 test_expect_failure
'5a-check: Merge directories, other side adds files to original and target' '
915 test_must_fail git merge -s recursive B^0 >out &&
916 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
918 git ls-files -s >out &&
919 test_line_count = 6 out &&
920 git ls-files -u >out &&
921 test_line_count = 0 out &&
922 git ls-files -o >out &&
923 test_line_count = 1 out &&
925 git rev-parse >actual \
926 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
927 git rev-parse >expect \
928 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
929 test_cmp expect actual
933 # Testcase 5b, Rename/delete in order to get add/add/add conflict
934 # (Related to testcase 8d; these may appear slightly inconsistent to users;
935 # Also related to testcases 7d and 7e)
936 # Commit O: z/{b,c,d_1}
937 # Commit A: y/{b,c,d_2}
938 # Commit B: z/{b,c,d_1,e}, y/d_3
939 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
940 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
941 # we normaly would since z/ is being renamed to y/, then this would be
942 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
943 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
944 # representable in the index, so the existence of y/d_3 needs to
945 # cause us to bail on directory rename detection for that path, falling
946 # back to git behavior without the directory rename detection.
948 test_expect_success
'5b-setup: Rename/delete in order to get add/add/add conflict' '
949 test_create_repo 5b &&
983 test_expect_failure
'5b-check: Rename/delete in order to get add/add/add conflict' '
989 test_must_fail git merge -s recursive B^0 >out &&
990 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
992 git ls-files -s >out &&
993 test_line_count = 5 out &&
994 git ls-files -u >out &&
995 test_line_count = 2 out &&
996 git ls-files -o >out &&
997 test_line_count = 1 out &&
999 git rev-parse >actual \
1000 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1001 git rev-parse >expect \
1002 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1003 test_cmp expect actual &&
1005 test_must_fail git rev-parse :1:y/d &&
1006 test_path_is_file y/d
1010 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1011 # (Directory rename detection would result in transitive rename vs.
1012 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1013 # rename paths conflict with separate adds on the other side)
1014 # (Related to testcases 3b and 7c)
1015 # Commit O: z/{b,c}, x/d_1
1016 # Commit A: y/{b,c,d_2}, w/d_1
1017 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1018 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1019 # presence of y/d_4 in B to avoid doing transitive rename of
1020 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1021 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1022 # though, because it doesn't have anything in the way.
1024 test_expect_success
'5c-setup: Transitive rename would cause rename/rename/rename/add/add/add' '
1025 test_create_repo 5c &&
1036 git commit -m "O" &&
1048 git commit -m "A" &&
1057 git add w/ y/ z/e &&
1063 test_expect_failure
'5c-check: Transitive rename would cause rename/rename/rename/add/add/add' '
1069 test_must_fail git merge -s recursive B^0 >out &&
1070 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1071 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1073 git ls-files -s >out &&
1074 test_line_count = 9 out &&
1075 git ls-files -u >out &&
1076 test_line_count = 6 out &&
1077 git ls-files -o >out &&
1078 test_line_count = 3 out &&
1080 git rev-parse >actual \
1081 :0:y/b :0:y/c :0:y/e &&
1082 git rev-parse >expect \
1083 O:z/b O:z/c B:z/e &&
1084 test_cmp expect actual &&
1086 test_must_fail git rev-parse :1:y/d &&
1087 git rev-parse >actual \
1088 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1089 git rev-parse >expect \
1090 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1091 test_cmp expect actual &&
1093 git hash-object >actual \
1094 w/d~HEAD w/d~B^0 z/d &&
1095 git rev-parse >expect \
1096 O:x/d B:w/d O:x/d &&
1097 test_cmp expect actual &&
1098 test_path_is_missing x/d &&
1099 test_path_is_file y/d &&
1100 grep -q "<<<<" y/d # conflict markers should be present
1104 # Testcase 5d, Directory/file/file conflict due to directory rename
1106 # Commit A: y/{b,c,d_1}
1107 # Commit B: z/{b,c,d_2,f}, y/d/e
1108 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1109 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1110 # detection for z/d_2, but that doesn't prevent us from applying the
1111 # directory rename detection for z/f -> y/f.
1113 test_expect_success
'5d-setup: Directory/file/file conflict due to directory rename' '
1114 test_create_repo 5d &&
1123 git commit -m "O" &&
1134 git commit -m "A" &&
1141 git add y/d/e z/d z/f &&
1147 test_expect_failure
'5d-check: Directory/file/file conflict due to directory rename' '
1153 test_must_fail git merge -s recursive B^0 >out &&
1154 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1156 git ls-files -s >out &&
1157 test_line_count = 6 out &&
1158 git ls-files -u >out &&
1159 test_line_count = 1 out &&
1160 git ls-files -o >out &&
1161 test_line_count = 2 out &&
1163 git rev-parse >actual \
1164 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1165 git rev-parse >expect \
1166 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1167 test_cmp expect actual &&
1169 git hash-object y/d~HEAD >actual &&
1170 git rev-parse A:y/d >expect &&
1171 test_cmp expect actual
1175 ###########################################################################
1176 # Rules suggested by section 5:
1178 # If a subset of to-be-renamed files have a file or directory in the way,
1179 # "turn off" the directory rename for those specific sub-paths, falling
1180 # back to old handling. But, sadly, see testcases 8a and 8b.
1181 ###########################################################################
1184 ###########################################################################
1185 # SECTION 6: Same side of the merge was the one that did the rename
1187 # It may sound obvious that you only want to apply implicit directory
1188 # renames to directories if the _other_ side of history did the renaming.
1189 # If you did make an implementation that didn't explicitly enforce this
1190 # rule, the majority of cases that would fall under this section would
1191 # also be solved by following the rules from the above sections. But
1192 # there are still a few that stick out, so this section covers them just
1193 # to make sure we also get them right.
1194 ###########################################################################
1196 # Testcase 6a, Tricky rename/delete
1197 # Commit O: z/{b,c,d}
1199 # Commit B: y/{b,c}, z/d
1200 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1201 # Note: We're just checking here that the rename of z/b and z/c to put
1202 # them under y/ doesn't accidentally catch z/d and make it look like
1203 # it is also involved in a rename/delete conflict.
1205 test_expect_success
'6a-setup: Tricky rename/delete' '
1206 test_create_repo 6a &&
1216 git commit -m "O" &&
1226 git commit -m "A" &&
1237 test_expect_success
'6a-check: Tricky rename/delete' '
1243 test_must_fail git merge -s recursive B^0 >out &&
1244 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1246 git ls-files -s >out &&
1247 test_line_count = 2 out &&
1248 git ls-files -u >out &&
1249 test_line_count = 1 out &&
1250 git ls-files -o >out &&
1251 test_line_count = 1 out &&
1253 git rev-parse >actual \
1255 git rev-parse >expect \
1257 test_cmp expect actual
1261 # Testcase 6b, Same rename done on both sides
1262 # (Related to testcases 6c and 8e)
1265 # Commit B: y/{b,c}, z/d
1266 # Expected: y/{b,c}, z/d
1267 # Note: If we did directory rename detection here, we'd move z/d into y/,
1268 # but B did that rename and still decided to put the file into z/,
1269 # so we probably shouldn't apply directory rename detection for it.
1271 test_expect_success
'6b-setup: Same rename done on both sides' '
1272 test_create_repo 6b &&
1281 git commit -m "O" &&
1290 git commit -m "A" &&
1302 test_expect_success
'6b-check: Same rename done on both sides' '
1308 git merge -s recursive B^0 &&
1310 git ls-files -s >out &&
1311 test_line_count = 3 out &&
1312 git ls-files -u >out &&
1313 test_line_count = 0 out &&
1314 git ls-files -o >out &&
1315 test_line_count = 1 out &&
1317 git rev-parse >actual \
1318 HEAD:y/b HEAD:y/c HEAD:z/d &&
1319 git rev-parse >expect \
1320 O:z/b O:z/c B:z/d &&
1321 test_cmp expect actual
1325 # Testcase 6c, Rename only done on same side
1326 # (Related to testcases 6b and 8e)
1328 # Commit A: z/{b,c} (no change)
1329 # Commit B: y/{b,c}, z/d
1330 # Expected: y/{b,c}, z/d
1331 # NOTE: Seems obvious, but just checking that the implementation doesn't
1332 # "accidentally detect a rename" and give us y/{b,c,d}.
1334 test_expect_success
'6c-setup: Rename only done on same side' '
1335 test_create_repo 6c &&
1344 git commit -m "O" &&
1352 git commit --allow-empty -m "A" &&
1364 test_expect_success
'6c-check: Rename only done on same side' '
1370 git merge -s recursive B^0 &&
1372 git ls-files -s >out &&
1373 test_line_count = 3 out &&
1374 git ls-files -u >out &&
1375 test_line_count = 0 out &&
1376 git ls-files -o >out &&
1377 test_line_count = 1 out &&
1379 git rev-parse >actual \
1380 HEAD:y/b HEAD:y/c HEAD:z/d &&
1381 git rev-parse >expect \
1382 O:z/b O:z/c B:z/d &&
1383 test_cmp expect actual
1387 # Testcase 6d, We don't always want transitive renaming
1388 # (Related to testcase 1c)
1389 # Commit O: z/{b,c}, x/d
1390 # Commit A: z/{b,c}, x/d (no change)
1391 # Commit B: y/{b,c}, z/d
1392 # Expected: y/{b,c}, z/d
1393 # NOTE: Again, this seems obvious but just checking that the implementation
1394 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1396 test_expect_success
'6d-setup: We do not always want transitive renaming' '
1397 test_create_repo 6d &&
1408 git commit -m "O" &&
1416 git commit --allow-empty -m "A" &&
1426 test_expect_success
'6d-check: We do not always want transitive renaming' '
1432 git merge -s recursive B^0 &&
1434 git ls-files -s >out &&
1435 test_line_count = 3 out &&
1436 git ls-files -u >out &&
1437 test_line_count = 0 out &&
1438 git ls-files -o >out &&
1439 test_line_count = 1 out &&
1441 git rev-parse >actual \
1442 HEAD:y/b HEAD:y/c HEAD:z/d &&
1443 git rev-parse >expect \
1444 O:z/b O:z/c O:x/d &&
1445 test_cmp expect actual
1449 # Testcase 6e, Add/add from one-side
1451 # Commit A: z/{b,c} (no change)
1452 # Commit B: y/{b,c,d_1}, z/d_2
1453 # Expected: y/{b,c,d_1}, z/d_2
1454 # NOTE: Again, this seems obvious but just checking that the implementation
1455 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1456 # add/add conflict on y/d_1 vs y/d_2.
1458 test_expect_success
'6e-setup: Add/add from one side' '
1459 test_create_repo 6e &&
1468 git commit -m "O" &&
1476 git commit --allow-empty -m "A" &&
1489 test_expect_success
'6e-check: Add/add from one side' '
1495 git merge -s recursive B^0 &&
1497 git ls-files -s >out &&
1498 test_line_count = 4 out &&
1499 git ls-files -u >out &&
1500 test_line_count = 0 out &&
1501 git ls-files -o >out &&
1502 test_line_count = 1 out &&
1504 git rev-parse >actual \
1505 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1506 git rev-parse >expect \
1507 O:z/b O:z/c B:y/d B:z/d &&
1508 test_cmp expect actual
1512 ###########################################################################
1513 # Rules suggested by section 6:
1515 # Only apply implicit directory renames to directories if the other
1516 # side of history is the one doing the renaming.
1517 ###########################################################################