public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>, git@vger.kernel.org
Subject: Re: [PATCH] rev-parse: have --parseopt callers exit 0 on --help
Date: Tue, 17 Mar 2026 14:44:41 -0400	[thread overview]
Message-ID: <20260317184441.GA574291@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqv7eul71y.fsf@gitster.g>

On Tue, Mar 17, 2026 at 10:06:17AM -0700, Junio C Hamano wrote:

> > 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

  reply	other threads:[~2026-03-17 18:44 UTC|newest]

Thread overview: 14+ 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 [this message]
2026-03-18  0:24             ` brian m. carlson
2026-03-18  1:22               ` Jeff King
2026-03-18  2:45                 ` 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=20260317184441.GA574291@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sandals@crustytoothpaste.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