Re: rev-parse: -- is sometimes a flag and sometimes an arg?
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 20, 2022, 22:59 UTC
- Message-ID
- <xmqq8rniikrg.fsf@gitster.g>
- In-Reply-To
- <CAO_RewbD+BJd1hPKCmCNM8wYBSUmZ2TuOoy6t1up1CT-rbn4DA@mail.gmail.com>
Tim Hockin <thockin@google.com> writes:
Show 33 quoted lines
> ``` > $ git rev-parse unknown-tag > unknown-tag > fatal: ambiguous argument 'unknown-tag': unknown revision or path not > in the working tree. > Use '--' to separate paths from revisions, like this: > 'git <command> [<revision>...] -- [<file>...]' > ``` > > OK > > ``` > $ git rev-parse unknown-tag -- > fatal: bad revision 'unknown-tag' > ``` > > Much nicer error. But: > > ``` > $ git rev-parse HEAD -- > 113a928239196d0d9f70671517ce917071ceecf6 > -- > ``` > > That's not very nice. Why is "--" treated as an arg? > > ``` > $ git rev-parse HEAD > 113a928239196d0d9f70671517ce917071ceecf6 > ``` > > Looking at rev-parse code it SEEMS to be intentional, but I can't > comprehend why.
Because the first function of "rev-parse" (among many others) is to be a helper usable in scripted Porcelains to "parse" command line arguments, shifting them into revs and "files". Without options like --revs-only, --no-revs, --flags etc., it dumps everything, while translating "revs" into raw object names, to its output. "--" is a valid command line option for whatever scripted Porcelain you'd be writing using "rev-parse" to help parsing its command line arguments.
So everything we see above is very much working as designed.