[PATCH v2 0/4] rev-parse: exit 0 on --help
From: brian m. carlson <hidden>
Date: 2026-07-01 21:24:53
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(-)