From: Johannes Schindelin Date: Thu, 3 May 2018 23:01:28 +0000 (+0200) Subject: rebase --rebase-merges: a "merge" into a new root is a fast-forward X-Git-Tag: v2.18.0-rc0~32^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c85a1c29c5ac26c94aa6eda8da9bbfbc6751785;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/sequencer.c b/sequencer.c index a7832399b1..65a8c49378 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2870,6 +2870,18 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, goto leave_merge; } + if (opts->have_squash_onto && + !oidcmp(&head_commit->object.oid, &opts->squash_onto)) { + /* + * When the user tells us to "merge" something into a + * "[new root]", let's simply fast-forward to the merge head. + */ + rollback_lock_file(&lock); + ret = fast_forward_to(&merge_commit->object.oid, + &head_commit->object.oid, 0, opts); + goto leave_merge; + } + if (commit) { const char *message = get_commit_buffer(commit, NULL); const char *body; diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 35260862fc..5543f1d5a3 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -275,4 +275,17 @@ test_expect_success 'root commits' ' test_cmp_rev HEAD $before ' +test_expect_success 'a "merge" into a root commit is a fast-forward' ' + head=$(git rev-parse HEAD) && + cat >script-from-scratch <<-EOF && + reset [new root] + merge $head + EOF + test_config sequence.editor \""$PWD"/replace-editor.sh\" && + test_tick && + git rebase -i -r HEAD^ && + test_cmp_rev HEAD $head +' + + test_done