Skip to content

Commit bb6316a

Browse files
prertikgitster
authored andcommitted
builtin rebase: error out on incompatible option/mode combinations
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fed96e commit bb6316a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

builtin/rebase.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10981098
break;
10991099
}
11001100

1101+
if (options.git_am_opt.len) {
1102+
const char *p;
1103+
1104+
/* all am options except -q are compatible only with --am */
1105+
strbuf_reset(&buf);
1106+
strbuf_addbuf(&buf, &options.git_am_opt);
1107+
strbuf_addch(&buf, ' ');
1108+
while ((p = strstr(buf.buf, " -q ")))
1109+
strbuf_splice(&buf, p - buf.buf, 4, " ", 1);
1110+
strbuf_trim(&buf);
1111+
1112+
if (is_interactive(&options) && buf.len)
1113+
die(_("error: cannot combine interactive options "
1114+
"(--interactive, --exec, --rebase-merges, "
1115+
"--preserve-merges, --keep-empty, --root + "
1116+
"--onto) with am options (%s)"), buf.buf);
1117+
if (options.type == REBASE_MERGE && buf.len)
1118+
die(_("error: cannot combine merge options (--merge, "
1119+
"--strategy, --strategy-option) with am options "
1120+
"(%s)"), buf.buf);
1121+
}
1122+
11011123
if (options.signoff) {
11021124
if (options.type == REBASE_PRESERVE_MERGES)
11031125
die("cannot combine '--signoff' with "
@@ -1106,6 +1128,25 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11061128
options.flags |= REBASE_FORCE;
11071129
}
11081130

1131+
if (options.type == REBASE_PRESERVE_MERGES)
1132+
/*
1133+
* Note: incompatibility with --signoff handled in signoff block above
1134+
* Note: incompatibility with --interactive is just a strong warning;
1135+
* git-rebase.txt caveats with "unless you know what you are doing"
1136+
*/
1137+
if (options.rebase_merges)
1138+
die(_("error: cannot combine '--preserve_merges' with "
1139+
"'--rebase-merges'"));
1140+
1141+
if (options.rebase_merges) {
1142+
if (strategy_options.nr)
1143+
die(_("error: cannot combine '--rebase_merges' with "
1144+
"'--strategy-option'"));
1145+
if (options.strategy)
1146+
die(_("error: cannot combine '--rebase_merges' with "
1147+
"'--strategy'"));
1148+
}
1149+
11091150
if (!options.root) {
11101151
if (argc < 1) {
11111152
struct branch *branch;

0 commit comments

Comments
 (0)