Skip to content

Commit 7eecfa5

Browse files
prertikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa443d4 commit 7eecfa5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

builtin/rebase.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13681368
die(_("Could not detach HEAD"));
13691369
strbuf_release(&msg);
13701370

1371+
/*
1372+
* If the onto is a proper descendant of the tip of the branch, then
1373+
* we just fast-forwarded.
1374+
*/
1375+
strbuf_reset(&msg);
1376+
if (!oidcmp(&merge_base, &options.orig_head)) {
1377+
printf(_("Fast-forwarded %s to %s. \n"),
1378+
branch_name, options.onto_name);
1379+
strbuf_addf(&msg, "rebase finished: %s onto %s",
1380+
options.head_name ? options.head_name : "detached HEAD",
1381+
oid_to_hex(&options.onto->object.oid));
1382+
reset_head(NULL, "Fast-forwarded", options.head_name, 0,
1383+
"HEAD", msg.buf);
1384+
strbuf_release(&msg);
1385+
ret = !!finish_rebase(&options);
1386+
goto cleanup;
1387+
}
1388+
13711389
strbuf_addf(&revisions, "%s..%s",
13721390
options.root ? oid_to_hex(&options.onto->object.oid) :
13731391
(options.restrict_revision ?

0 commit comments

Comments
 (0)