Merge branch 'jk/parse-revision-opt-fixes'
The command-line parsing of revision options has been updated to properly distinguish between malformed and unknown options, and to correctly report the name of unknown options after they have been moved during the option parsing process. * jk/parse-revision-opt-fixes: revision: handle argv movement in parse_revision_opt() revision: avoid reporting known options as unknown on errormain
commit
9ac1e81458
|
|
@ -2771,8 +2771,11 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
|
|||
{
|
||||
int n = handle_revision_opt(revs, ctx->argc, ctx->argv,
|
||||
&ctx->cpidx, ctx->out, NULL);
|
||||
if (n <= 0) {
|
||||
error("unknown option `%s'", ctx->argv[0]);
|
||||
if (n < 0) {
|
||||
/* handle_revision_opt() has already reported the error. */
|
||||
usage_with_options(usagestr, options);
|
||||
} else if (!n) {
|
||||
error("unknown option `%s'", ctx->out[ctx->cpidx - 1]);
|
||||
usage_with_options(usagestr, options);
|
||||
}
|
||||
ctx->argv += n;
|
||||
|
|
|
|||
|
|
@ -436,4 +436,15 @@ test_expect_success 'stdin with multiple groups reports error' '
|
|||
test_must_fail git shortlog --group=author --group=committer <log
|
||||
'
|
||||
|
||||
test_expect_success 'invalid revision options are not reported as unknown' '
|
||||
test_must_fail git shortlog --default 2>err &&
|
||||
test_grep "bad --default argument" err &&
|
||||
test_grep ! "unknown option" err
|
||||
'
|
||||
|
||||
test_expect_success 'unknown revision options are reported correctly' '
|
||||
test_must_fail git shortlog -n --no-such-option 2>err &&
|
||||
test_grep "unknown option .*--no-such-option" err
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
|
|||
Loading…
Reference in New Issue