git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Junio C HamanoNext: brian m. carlson
Message 11 of 39 in “Unexpected exit code for --help with rev-parse --parseopt”
  1. brian m. carlsonMar 15, 2026
  2. Jeff KingMar 15, 2026
  3. brian m. carlsonMar 15, 2026
  4. Jeff KingMar 15, 2026
  5. rev-parse: have --parseopt callers exit 0 on --helpbrian m. carlson, Mar 16, 2026
  6. Junio C HamanoMar 17, 2026
  7. brian m. carlsonMar 17, 2026
  8. Jeff KingMar 17, 2026
  9. Jeff KingMar 17, 2026
  10. Junio C HamanoMar 17, 2026
  11. Jeff KingMar 17, 2026
  12. brian m. carlsonMar 18, 2026
  13. Jeff KingMar 18, 2026
  14. Junio C HamanoMar 18, 2026
  15. 0/4 rev-parse: exit 0 on --helpbrian m. carlson, Jul 1, 2026
  16. 3/4 rev-parse: have --parseopt callers exit 0 on --helpbrian m. carlson, Jul 1, 2026
  17. Junio C HamanoJul 1, 2026
  18. 1/4 t1517: skip svn tests if svn is not installedbrian m. carlson, Jul 1, 2026
  19. Junio C HamanoJul 1, 2026
  20. Junio C HamanoJul 1, 2026
  21. brian m. carlsonJul 2, 2026
  22. Jeff KingJul 2, 2026
  23. Junio C HamanoJul 3, 2026
  24. Jeff KingJul 4, 2026
  25. 4/4 parse-options: exit 0 on -hbrian m. carlson, Jul 1, 2026
  26. 2/4 parse-options: add a separate case for help output on errorbrian m. carlson, Jul 1, 2026
  27. Jeff KingJul 2, 2026
  28. Junio C HamanoJul 1, 2026
  29. Jeff KingJul 2, 2026
  30. Junio C HamanoJul 3, 2026
  31. 0/4 parseopt: exit 0 on helpbrian m. carlson, Jul 8, 2026
  32. 1/4 t1517: skip svn tests if svn is not installedbrian m. carlson, Jul 8, 2026
  33. Junio C HamanoJul 8, 2026
  34. 3/4 rev-parse: have --parseopt callers exit 0 on --helpbrian m. carlson, Jul 8, 2026
  35. 2/4 parse-options: add a separate case for help output on errorbrian m. carlson, Jul 8, 2026
  36. Junio C HamanoJul 8, 2026
  37. 4/4 parse-options: exit 0 on -hbrian m. carlson, Jul 8, 2026
  38. Jeff KingJul 8, 2026
  39. Junio C HamanoJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.