git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] t6423: document two bugs with rename-to-self testcases

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 22, 2025, 15:23 UTC
Message-ID
<bda42aa85cf4f332ef60aca1a8937ed4b868fa87.1753197791.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1943.git.1753197791.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

When commit 98a1a00d5301 (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 <newren@gmail.com>
---
 t/t6423-merge-rename-directories.sh | 101 +++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 2 deletions(-)
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh
index f48ed6d03534..69de7a3b84af 100755
--- a/t/t6423-merge-rename-directories.sh
+++ b/t/t6423-merge-rename-directories.sh
@@ -5056,6 +5056,25 @@ test_expect_success '12m: Change parent of renamed-dir to symlink on other side'
 	)
 '
 
+# Testcase 12n, Directory rename transitively makes rename back to self
+#
+# (Since this is a cherry-pick instead of merge, the labels are a bit weird.
+#  O, the original commit, is A~1 rather than what branch O points to.)
+#
+#   Commit O:  tools/hello
+#              world
+#   Commit A:  tools/hello
+#              tools/world
+#   Commit B:  hello
+#   In words:
+#     A: world -> tools/world
+#     B: tools/ -> /, i.e. rename all of tools to toplevel directory
+#        delete world
+#
+#   Expected:
+#             CONFLICT (file location): tools/world vs. world
+#
+
 test_setup_12n () {
 	git init 12n &&
 	(
@@ -5084,7 +5103,7 @@ test_setup_12n () {
 	)
 }
 
-test_expect_success '12n: Directory rename transitively makes rename back to self' '
+test_expect_failure '12n: Directory rename transitively makes rename back to self' '
 	test_setup_12n &&
 	(
 		cd 12n &&
@@ -5092,7 +5111,85 @@ test_expect_success '12n: Directory rename transitively makes rename back to sel
 		git checkout -q B^0 &&
 
 		test_must_fail git cherry-pick A^0 >out &&
-		grep "CONFLICT (file location).*should perhaps be moved" out
+		grep "CONFLICT (file location).*should perhaps be moved" out &&
+
+		# Should have 1 entry for hello, and 1 for world
+		test_stdout_line_count = 2 git ls-files -s &&
+		test_stdout_line_count = 1 git ls-files -s hello &&
+		test_stdout_line_count = 2 git ls-files -s world
+	)
+'
+
+# Testcase 12n2, Directory rename transitively makes rename back to self
+#
+#   Commit O:  tools/hello
+#              world
+#   Commit A:  tools/hello
+#              tools/world
+#   Commit B:  hello
+#   In words:
+#     A: world -> tools/world
+#     B: tools/ -> /, i.e. rename all of tools to toplevel directory
+#        delete world
+#
+#   Expected:
+#             CONFLICT (file location): tools/world vs. world
+#
+
+test_setup_12n2 () {
+	git init 12n2 &&
+	(
+		cd 12n2 &&
+
+		mkdir tools &&
+		echo hello >tools/hello &&
+		git add tools/hello &&
+		echo world >world &&
+		git add world &&
+		git commit -m "O" &&
+
+		git branch O &&
+		git branch A &&
+		git branch B &&
+
+		git switch A &&
+		git mv world tools/world &&
+		git commit -m "Move world into tools/" &&
+
+		git switch B &&
+		git mv tools/hello hello &&
+		git rm world &&
+		git commit -m "Move hello from tools/ to toplevel"
+	)
+}
+
+test_expect_failure '12n2: Directory rename transitively makes rename back to self' '
+	test_setup_12n2 &&
+	(
+		cd 12n2 &&
+
+		git checkout -q B^0 &&
+
+		# NOTE: Since merge.directoryRenames=true, there is no path
+		# conflict for world vs. tools/world; it should end up at
+		# world.  The fact that world was unmodified on side A, means
+		# there was no content conflict; we should just take the
+		# content from side B -- i.e. delete the file.  So merging
+		# could just delete world.
+		#
+		# However, rename-to-self-via-directory-rename is a bit more
+		# challenging.  Relax this test to allow world to be treated
+		# as a modify/delete conflict as well.
+
+		test_might_fail git -c merge.directoryRenames=true merge A^0 >out &&
+
+		# Should have 1 entry for hello, and either 0 or 2 for world
+		test_stdout_line_count = 1 git ls-files -s hello &&
+		test_stdout_line_count != 1 git ls-files -s world &&
+		if test_stdout_line_count != 0 git ls-files -s world
+		then
+			grep "CONFLICT (modify/delete).*world deleted in HEAD" out
+		fi
 	)
 '
 
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Patrick Steinhardt
Message 4 of 39 in “Fix various rename corner cases”
  1. 0/6 Fix various rename corner casesElijah Newren via GitGitGadget, Jul 22, 2025
  2. 1/6 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Jul 22, 2025
  3. 2/6 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Jul 22, 2025
  4. 3/6 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Jul 22, 2025
  5. Patrick SteinhardtAug 1, 2025
  6. Elijah NewrenAug 4, 2025
  7. Patrick SteinhardtAug 5, 2025
  8. Elijah NewrenAug 5, 2025
  9. 4/6 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Jul 22, 2025
  10. Patrick SteinhardtAug 1, 2025
  11. Elijah NewrenAug 4, 2025
  12. Patrick SteinhardtAug 5, 2025
  13. Elijah NewrenAug 5, 2025
  14. 5/6 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Jul 22, 2025
  15. Patrick SteinhardtAug 1, 2025
  16. Elijah NewrenAug 4, 2025
  17. Patrick SteinhardtAug 5, 2025
  18. Elijah NewrenAug 5, 2025
  19. 6/6 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Jul 22, 2025
  20. Patrick SteinhardtAug 1, 2025
  21. Elijah NewrenAug 4, 2025
  22. Patrick SteinhardtAug 1, 2025
  23. 0/6 Fix various rename corner casesElijah Newren via GitGitGadget, Aug 5, 2025
  24. 1/6 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Aug 5, 2025
  25. 2/6 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Aug 5, 2025
  26. 3/6 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Aug 5, 2025
  27. 4/6 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Aug 5, 2025
  28. 5/6 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Aug 5, 2025
  29. 6/6 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Aug 5, 2025
  30. Junio C HamanoAug 5, 2025
  31. Elijah NewrenAug 5, 2025
  32. 0/7 Fix various rename corner casesElijah Newren via GitGitGadget, Aug 6, 2025
  33. 1/7 merge-ort: update comments to modern testfile locationElijah Newren via GitGitGadget, Aug 6, 2025
  34. 2/7 merge-ort: drop unnecessary temporary in check_for_directory_rename()Elijah Newren via GitGitGadget, Aug 6, 2025
  35. 3/7 t6423: document two bugs with rename-to-self testcasesElijah Newren via GitGitGadget, Aug 6, 2025
  36. 4/7 t6423: fix missed staging of file in testcases 12i,12j,12kElijah Newren via GitGitGadget, Aug 6, 2025
  37. 5/7 merge-ort: clarify the interning of strings in opt->priv->pathElijah Newren via GitGitGadget, Aug 6, 2025
  38. 6/7 merge-ort: fix incorrect file handlingElijah Newren via GitGitGadget, Aug 6, 2025
  39. 7/7 merge-ort: fix directory rename on top of source of other rename/deleteElijah Newren via GitGitGadget, Aug 6, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.