Thread (30 messages) 30 messages, 3 authors, 14d ago

Re: [PATCH v2 0/4] rev-parse: exit 0 on --help

From: Junio C Hamano <hidden>
Date: 2026-07-01 22:06:55

"brian m. carlson" [off-list ref] writes:
The standard philosophy for Unix software when a help option (such as
--help) is specified is that the software should exit 0, printing the
help output to standard output, since the standard output is for
user-requested output and the program performed the requested task
successfully.  If the user specifies an incorrect option, then the help
output should be printed to standard error (since the user has made a
mistake) and it should exit unsuccessfully.
Hmph.
git rev-parse --parseopt properly directs the output in both of these
cases, but it currently exits 129 when it receives a --help or -h option
on the command line, which causes its invoking script to do the same.
This is not in line with the usual behavior and it causes scripts using
this command to exit unsuccessfully on --help as well.

This series introduces some changes to distinguish the --help and -h
options from other cases in which we print help output and adjusts the
exit code to 0 from those two options.  We continue to exit 129 when the
options are invalid, which is useful information to have for callers.
We also make the relevant changes such that `git rev-parse --parseopt`
does the same thing as long as it is invoked in the way specified in the
manual page (which a quick GitHub search shows almost everyone does).

One of the patches is rather long because we have many cases in which
we've hard-coded exit code 129 into our tests.  However, the changes
there should not be complex, only somewhat tedious to review.
It is borderline for "yes, we all know it is obvious that things
should have worked this way from day one, we regret that it is not
the case, but it has been working differently and users' scripts all
have been working with the current behaviour, and it is likely that
they will all break".

Two big things that make it much less likely, saving grace, are that
this is only about "--help" (which is unlikely to be a part of
end-user script), and this makes the invocation succeed (if we were
changing from exit 0 to exit 129, we would be breaking tons more).

;-)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help