Skip to content

Commit c4ce5e4

Browse files
newrengitster
authored andcommitted
t6423: document two bugs with rename-to-self testcases
When commit 98a1a00 (t6423: add a testcase causing a failed assertion in process_renames, 2025-03-06) was added, I tweaked the commit message, and moved the test into t6423. However, that still left two other things missing that made this test unlike the others in the same testfile: * It didn't have an English description of the test setup like all other tests in t6423 * It didn't check that the right number of files were present at the end The former issue is a minor detail that isn't that critical, but the latter feels more important. If it had been done, I might have noticed another bug. In particular, this testcase involves Side A: rename world -> tools/world and Side B: rename tools/ -> <the toplevel> Side B: remove world The tools/ -> <toplevel> rename turns the world -> tools/world rename into world -> world, i.e. a rename-to-self case. But, it's a path conflict because merge.directoryRenames defaults to false. There's no content conflict because Side A didn't modify world, so we should just take the content of world from Side B -- i.e. delete it. So, we have a conflict on the path, but not on its content. We could consider letting the content trump since it is unconflicted, but if we are going to leave a conflict, it should certainly represent that 'world' existed both in the base version and on Side A. Currently it doesn't. Add a description of this test, add some checking of the number of entries in the index at the end of the merge, and mark the test as expecting to fail for now. A subsequent commit will fix this bug. While at it, I found another related bug from a nearly identical setup but setting merge.directoryRenames=true. Copy testcase 12n into 12n2, changing it to use merge instead of cherry-pick, and turn on directory renames for this test. In this case, since there is no content conflict and no path conflict, it should be okay to delete the file. Unfortunately, the code resolves without conflict but silently leaves world despite the fact it should be deleted. It might also be okay if the code spuriously thought there was a modify/delete conflict here; that would at least notify users to look closer and then when they notice there was no change since the base version, they can easily resolve. A conflict notice is much better than silently providing the wrong resolution. Cover this with the 12n2 testcase, which for now is marked as expecting to fail as well. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42a5b15 commit c4ce5e4

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

t/t6423-merge-rename-directories.sh

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,6 +5056,25 @@ test_expect_success '12m: Change parent of renamed-dir to symlink on other side'
50565056
)
50575057
'
50585058

5059+
# Testcase 12n, Directory rename transitively makes rename back to self
5060+
#
5061+
# (Since this is a cherry-pick instead of merge, the labels are a bit weird.
5062+
# O, the original commit, is A~1 rather than what branch O points to.)
5063+
#
5064+
# Commit O: tools/hello
5065+
# world
5066+
# Commit A: tools/hello
5067+
# tools/world
5068+
# Commit B: hello
5069+
# In words:
5070+
# A: world -> tools/world
5071+
# B: tools/ -> /, i.e. rename all of tools to toplevel directory
5072+
# delete world
5073+
#
5074+
# Expected:
5075+
# CONFLICT (file location): tools/world vs. world
5076+
#
5077+
50595078
test_setup_12n () {
50605079
git init 12n &&
50615080
(
@@ -5084,15 +5103,93 @@ test_setup_12n () {
50845103
)
50855104
}
50865105

5087-
test_expect_success '12n: Directory rename transitively makes rename back to self' '
5106+
test_expect_failure '12n: Directory rename transitively makes rename back to self' '
50885107
test_setup_12n &&
50895108
(
50905109
cd 12n &&
50915110
50925111
git checkout -q B^0 &&
50935112
50945113
test_must_fail git cherry-pick A^0 >out &&
5095-
grep "CONFLICT (file location).*should perhaps be moved" out
5114+
grep "CONFLICT (file location).*should perhaps be moved" out &&
5115+
5116+
# Should have 1 entry for hello, and 1 for world
5117+
test_stdout_line_count = 2 git ls-files -s &&
5118+
test_stdout_line_count = 1 git ls-files -s hello &&
5119+
test_stdout_line_count = 2 git ls-files -s world
5120+
)
5121+
'
5122+
5123+
# Testcase 12n2, Directory rename transitively makes rename back to self
5124+
#
5125+
# Commit O: tools/hello
5126+
# world
5127+
# Commit A: tools/hello
5128+
# tools/world
5129+
# Commit B: hello
5130+
# In words:
5131+
# A: world -> tools/world
5132+
# B: tools/ -> /, i.e. rename all of tools to toplevel directory
5133+
# delete world
5134+
#
5135+
# Expected:
5136+
# CONFLICT (file location): tools/world vs. world
5137+
#
5138+
5139+
test_setup_12n2 () {
5140+
git init 12n2 &&
5141+
(
5142+
cd 12n2 &&
5143+
5144+
mkdir tools &&
5145+
echo hello >tools/hello &&
5146+
git add tools/hello &&
5147+
echo world >world &&
5148+
git add world &&
5149+
git commit -m "O" &&
5150+
5151+
git branch O &&
5152+
git branch A &&
5153+
git branch B &&
5154+
5155+
git switch A &&
5156+
git mv world tools/world &&
5157+
git commit -m "Move world into tools/" &&
5158+
5159+
git switch B &&
5160+
git mv tools/hello hello &&
5161+
git rm world &&
5162+
git commit -m "Move hello from tools/ to toplevel"
5163+
)
5164+
}
5165+
5166+
test_expect_failure '12n2: Directory rename transitively makes rename back to self' '
5167+
test_setup_12n2 &&
5168+
(
5169+
cd 12n2 &&
5170+
5171+
git checkout -q B^0 &&
5172+
5173+
# NOTE: Since merge.directoryRenames=true, there is no path
5174+
# conflict for world vs. tools/world; it should end up at
5175+
# world. The fact that world was unmodified on side A, means
5176+
# there was no content conflict; we should just take the
5177+
# content from side B -- i.e. delete the file. So merging
5178+
# could just delete world.
5179+
#
5180+
# However, rename-to-self-via-directory-rename is a bit more
5181+
# challenging. Relax this test to allow world to be treated
5182+
# as a modify/delete conflict as well.
5183+
5184+
test_might_fail git -c merge.directoryRenames=true merge A^0 >out &&
5185+
5186+
# Should have 1 entry for hello, and either 0 or 2 for world
5187+
test_stdout_line_count = 1 git ls-files -s hello &&
5188+
test_stdout_line_count != 1 git ls-files -s world &&
5189+
if test_stdout_line_count != 0 git ls-files -s world
5190+
then
5191+
grep "CONFLICT (modify/delete).*world deleted in HEAD" out
5192+
fi
50965193
)
50975194
'
50985195

0 commit comments

Comments
 (0)