]>
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 ###########################################################################