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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 28, 2023 at 09:40:08AM +0100, Sven Strickroth wrote:

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

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux