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

[PATCH 3/3] am: avoid directory rename detection when calling recursive merge machinery

From
Elijah Newren <newren@gmail.com>
Date
Aug 29, 2018, 07:06 UTC
Message-ID
<20180829070613.11793-4-newren@gmail.com>
In-Reply-To
<20180829070613.11793-1-newren@gmail.com>

Let's say you have the following three trees, where Base is from one commit behind either master or branch:

   Base  : bar_v1, foo/{file1, file2, file3}
   branch: bar_v2, foo/{file1, file2},       goo/file3
   master: bar_v3, foo/{file1, file2, file3}

Using git-am (or am-based rebase) to apply the changes from branch onto master results in the following tree:

   Result: bar_merged, goo/{file1, file2, file3}

This is not what users want; they did not rename foo/ -> goo/, they only renamed one file within that directory. The reason this happens is am constructs fake trees (via build_fake_ancestor()) of the following form:

   Base_bfa  : bar_v1, foo/file3
   branch_bfa: bar_v2, goo/file3
Combining these two trees with master's tree:
   master: bar_v3, foo/{file1, file2, file3},

You can see that merge_recursive_generic() would see branch_bfa as renaming foo/ -> goo/, and master as just adding both foo/file1 and foo/file2. As such, it ends up with goo/{file1, file2, file3}

The core problem is that am does not have access to the original trees; it can only construct trees using the blobs involved in the patch. As such, it is not safe to perform directory rename detection within am -3.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/am.c                    | 1 +
 t/t3401-rebase-and-am-rename.sh | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 2fc2d1e82c..1494a9be84 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1596,6 +1596,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 	o.branch1 = "HEAD";
 	their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
 	o.branch2 = their_tree_name;
+	o.detect_directory_renames = 0;
 
 	if (state->quiet)
 		o.verbosity = 0;
diff --git a/t/t3401-rebase-and-am-rename.sh b/t/t3401-rebase-and-am-rename.sh
index a87df9e675..94bdfbd69c 100755
--- a/t/t3401-rebase-and-am-rename.sh
+++ b/t/t3401-rebase-and-am-rename.sh
@@ -152,7 +152,7 @@ test_expect_success 'rebase --interactive: NO directory rename' '
 	)
 '
 
-test_expect_failure 'rebase (am): NO directory rename' '
+test_expect_success 'rebase (am): NO directory rename' '
 	test_when_finished "git -C no-dir-rename rebase --abort" &&
 	(
 		cd no-dir-rename &&
@@ -190,7 +190,7 @@ test_expect_success 'rebase --merge: NO directory rename' '
 	)
 '
 
-test_expect_failure 'am: NO directory rename' '
+test_expect_success 'am: NO directory rename' '
 	test_when_finished "git -C no-dir-rename am --abort" &&
 	(
 		cd no-dir-rename &&
-- 
2.18.0.12.g97a29da30a
Previous: Elijah NewrenNext: Johannes Schindelin
Message 16 of 20 in “A rebase regression in Git 2.18.0”
  1. Nikolay KasyanovAug 28, 2018
  2. Ævar Arnfjörð BjarmasonAug 28, 2018
  3. Johannes SchindelinAug 28, 2018
  4. Nikolay KasyanovAug 28, 2018
  5. Elijah NewrenAug 28, 2018
  6. Junio C HamanoAug 28, 2018
  7. 0/3 Turn off directory rename detection in am -3Elijah Newren, Aug 29, 2018
  8. 1/3 t3401: add another directory rename testcase for rebase and amElijah Newren, Aug 29, 2018
  9. Junio C HamanoAug 29, 2018
  10. Elijah NewrenAug 29, 2018
  11. Junio C HamanoAug 30, 2018
  12. Elijah NewrenAug 30, 2018
  13. 2/3 merge-recursive: add ability to turn off directory rename detectionElijah Newren, Aug 29, 2018
  14. Johannes SchindelinAug 29, 2018
  15. Elijah NewrenAug 29, 2018
  16. 3/3 am: avoid directory rename detection when calling recursive merge machineryElijah Newren, Aug 29, 2018
  17. Johannes SchindelinAug 29, 2018
  18. Elijah NewrenAug 30, 2018
  19. Johannes SchindelinAug 31, 2018
  20. Elijah NewrenAug 31, 2018

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.