diff --git a/revision.c b/revision.c index ee1df92d1d..a83e499047 100644 --- a/revision.c +++ b/revision.c @@ -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; diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 023fbff546..10c43e6e75 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -436,4 +436,15 @@ test_expect_success 'stdin with multiple groups reports error' ' test_must_fail git shortlog --group=author --group=committer 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