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

Re: --end-of-options inconsistently available?!

From
Jeff King <peff@peff.net>
Date
Dec 6, 2023, 21:16 UTC
Message-ID
<20231206211639.GB106480@coredump.intra.peff.net>
In-Reply-To
<ab14260c-d515-425e-8ef6-5739d3d6ca4e@cs-ware.de>
On Tue, Nov 28, 2023 at 09:40:08AM +0100, Sven Strickroth wrote:
Show 21 quoted lines
> > This one is intentional. rev-parse in its default mode is not just
> > spitting out revisions, but also options that are meant to be passed
> > along to the revision machinery via other commands (like rev-list). So
> > for example:
> > 
> >    $ git rev-parse --foo HEAD
> >    --foo
> >    564d0252ca632e0264ed670534a51d18a689ef5d
> > 
> > And it does understand end-of-options explicitly, so:
> > 
> >    $ git rev-parse --end-of-options --foo --
> >    --end-of-options
> >    fatal: bad revision '--foo'
> > 
> > If you just want to parse a name robustly, use --verify.
> 
> I would expect that -- and --end-of-options are handled in a special way
> here so that rev-parse can also be used in scripts. I need to check whether
> --verify works for me (from the manual I thought I need to specify full
> reference names).

They _are_ handled specially, and for the purpose of using rev-parse in scripts. It's just that in its default mode it does not do what you want, because it has another purpose.

Show 10 quoted lines
> > > $ git checkout -f --end-of-options HEAD~1 -- afile.txt
> > > fatal: only one reference expected, 2 given.
> > 
> > I think this is the same KEEP_DASHDASH problem as with git-reset.
> 
> I also found another problem:
> $ git format-patch --end-of-options -1
> fatal: option '-1' must come before non-option arguments
> 
> Where -1 is the number of commits here...

This is the same as the "log --end-of-options --foo" example I showed earlier. That "-1" cannot mean "use 1 commit", since you used it after --end-of-options. It will correctly resolve refs/heads/-1 if you have such a ref. But if you don't, then the DWIM logic for distinguishing revisions and pathspecs produces a confusing message.

It would be possible to fix that (by telling verify_filename() that we saw --end-of-options, and not to treat dashes specially). But in practice if you are bothering to use --end-of-options, you really ought to be using "--" as well, like:

  git format-patch --end-of-options $revs -- $paths
in which case it will know that "-1" _must_ be a revision, and complain:
  $ git format-patch --end-of-options -1 --
  fatal: bad revision '-1'
-Peff
Previous: Sven StrickrothNext: Jeff King
Message 4 of 5 in “--end-of-options inconsistently available?!”
  1. Sven StrickrothNov 27, 2023
  2. Jeff KingNov 27, 2023
  3. Sven StrickrothNov 28, 2023
  4. Jeff KingDec 6, 2023
  5. parse-options: decouple "--end-of-options" and "--"Jeff King, Dec 6, 2023

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.