summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Pratik Karki <predatoramigo@gmail.com>2018-08-08 21:21:32 +0545
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-10-11 14:16:05 +0900
commit7eecfa56017017208fd71c7aad9310a582a558ad (patch)
tree65f8bf87e3b9355a008ce14477941ddb14437eb2
parentbuiltin rebase: optionally pass custom reflogs to reset_head() (diff)
downloadtgif-7eecfa56017017208fd71c7aad9310a582a558ad.tar.xz
builtin rebase: fast-forward to onto if it is a proper descendant
When trying to rebase onto a direct descendant of HEAD, we can take a shortcut and fast-forward instead. This commit makes it so. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/rebase.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 49856d9bf7..7522be837c 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1368,6 +1368,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
die(_("Could not detach HEAD"));
strbuf_release(&msg);
+ /*
+ * If the onto is a proper descendant of the tip of the branch, then
+ * we just fast-forwarded.
+ */
+ strbuf_reset(&msg);
+ if (!oidcmp(&merge_base, &options.orig_head)) {
+ printf(_("Fast-forwarded %s to %s. \n"),
+ branch_name, options.onto_name);
+ strbuf_addf(&msg, "rebase finished: %s onto %s",
+ options.head_name ? options.head_name : "detached HEAD",
+ oid_to_hex(&options.onto->object.oid));
+ reset_head(NULL, "Fast-forwarded", options.head_name, 0,
+ "HEAD", msg.buf);
+ strbuf_release(&msg);
+ ret = !!finish_rebase(&options);
+ goto cleanup;
+ }
+
strbuf_addf(&revisions, "%s..%s",
options.root ? oid_to_hex(&options.onto->object.oid) :
(options.restrict_revision ?