Message ID | d3572e8bc85e4c7a33094f5da71957c2e59fd7f4.1624727121.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix bugs from interesting renaming pairs: one side renames A/file -> B/file, the other B/ -> A/ | expand |
On 6/26/2021 1:05 PM, Elijah Newren via GitGitGadget wrote: > From: Elijah Newren <newren@gmail.com> > > Directory rename detection can cause transitive renames, e.g. if the two > different sides of history each do one half of: > A/file -> B/file > B/ -> C/ > then directory rename detection transitively renames to give us C/file. > Since the default for merge.directoryRenames is conflict, this results > in an error message saying it is unclear whether the file should be > placed at B/file or C/file. > > What if C/ is A/, though? This case seems interesting, but somehow missing from the test cases below. Each of those cases include renaming up or down the directory hierarchy instead of doing a sideways rename. > +# Testcase 12i, Directory rename causes rename-to-self > +# Commit O: source/{subdir/foo, bar, baz_1} > +# Commit A: source/{foo, bar, baz_1} > +# Commit B: source/{subdir/{foo, bar}, baz_2} > +# Expected: source/{foo, bar, baz_2}, with conflicts on > +# source/bar vs. source/subdir/bar This test goes deeper. > +# Testcase 12j, Directory rename to root causes rename-to-self > +# Commit O: {subdir/foo, bar, baz_1} > +# Commit A: {foo, bar, baz_1} > +# Commit B: {subdir/{foo, bar}, baz_2} > +# Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar This test goes higher. Does the problematic case not hit when going out to the side, such as "with conflicts on subdir/bar vs otherdir/bar"? If so, then _maybe_ the commit message could indicate this is an omission on purpose. If not, then maybe a third test should be added? Thanks, -Stolee
On Tue, Jun 29, 2021 at 5:50 AM Derrick Stolee <stolee@gmail.com> wrote: > > On 6/26/2021 1:05 PM, Elijah Newren via GitGitGadget wrote: > > From: Elijah Newren <newren@gmail.com> > > > > Directory rename detection can cause transitive renames, e.g. if the two > > different sides of history each do one half of: > > A/file -> B/file > > B/ -> C/ > > then directory rename detection transitively renames to give us C/file. > > Since the default for merge.directoryRenames is conflict, this results > > in an error message saying it is unclear whether the file should be > > placed at B/file or C/file. > > > > What if C/ is A/, though? > > This case seems interesting, but somehow missing from the test cases > below. Each of those cases include renaming up or down the directory > hierarchy instead of doing a sideways rename. > > > +# Testcase 12i, Directory rename causes rename-to-self > > +# Commit O: source/{subdir/foo, bar, baz_1} > > +# Commit A: source/{foo, bar, baz_1} > > +# Commit B: source/{subdir/{foo, bar}, baz_2} > > +# Expected: source/{foo, bar, baz_2}, with conflicts on > > +# source/bar vs. source/subdir/bar > > This test goes deeper. > > > +# Testcase 12j, Directory rename to root causes rename-to-self > > +# Commit O: {subdir/foo, bar, baz_1} > > +# Commit A: {foo, bar, baz_1} > > +# Commit B: {subdir/{foo, bar}, baz_2} > > +# Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar > > This test goes higher. > > Does the problematic case not hit when going out to the side, such > as "with conflicts on subdir/bar vs otherdir/bar"? > > If so, then _maybe_ the commit message could indicate this is an > omission on purpose. If not, then maybe a third test should be > added? The only special case in the code is renaming to the root directory, so I didn't think of extending beyond two cases. However, while adding more testcases doesn't exercise the current incarnation of the code further, it's pretty easy to add another and it certainly doesn't hurt. I'll resubmit with a third testcase.
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh index be84d22419d..2a2ab907338 100755 --- a/t/t6423-merge-rename-directories.sh +++ b/t/t6423-merge-rename-directories.sh @@ -5024,6 +5024,123 @@ test_expect_failure '12h: renaming a file within a renamed directory' ' ) ' +# Testcase 12i, Directory rename causes rename-to-self +# Commit O: source/{subdir/foo, bar, baz_1} +# Commit A: source/{foo, bar, baz_1} +# Commit B: source/{subdir/{foo, bar}, baz_2} +# Expected: source/{foo, bar, baz_2}, with conflicts on +# source/bar vs. source/subdir/bar + +test_setup_12i () { + test_create_repo 12i && + ( + cd 12i && + + mkdir -p source/subdir && + echo foo >source/subdir/foo && + echo bar >source/bar && + echo baz >source/baz && + git add source && + git commit -m orig && + + git branch O && + git branch A && + git branch B && + + git switch A && + git mv source/subdir/foo source/foo && + git commit -m A && + + git switch B && + git mv source/bar source/subdir/bar && + echo more baz >>source/baz && + git commit -m B + ) +} + +test_expect_merge_algorithm failure failure '12i: Directory rename causes rename-to-self' ' + test_setup_12i && + ( + cd 12i && + + git checkout A^0 && + + test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 && + + test_path_is_missing source/subdir && + test_path_is_file source/bar && + test_path_is_file source/baz && + + git ls-files | uniq >tracked && + test_line_count = 3 tracked && + + git status --porcelain -uno >actual && + cat >expect <<-\EOF && + UU source/bar + M source/baz + EOF + test_cmp expect actual + ) +' + +# Testcase 12j, Directory rename to root causes rename-to-self +# Commit O: {subdir/foo, bar, baz_1} +# Commit A: {foo, bar, baz_1} +# Commit B: {subdir/{foo, bar}, baz_2} +# Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar + +test_setup_12j () { + test_create_repo 12j && + ( + cd 12j && + + mkdir -p subdir && + echo foo >subdir/foo && + echo bar >bar && + echo baz >baz && + git add . && + git commit -m orig && + + git branch O && + git branch A && + git branch B && + + git switch A && + git mv subdir/foo foo && + git commit -m A && + + git switch B && + git mv bar subdir/bar && + echo more baz >>baz && + git commit -m B + ) +} + +test_expect_merge_algorithm failure failure '12j: Directory rename to root causes rename-to-self' ' + test_setup_12j && + ( + cd 12j && + + git checkout A^0 && + + test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 && + + test_path_is_missing subdir && + test_path_is_file bar && + test_path_is_file baz && + + git ls-files | uniq >tracked && + test_line_count = 3 tracked && + + git status --porcelain -uno >actual && + cat >expect <<-\EOF && + UU bar + M baz + EOF + test_cmp expect actual + ) +' + ########################################################################### # SECTION 13: Checking informational and conflict messages #