Skip to content

Commit 62fddd5

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 5b7b27a commit 62fddd5

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
@@ -1367,6 +1367,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13671367
die(_("Could not detach HEAD"));
13681368
strbuf_release(&msg);
13691369

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

0 commit comments

Comments
 (0)