]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase: validate -C<n> and --whitespace=<mode> parameters early
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 14 Nov 2018 16:25:31 +0000 (08:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Nov 2018 02:52:13 +0000 (11:52 +0900)
It is a good idea to error out early upon seeing, say, `-Cbad`, rather
than starting the rebase only to have the `--am` backend complain later.

Let's do this.

The only options accepting parameters which we pass through to `git am`
(which may, or may not, forward them to `git apply`) are `-C` and
`--whitespace`. The other options we pass through do not accept
parameters, so we do not have to validate them here.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rebase.c
t/t3406-rebase-message.sh

index 96ffa80b7119e4436c5d078e157e530fb5af670f..571cf899d5b48c87c3c2f1d91d2d94e559bcfd68 100644 (file)
@@ -1064,12 +1064,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
        }
 
        for (i = 0; i < options.git_am_opts.argc; i++) {
-               const char *option = options.git_am_opts.argv[i];
+               const char *option = options.git_am_opts.argv[i], *p;
                if (!strcmp(option, "--committer-date-is-author-date") ||
                    !strcmp(option, "--ignore-date") ||
                    !strcmp(option, "--whitespace=fix") ||
                    !strcmp(option, "--whitespace=strip"))
                        options.flags |= REBASE_FORCE;
+               else if (skip_prefix(option, "-C", &p)) {
+                       while (*p)
+                               if (!isdigit(*(p++)))
+                                       die(_("switch `C' expects a "
+                                             "numerical value"));
+               } else if (skip_prefix(option, "--whitespace=", &p)) {
+                       if (*p && strcmp(p, "warn") && strcmp(p, "nowarn") &&
+                           strcmp(p, "error") && strcmp(p, "error-all"))
+                               die("Invalid whitespace option: '%s'", p);
+               }
        }
 
        if (!(options.flags & REBASE_NO_QUIET))
index 0392e36d2364c8149f2a628a0901f113b7a5875f..2c79eed4febda6977dde4d530d73a184cfa92d80 100755 (executable)
@@ -84,4 +84,11 @@ test_expect_success 'rebase --onto outputs the invalid ref' '
        test_i18ngrep "invalid-ref" err
 '
 
+test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
+       test_must_fail git rebase -Cnot-a-number HEAD 2>err &&
+       test_i18ngrep "numerical value" err &&
+       test_must_fail git rebase --whitespace=bad HEAD 2>err &&
+       test_i18ngrep "Invalid whitespace option" err
+'
+
 test_done