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

[PATCH] Fix 3-way merge with file move when diff.renames = copies

From
David D. Kilzer <ddkilzer@kilzer.net>
Date
Nov 10, 2008, 23:53 UTC
Message-ID
<1226361207-7491-1-git-send-email-ddkilzer@kilzer.net>
In-Reply-To
<alpine.DEB.1.00.0811110039280.30769@pacific.mpi-cbg.de>

With diff.renames = copies, a 3-way merge (e.g. "git rebase") with a file move would fail with the following error:

    fatal: mode change for <file>, which is not in current HEAD
    Repository lacks necessary blobs to fall back on 3-way merge.
    Cannot fall back to three-way merge.
    Patch failed at 0001.

The bug is a logic error added in ece7b749, which attempts to find an sha1 for a patch with no index line in build_fake_ancestor(). Instead of failing unless an sha1 is found for both the old file and the new file, a failure should only be reported if neither the old file nor the new file is found.

Signed-off-by: David D. Kilzer <ddkilzer@kilzer.net>
---
Same as "[PATCH] 3-way merge with file move fails when diff.renames = copies"
but with an updated subject and initial sentence (added "with a file move").
 builtin-apply.c   |    2 +-
 t/t3400-rebase.sh |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 4c4d1e1..cfeb6cc 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2573,7 +2573,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
 		else if (get_sha1(patch->old_sha1_prefix, sha1))
 			/* git diff has no index line for mode/type changes */
 			if (!patch->lines_added && !patch->lines_deleted) {
-				if (get_current_sha1(patch->new_name, sha1) ||
+				if (get_current_sha1(patch->new_name, sha1) &&
 				    get_current_sha1(patch->old_name, sha1))
 					die("mode change for %s, which is not "
 						"in current HEAD", name);
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index b7a670e..a156850 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -84,4 +84,21 @@ test_expect_success 'rebase a single mode change' '
      GIT_TRACE=1 git rebase master
 '
 
+test_expect_success 'rebase a single file move with diff.renames = copies' '
+     git config diff.renames copies &&
+     git checkout master &&
+     echo 1 > Y &&
+     git add Y &&
+     test_tick &&
+     git commit -m "prepare file move" &&
+     git checkout -b filemove HEAD^ &&
+     echo 1 > Y &&
+     git add Y &&
+     mkdir D &&
+     git mv A D/A &&
+     test_tick &&
+     git commit -m filemove &&
+     GIT_TRACE=1 git rebase master
+'
+
 test_done
-- 
1.6.0
Previous: Johannes SchindelinNext: Junio C Hamano
Message 3 of 22 in “3-way merge with file move fails when diff.renames = copies”
  1. 3-way merge with file move fails when diff.renames = copiesDavid D. Kilzer, Nov 10, 2008
  2. Johannes SchindelinNov 10, 2008
  3. Fix 3-way merge with file move when diff.renames = copiesDavid D. Kilzer, Nov 10, 2008
  4. Junio C HamanoNov 10, 2008
  5. David D. KilzerNov 11, 2008
  6. Junio C HamanoNov 11, 2008
  7. Fix rebase with file move when diff.renames = copiesDavid D. Kilzer, Jul 21, 2010
  8. Junio C HamanoJul 21, 2010
  9. David D. KilzerJul 22, 2010
  10. Jonathan NiederJul 22, 2010
  11. David D. KilzerJul 22, 2010
  12. 0/5 Fix rebase with file move when diff.renames = copiesJonathan Nieder, Jul 23, 2010
  13. 1/5 t4150 (am): style tweaksJonathan Nieder, Jul 23, 2010
  14. 2/5 t4150 (am): futureproof against failing testsJonathan Nieder, Jul 23, 2010
  15. 3/5 Teach "apply --index-info" to handle rename patchesJonathan Nieder, Jul 23, 2010
  16. 4/5 t3400 (rebase): whitespace cleanupJonathan Nieder, Jul 23, 2010
  17. 5/5 rebase: protect against diff.renames configurationJonathan Nieder, Jul 23, 2010
  18. Sverre RabbelierJul 23, 2010
  19. Junio C HamanoJul 23, 2010
  20. Sverre RabbelierJul 23, 2010
  21. David D. KilzerJul 23, 2010
  22. Jonathan NiederJul 24, 2010

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.