From: Junio C Hamano <gitster@pobox.com>
To: Tim Hockin <thockin@google.com>
Cc: git@vger.kernel.org
Subject: Re: rev-parse: -- is sometimes a flag and sometimes an arg?
Date: Sat, 20 Aug 2022 15:59:47 -0700 [thread overview]
Message-ID: <xmqq8rniikrg.fsf@gitster.g> (raw)
In-Reply-To: <CAO_RewbD+BJd1hPKCmCNM8wYBSUmZ2TuOoy6t1up1CT-rbn4DA@mail.gmail.com> (Tim Hockin's message of "Sat, 20 Aug 2022 15:39:54 -0700")
Tim Hockin <thockin@google.com> writes:
> ```
> $ 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.
next prev parent reply other threads:[~2022-08-20 22:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-20 22:39 rev-parse: -- is sometimes a flag and sometimes an arg? Tim Hockin
2022-08-20 22:59 ` Junio C Hamano [this message]
2022-08-21 0:31 ` Tim Hockin
2022-08-21 0:36 ` Junio C Hamano
2022-08-21 0:39 ` Tim Hockin
2022-08-21 0:54 ` Junio C Hamano
2022-08-23 0:51 ` brian m. carlson
2022-08-23 17:45 ` Tim Hockin
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=xmqq8rniikrg.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=thockin@google.com \
/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