Re: [PATCH] rev-parse: have --parseopt callers exit 0 on --help
- From
Jeff King <peff@peff.net>
- Date
- Mar 17, 2026, 18:44 UTC
- Message-ID
- <20260317184441.GA574291@coredump.intra.peff.net>
- In-Reply-To
- <xmqqv7eul71y.fsf@gitster.g>
On Tue, Mar 17, 2026 at 10:06:17AM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> > But this > > is not just a bug fix for --parseopt, but a change in overall intent. It > > might be worth digging in the commit history or list archive to see if > > there's any discussion on why we are using 129 in the first place. > > And if it turns out that old discussion was convincing enough, I'd > prefer to see us moving to --help/-h exiting with 0 eventually. I > do not mind doing so at the Git 3.0 boundary, if an excuse to make > a big change is needed ;-)
I could not find anything convincing. :)
We should also apply our little grey cells and see if we can think of any reason somebody would be unhappy with a change of exit code now. The most I could come up with is a script like:
#!/bin/sh git rev-list "$@" >tmp && do_something <tmp
where you might imagine it is run as "foo.sh --objects HEAD" or something. Right now, running:
foo.sh -h
will bail when rev-list returns 129, but in the proposed world it would keep going and run do_something. And you can further imagine a world where the script then quietly produces the wrong answer, because do_something thinks the rev-list output was empty (or actually it is worse; it gets the help output here).
I think this is mostly a case of "if it hurts, don't do it". The "-h" is not doing anything useful (the user does not even see the help text!), and if the script wants to support a usage message, it should parse the "-h" out separately.
Could somebody maliciously convince you to pass "-h" to such a script? Maybe, but not only are we getting into a series of increasingly unlikely events, but I think that means you probably have worse option-injection risks.
So unless somebody can come up with a more compelling example, I don't really see much backwards-compatibility risk. But maybe I just lack imagination. ;)
-Peff