Skip to content

Commit 9c85a1c

Browse files
dschogitster
authored andcommitted
rebase --rebase-merges: a "merge" into a new root is a fast-forward
When a user provides a todo list containing something like reset [new root] merge my-branch let's do the same as if pulling into an orphan branch: simply fast-forward. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebddf39 commit 9c85a1c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sequencer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,18 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
28702870
goto leave_merge;
28712871
}
28722872

2873+
if (opts->have_squash_onto &&
2874+
!oidcmp(&head_commit->object.oid, &opts->squash_onto)) {
2875+
/*
2876+
* When the user tells us to "merge" something into a
2877+
* "[new root]", let's simply fast-forward to the merge head.
2878+
*/
2879+
rollback_lock_file(&lock);
2880+
ret = fast_forward_to(&merge_commit->object.oid,
2881+
&head_commit->object.oid, 0, opts);
2882+
goto leave_merge;
2883+
}
2884+
28732885
if (commit) {
28742886
const char *message = get_commit_buffer(commit, NULL);
28752887
const char *body;

t/t3430-rebase-merges.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,17 @@ test_expect_success 'root commits' '
275275
test_cmp_rev HEAD $before
276276
'
277277

278+
test_expect_success 'a "merge" into a root commit is a fast-forward' '
279+
head=$(git rev-parse HEAD) &&
280+
cat >script-from-scratch <<-EOF &&
281+
reset [new root]
282+
merge $head
283+
EOF
284+
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
285+
test_tick &&
286+
git rebase -i -r HEAD^ &&
287+
test_cmp_rev HEAD $head
288+
'
289+
290+
278291
test_done

0 commit comments

Comments
 (0)