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 <predatoramigo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pratik Karki committed
Aug 8, 2018 at 21:21 UTC
b361bd754d141ef1010286dbe5fe810992a498a0
1 file changed
+41
builtin/rebase.c
+41
@@ -1099,6 +1099,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1099
break;
1100
}
1101
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
+
1124
if (options.signoff) {
1125
if (options.type == REBASE_PRESERVE_MERGES)
1126
die("cannot combine '--signoff' with "
@@ -1107,6 +1129,25 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1129
options.flags |= REBASE_FORCE;
1130
}
1131
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
+
1151
if (!options.root) {
1152
if (argc < 1) {
1153
struct branch *branch;