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>
Pratik Karki committed
Aug 8, 2018 at 21:21 UTC
7eecfa56017017208fd71c7aad9310a582a558ad
1 file changed
+18
builtin/rebase.c
+18
@@ -1368,6 +1368,24 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1368
die(_("Could not detach HEAD"));
1369
strbuf_release(&msg);
1370
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
+
1389
strbuf_addf(&revisions, "%s..%s",
1390
options.root ? oid_to_hex(&options.onto->object.oid) :
1391
(options.restrict_revision ?