Skip to content

Commit 6aba117

Browse files
newrengitster
authored andcommitted
am: avoid directory rename detection when calling recursive merge machinery
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fdddd9 commit 6aba117

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/am.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15961596
o.branch1 = "HEAD";
15971597
their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
15981598
o.branch2 = their_tree_name;
1599+
o.detect_directory_renames = 0;
15991600

16001601
if (state->quiet)
16011602
o.verbosity = 0;

t/t3401-rebase-and-am-rename.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ test_expect_success 'rebase --interactive: NO directory rename' '
152152
)
153153
'
154154

155-
test_expect_failure 'rebase (am): NO directory rename' '
155+
test_expect_success 'rebase (am): NO directory rename' '
156156
test_when_finished "git -C no-dir-rename rebase --abort" &&
157157
(
158158
cd no-dir-rename &&
@@ -190,7 +190,7 @@ test_expect_success 'rebase --merge: NO directory rename' '
190190
)
191191
'
192192

193-
test_expect_failure 'am: NO directory rename' '
193+
test_expect_success 'am: NO directory rename' '
194194
test_when_finished "git -C no-dir-rename am --abort" &&
195195
(
196196
cd no-dir-rename &&

0 commit comments

Comments
 (0)