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

[PATCH 6/6] builtin rebase: error out on incompatible option/mode combinations

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

While working on the GSoC project to convert the rebase command to a builtin, the rebase command learned to error out on certain command-line option combinations that cannot work, such as --whitespace=fix with --interactive.

This commit converts that code.
Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
---
 builtin/rebase.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index fb8ab5a177..4e69458161 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1098,6 +1098,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		break;
 	}
 
+	if (options.git_am_opt.len) {
+		const char *p;
+
+		/* all am options except -q are compatible only with --am */
+		strbuf_reset(&buf);
+		strbuf_addbuf(&buf, &options.git_am_opt);
+		strbuf_addch(&buf, ' ');
+		while ((p = strstr(buf.buf, " -q ")))
+			strbuf_splice(&buf, p - buf.buf, 4, " ", 1);
+		strbuf_trim(&buf);
+
+		if (is_interactive(&options) && buf.len)
+			die(_("error: cannot combine interactive options "
+			      "(--interactive, --exec, --rebase-merges, "
+			      "--preserve-merges, --keep-empty, --root + "
+			      "--onto) with am options (%s)"), buf.buf);
+		if (options.type == REBASE_MERGE && buf.len)
+			die(_("error: cannot combine merge options (--merge, "
+			      "--strategy, --strategy-option) with am options "
+			      "(%s)"), buf.buf);
+	}
+
 	if (options.signoff) {
 		if (options.type == REBASE_PRESERVE_MERGES)
 			die("cannot combine '--signoff' with "
@@ -1106,6 +1128,25 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		options.flags |= REBASE_FORCE;
 	}
 
+	if (options.type == REBASE_PRESERVE_MERGES)
+		/*
+		 * Note: incompatibility with --signoff handled in signoff block above
+		 * Note: incompatibility with --interactive is just a strong warning;
+		 *       git-rebase.txt caveats with "unless you know what you are doing"
+		 */
+		if (options.rebase_merges)
+			die(_("error: cannot combine '--preserve_merges' with "
+			      "'--rebase-merges'"));
+
+	if (options.rebase_merges) {
+		if (strategy_options.nr)
+			die(_("error: cannot combine '--rebase_merges' with "
+			      "'--strategy-option'"));
+		if (options.strategy)
+			die(_("error: cannot combine '--rebase_merges' with "
+			      "'--strategy'"));
+	}
+
 	if (!options.root) {
 		if (argc < 1) {
 			struct branch *branch;
-- 
2.18.0
Previous: Pratik Karki
Message 7 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.