Skip to content

Commit 17f09d1

Browse files
prertikdscho
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 af44bb7 commit 17f09d1

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
@@ -1099,6 +1099,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10991099
break;
11001100
}
11011101

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

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

0 commit comments

Comments
 (0)