From 253118d1d99b28b1c809e3607c0a182e141f3e45 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 25 Sep 2026 16:35:48 -0400 Subject: [PATCH] revision: avoid reporting known options as unknown on error In parse_revision_opt(), we report "unknown option" when handle_revision_opt() returns a negative value or zero. But these are two different conditions: a negative value indicates a malformed option (like a missing argument) and zero indicates an unknown option. So malformed options produce nonsense like this: $ git shortlog --default error: bad --default argument error: unknown option `--default' usage: [...] We should treat a negative return as a logic error which has already been reported by handle_revision_opt(), and just show the regular usage message. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 5 ++++- t/t4201-shortlog.sh | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index cf5e6c1ec9..1c9934fb4d 100644 --- a/revision.c +++ b/revision.c @@ -2734,7 +2734,10 @@ 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) { + if (n < 0) { + /* handle_revision_opt() has already reported the error. */ + usage_with_options(usagestr, options); + } else if (!n) { error("unknown option `%s'", ctx->argv[0]); usage_with_options(usagestr, options); } diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 5f23fc147b..cde519402e 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -434,4 +434,10 @@ 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_done