]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase --rebase-merges: a "merge" into a new root is a fast-forward
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 3 May 2018 23:01:28 +0000 (01:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 6 May 2018 04:21:58 +0000 (13:21 +0900)
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>
sequencer.c
t/t3430-rebase-merges.sh

index a7832399b1f324560d4b18822eb8665b4a7a050b..65a8c493781034aa9a5a5651cb4a1db06aa213a8 100644 (file)
@@ -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;
index 35260862fcb759c9f29ded4fcf3ba0f19628631b..5543f1d5a346057548c633f6c718a0c6c5f568fe 100755 (executable)
@@ -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