builtin rebase: error out on incompatible option/mode combinations
authorPratik Karki <predatoramigo@gmail.com>
Wed, 8 Aug 2018 15:36:35 +0000 (21:21 +0545)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Oct 2018 05:16:05 +0000 (14:16 +0900)
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>
builtin/rebase.c
index 36d311b42fb9ebe2d482a1bdff61389b627aa080..d3d1d39bfa0fd6bca3c7668a1514693b5f9f60f5 100644 (file)
@@ -1099,6 +1099,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 "
@@ -1107,6 +1129,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;