From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: Unexpected exit code for --help with rev-parse --parseopt
Date: Sun, 15 Mar 2026 16:59:48 +0000 [thread overview]
Message-ID: <abblhCBTgamxPOhD@fruit.crustytoothpaste.net> (raw)
In-Reply-To: <20260315031447.GB926820@coredump.intra.peff.net>
[-- Attachment #1: Type: text/plain, Size: 1751 bytes --]
On 2026-03-15 at 03:14:47, Jeff King wrote:
> So the calling program runs that cat command. And I think what you
> really want is to tack "exit 0" onto the end of that output, which would
> tell the callers to exit. Something like this:
>
> diff --git a/parse-options.c b/parse-options.c
> index a676da86f5..b990f38419 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -1473,8 +1473,10 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
> }
> fputc('\n', outfile);
>
> - if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
> + if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL) {
> fputs("EOF\n", outfile);
> + fputs("exit 0\n", outfile);
> + }
>
> return PARSE_OPT_HELP;
> }
Yeah, I did some poking around, saw the heredoc, and came to the same
conclusion that this was a viable solution. Since we both seem to agree
that this is a good solution and it also has the advantage of being
backward compatible (in that nobody has to change their code to get the
new behaviour[0]), this seems like the best option.
> And then you don't even need to change the exit code of rev-parse itself
> (since we'd never hit the "exit $?" that the caller tacks on in case of
> failure). Though I think it might be reasonable to switch it to 0
> anyway.
I can do that as well, even though I think that is actually
substantially more complicated than the first part. I'll write up a
bunch of new tests for these cases in addition.
Thanks for a sober second opinion.
[0] As we all know, sometimes one has to use older systems and having
scripts break on older systems needlessly is quite inconvenient.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2026-03-15 16:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 0:52 Unexpected exit code for --help with rev-parse --parseopt brian m. carlson
2026-03-15 3:14 ` Jeff King
2026-03-15 16:59 ` brian m. carlson [this message]
2026-03-15 18:16 ` Jeff King
2026-03-16 22:07 ` [PATCH] rev-parse: have --parseopt callers exit 0 on --help brian m. carlson
2026-03-17 0:47 ` Junio C Hamano
2026-03-17 11:59 ` brian m. carlson
2026-03-17 14:55 ` Jeff King
2026-03-17 15:07 ` Jeff King
2026-03-17 17:06 ` Junio C Hamano
2026-03-17 18:44 ` Jeff King
2026-03-18 0:24 ` brian m. carlson
2026-03-18 1:22 ` Jeff King
2026-03-18 2:45 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abblhCBTgamxPOhD@fruit.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.