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

[PATCH 2/2] merge-ort: fix slightly overzealous assertion for rename-to-self

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 6, 2025, 15:30 UTC
Message-ID
<f48b3310d4ae8d05780fd25e467083c4dc9852cc.1741275027.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1873.git.1741275027.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

merge-ort has a number of sanity checks on the file it is processing in process_renames(). One of these sanity checks was slightly overzealous because it indirectly assumed that a renamed file always ended up at a different path than where it started. That is normally an entirely fair assumption, but directory rename detection can make things interesting.

As a quick refresher, if one side of history renames directory A/ -> B/, and the other side of history adds new files to A/, then directory rename detection notices and suggests moving those new files to B/. A similar thing is done for paths renamed into A/, causing them to be transitively renamed into B/. But, if the file originally came from B/, then this can end up causing a file to be renamed back to itself.

It turns out the rest of the code following this assertion handled the case fine; the assertion was just an extra sanity check, not a rigid precondition. Therefore, simply adjust the assertion to pass under this special case as well.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c                         | 3 ++-
 t/t6423-merge-rename-directories.sh | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index 46e78c3ffa6..b0ff2236af0 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3048,7 +3048,8 @@ static int process_renames(struct merge_options *opt,
 			}
 		}
 
-		assert(source_deleted || oldinfo->filemask & old_sidemask);
+		assert(source_deleted || oldinfo->filemask & old_sidemask ||
+		       !strcmp(pair->one->path, pair->two->path));
 
 		/* Need to check for special types of rename conflicts... */
 		if (collision && !source_deleted) {
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh
index 259ee9628e4..9cbd41d3c69 100755
--- a/t/t6423-merge-rename-directories.sh
+++ b/t/t6423-merge-rename-directories.sh
@@ -5388,7 +5388,7 @@ test_setup_12n () {
 	)
 }
 
-test_expect_failure '12n: Directory rename transitively makes rename back to self' '
+test_expect_success '12n: Directory rename transitively makes rename back to self' '
 	test_setup_12n &&
 	(
 		cd 12n &&
-- 
gitgitgadget
Previous: Dmitry Goncharov via GitGitGadgetNext: Taylor Blau
Message 3 of 11 in “merge-ort: fix a crash in process_renames for a file transitively renamed to itself”
  1. 0/2 merge-ort: fix a crash in process_renames for a file transitively renamed to itselfElijah Newren via GitGitGadget, Mar 6, 2025
  2. 1/2 t6423: add a testcase causing a failed assertion in process_renamesDmitry Goncharov via GitGitGadget, Mar 6, 2025
  3. 2/2 merge-ort: fix slightly overzealous assertion for rename-to-selfElijah Newren via GitGitGadget, Mar 6, 2025
  4. Taylor BlauMar 12, 2025
  5. Elijah NewrenMar 12, 2025
  6. Junio C HamanoMar 12, 2025
  7. Elijah NewrenMar 13, 2025
  8. Junio C HamanoMar 13, 2025
  9. Elijah NewrenMar 13, 2025
  10. Junio C HamanoMar 13, 2025
  11. Elijah NewrenMar 14, 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.