* rev-parse: -- is sometimes a flag and sometimes an arg?
@ 2022-08-20 22:39 Tim Hockin
2022-08-20 22:59 ` Junio C Hamano
0 siblings, 1 reply; 8+ messages in thread
From: Tim Hockin @ 2022-08-20 22:39 UTC (permalink / raw)
To: git
```
$ 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.
Tim
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
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
2022-08-21 0:31 ` Tim Hockin
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2022-08-20 22:59 UTC (permalink / raw)
To: Tim Hockin; +Cc: git
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-20 22:59 ` Junio C Hamano
@ 2022-08-21 0:31 ` Tim Hockin
2022-08-21 0:36 ` Junio C Hamano
0 siblings, 1 reply; 8+ messages in thread
From: Tim Hockin @ 2022-08-21 0:31 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Thanks. Is there a more friendly way to do what I'm trying to
express? Should I just use `rev-list -n1` instead?
On Sat, Aug 20, 2022 at 3:59 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> 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.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-21 0:31 ` Tim Hockin
@ 2022-08-21 0:36 ` Junio C Hamano
2022-08-21 0:39 ` Tim Hockin
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2022-08-21 0:36 UTC (permalink / raw)
To: Tim Hockin; +Cc: git
Tim Hockin <thockin@google.com> writes:
> Thanks. Is there a more friendly way to do what I'm trying to
> express? Should I just use `rev-list -n1` instead?
That's hard to answer, as you didn't exactly say what you are trying
to express. All you asked was: why is "--" treated as an arg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-21 0:36 ` Junio C Hamano
@ 2022-08-21 0:39 ` Tim Hockin
2022-08-21 0:54 ` Junio C Hamano
0 siblings, 1 reply; 8+ messages in thread
From: Tim Hockin @ 2022-08-21 0:39 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Sorry, I assumed it was clear, but that was dumb of me.
I have a string - might be a tag name, might be a branch name, might
be a SHA (complete or partial). I want to resolve that into a
canonical SHA. My finger-memory is `git rev-parse`, but I can't say
if that's just a bad habit I picked up somewhere...
Tim
On Sat, Aug 20, 2022 at 5:36 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Tim Hockin <thockin@google.com> writes:
>
> > Thanks. Is there a more friendly way to do what I'm trying to
> > express? Should I just use `rev-list -n1` instead?
>
> That's hard to answer, as you didn't exactly say what you are trying
> to express. All you asked was: why is "--" treated as an arg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-21 0:39 ` Tim Hockin
@ 2022-08-21 0:54 ` Junio C Hamano
2022-08-23 0:51 ` brian m. carlson
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2022-08-21 0:54 UTC (permalink / raw)
To: Tim Hockin; +Cc: git
Tim Hockin <thockin@google.com> writes:
> Sorry, I assumed it was clear, but that was dumb of me.
>
> I have a string - might be a tag name, might be a branch name, might
> be a SHA (complete or partial). I want to resolve that into a
> canonical SHA.
"git rev-parse --verify string" would insist that 'string' is an
object name and show it as an object name to the standard output, or
gives an error message and exits with a non-zero status.
"git rev-parse --help" has some more elaborate examples in its
EXAMPLES section.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-21 0:54 ` Junio C Hamano
@ 2022-08-23 0:51 ` brian m. carlson
2022-08-23 17:45 ` Tim Hockin
0 siblings, 1 reply; 8+ messages in thread
From: brian m. carlson @ 2022-08-23 0:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Tim Hockin, git
[-- Attachment #1: Type: text/plain, Size: 842 bytes --]
On 2022-08-21 at 00:54:40, Junio C Hamano wrote:
> Tim Hockin <thockin@google.com> writes:
>
> > Sorry, I assumed it was clear, but that was dumb of me.
> >
> > I have a string - might be a tag name, might be a branch name, might
> > be a SHA (complete or partial). I want to resolve that into a
> > canonical SHA.
>
> "git rev-parse --verify string" would insist that 'string' is an
> object name and show it as an object name to the standard output, or
> gives an error message and exits with a non-zero status.
Note that this will print a full hex object ID whether it exists in the
repo or not if one is given (for example, the all-zeros object ID). If
you want to verify that the object exists, write this:
git rev-parse --verify string^{object}
--
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: rev-parse: -- is sometimes a flag and sometimes an arg?
2022-08-23 0:51 ` brian m. carlson
@ 2022-08-23 17:45 ` Tim Hockin
0 siblings, 0 replies; 8+ messages in thread
From: Tim Hockin @ 2022-08-23 17:45 UTC (permalink / raw)
To: brian m. carlson, Junio C Hamano, Tim Hockin, git
Thanks! That helps a lot.
On Mon, Aug 22, 2022 at 5:51 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> On 2022-08-21 at 00:54:40, Junio C Hamano wrote:
> > Tim Hockin <thockin@google.com> writes:
> >
> > > Sorry, I assumed it was clear, but that was dumb of me.
> > >
> > > I have a string - might be a tag name, might be a branch name, might
> > > be a SHA (complete or partial). I want to resolve that into a
> > > canonical SHA.
> >
> > "git rev-parse --verify string" would insist that 'string' is an
> > object name and show it as an object name to the standard output, or
> > gives an error message and exits with a non-zero status.
>
> Note that this will print a full hex object ID whether it exists in the
> repo or not if one is given (for example, the all-zeros object ID). If
> you want to verify that the object exists, write this:
>
> git rev-parse --verify string^{object}
> --
> brian m. carlson (he/him or they/them)
> Toronto, Ontario, CA
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-08-23 19:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).