From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: [PATCH v2 0/4] rev-parse: exit 0 on --help
Date: Wed, 1 Jul 2026 21:24:38 +0000 [thread overview]
Message-ID: <20260701212442.1430084-1-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20260316220742.1286157-1-sandals@crustytoothpaste.net>
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.
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.
brian m. carlson (4):
t1517: skip svn tests if svn is not installed
parse-options: add a separate case for help output on error
rev-parse: have --parseopt callers exit 0 on --help
parse-options: exit 0 on -h
builtin/blame.c | 2 ++
builtin/shortlog.c | 2 ++
builtin/update-index.c | 2 ++
contrib/subtree/t/t7900-subtree.sh | 2 +-
parse-options.c | 20 ++++++++++----
parse-options.h | 3 ++-
t/for-each-ref-tests.sh | 2 +-
t/t0012-help.sh | 2 +-
t/t0040-parse-options.sh | 2 +-
t/t0450-txt-doc-vs-help.sh | 2 +-
t/t0610-reftable-basics.sh | 4 +--
t/t1403-show-ref.sh | 2 +-
t/t1410-reflog.sh | 4 +--
t/t1418-reflog-exists.sh | 2 +-
t/t1502-rev-parse-parseopt.sh | 23 +++++++++-------
t/t1502/optionspec-neg.help | 1 +
t/t1502/optionspec.help | 1 +
t/t1517-outside-repo.sh | 43 +++++++++++++++++++++---------
t/t1800-hook.sh | 4 +--
t/t1900-repo-info.sh | 2 +-
t/t1901-repo-structure.sh | 2 +-
t/t2006-checkout-index-basic.sh | 6 ++---
t/t2107-update-index-basic.sh | 2 +-
t/t3004-ls-files-basic.sh | 6 ++---
t/t3200-branch.sh | 2 +-
t/t3903-stash.sh | 4 +--
t/t4200-rerere.sh | 2 +-
t/t5200-update-server-info.sh | 2 +-
t/t5304-prune.sh | 2 +-
t/t5400-send-pack.sh | 4 +--
t/t5512-ls-remote.sh | 2 +-
t/t6300-for-each-ref.sh | 4 +--
t/t6500-gc.sh | 2 +-
t/t7030-verify-tag.sh | 4 +--
t/t7508-status.sh | 4 +--
t/t7510-signed-commit.sh | 4 +--
t/t7600-merge.sh | 2 +-
t/t7800-difftool.sh | 3 +--
t/t7900-maintenance.sh | 2 +-
usage.c | 2 +-
40 files changed, 113 insertions(+), 73 deletions(-)
next prev parent reply other threads:[~2026-07-01 21:24 UTC|newest]
Thread overview: 30+ 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
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
2026-07-01 21:24 ` brian m. carlson [this message]
2026-07-01 21:24 ` [PATCH v2 1/4] t1517: skip svn tests if svn is not installed brian m. carlson
2026-07-01 22:10 ` Junio C Hamano
2026-07-01 22:27 ` Junio C Hamano
2026-07-02 14:47 ` [PATCH v2 1/4] t1517: skip svn tests if svn is not installed2sy brian m. carlson
2026-07-02 5:37 ` [PATCH v2 1/4] t1517: skip svn tests if svn is not installed Jeff King
2026-07-03 20:36 ` Junio C Hamano
2026-07-04 4:47 ` Jeff King
2026-07-01 21:24 ` [PATCH v2 2/4] parse-options: add a separate case for help output on error brian m. carlson
2026-07-02 8:38 ` Jeff King
2026-07-01 21:24 ` [PATCH v2 3/4] rev-parse: have --parseopt callers exit 0 on --help brian m. carlson
2026-07-01 22:16 ` Junio C Hamano
2026-07-01 21:24 ` [PATCH v2 4/4] parse-options: exit 0 on -h brian m. carlson
2026-07-01 22:06 ` [PATCH v2 0/4] rev-parse: exit 0 on --help Junio C Hamano
2026-07-02 8:45 ` Jeff King
2026-07-03 20:38 ` 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=20260701212442.1430084-1-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox