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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 4, 2018 at 01:01 UTC 9c85a1c29c5ac26c94aa6eda8da9bbfbc6751785
2 files changed +25
sequencer.c
+12
@@ -2870,6 +2870,18 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
2870 goto leave_merge;
2871 }
2872
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 +
2885 if (commit) {
2886 const char *message = get_commit_buffer(commit, NULL);
2887 const char *body;
t/t3430-rebase-merges.sh
+13
@@ -275,4 +275,17 @@ test_expect_success 'root commits' '
275 test_cmp_rev HEAD $before
276 '
277
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 +
291 test_done