Skip to content

Commit 04519d7

Browse files
dschogitster
authored andcommitted
rebase: validate -C<n> and --whitespace=<mode> parameters early
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f576968 commit 04519d7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

builtin/rebase.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,12 +1064,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10641064
}
10651065

10661066
for (i = 0; i < options.git_am_opts.argc; i++) {
1067-
const char *option = options.git_am_opts.argv[i];
1067+
const char *option = options.git_am_opts.argv[i], *p;
10681068
if (!strcmp(option, "--committer-date-is-author-date") ||
10691069
!strcmp(option, "--ignore-date") ||
10701070
!strcmp(option, "--whitespace=fix") ||
10711071
!strcmp(option, "--whitespace=strip"))
10721072
options.flags |= REBASE_FORCE;
1073+
else if (skip_prefix(option, "-C", &p)) {
1074+
while (*p)
1075+
if (!isdigit(*(p++)))
1076+
die(_("switch `C' expects a "
1077+
"numerical value"));
1078+
} else if (skip_prefix(option, "--whitespace=", &p)) {
1079+
if (*p && strcmp(p, "warn") && strcmp(p, "nowarn") &&
1080+
strcmp(p, "error") && strcmp(p, "error-all"))
1081+
die("Invalid whitespace option: '%s'", p);
1082+
}
10731083
}
10741084

10751085
if (!(options.flags & REBASE_NO_QUIET))

t/t3406-rebase-message.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,11 @@ test_expect_success 'rebase --onto outputs the invalid ref' '
8484
test_i18ngrep "invalid-ref" err
8585
'
8686

87+
test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
88+
test_must_fail git rebase -Cnot-a-number HEAD 2>err &&
89+
test_i18ngrep "numerical value" err &&
90+
test_must_fail git rebase --whitespace=bad HEAD 2>err &&
91+
test_i18ngrep "Invalid whitespace option" err
92+
'
93+
8794
test_done

0 commit comments

Comments
 (0)