git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] builtin rebase: fast-forward to onto if it is a proper descendant

From
Pratik Karki <predatoramigo@gmail.com>
Date
Aug 8, 2018, 15:36 UTC
Message-ID
<20180808153635.19944-4-predatoramigo@gmail.com>
In-Reply-To
<20180808153635.19944-1-predatoramigo@gmail.com>

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>
---
 builtin/rebase.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index c51b9d288a..1bb64e7cd7 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1367,6 +1367,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 ?
-- 
2.18.0
Previous: Pratik KarkiNext: Pratik Karki
Message 4 of 7 in “builtin rebase rest”
  1. Pratik KarkiAug 8, 2018
  2. 1/6 builtin rebase: optionally auto-detect the upstreamPratik Karki, Aug 8, 2018
  3. 2/6 builtin rebase: optionally pass custom reflogs to reset_head()Pratik Karki, Aug 8, 2018
  4. 3/6 builtin rebase: fast-forward to onto if it is a proper descendantPratik Karki, Aug 8, 2018
  5. 4/6 builtin rebase: show progress when connected to a terminalPratik Karki, Aug 8, 2018
  6. 5/6 builtin rebase: use no-op editor when interactive is "implied"Pratik Karki, Aug 8, 2018
  7. 6/6 builtin rebase: error out on incompatible option/mode combinationsPratik Karki, Aug 8, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.