All of lore.kernel.org
 help / color / mirror / Atom feed
* No clear API/Error message to validate a "revision object" using git rev-parse
@ 2019-01-29  9:25 Ντέντος Σταύρος
  2019-01-29 10:51 ` Christian Couder
  0 siblings, 1 reply; 3+ messages in thread
From: Ντέντος Σταύρος @ 2019-01-29  9:25 UTC (permalink / raw)
  To: git

Hello there everyone,

Minor bug report:
I have a utility script to find "reference points" that contain a
commit (git-x-in-y)

The script needs to accept "any valid reference point", that includes
e.g. tags as well.
I validate said input by passing whatever argument through git rev-parse.

If the tag name is invalid, say:
$ git rev-parse version.3
version.3
fatal: ambiguous argument 'version.3': unknown revision or path not in
the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

So, I follow the recommendation to add '--', since I know that I won't
be adding any paths:

$ git rev-parse version.3 --
fatal: bad revision 'version.3'

However, what happens with the correct tags is, I get the trailing
double dash in:
$  git rev-parse version-0.false --
d43292476ea9ab8c3d32940352b680549b64e8d8
--
$

A further leading argument, e.g. '' makes the situation worse:
$ git rev-parse version-0.false -- ''
d43292476ea9ab8c3d32940352b680549b64e8d8
--

$

`--verify`s error message is even more cryptic:
$ git rev-parse --verify version.3
fatal: Needed a single revision
$ git rev-parse --verify version-0.false
80f20b100cca5166b22cbcc1f4a6ac1eae64a0d0

Further attempts do not help either:
$  git rev-parse --revs-only version-3 ; echo $?
0
$

Am I writing the command wrong, or is there some part of it I don't understand?

Ntentos Stavros

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: No clear API/Error message to validate a "revision object" using git rev-parse
  2019-01-29  9:25 No clear API/Error message to validate a "revision object" using git rev-parse Ντέντος Σταύρος
@ 2019-01-29 10:51 ` Christian Couder
  2019-01-29 12:01   ` Ντέντος Σταύρος
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2019-01-29 10:51 UTC (permalink / raw)
  To: Ντέντος
	Σταύρος
  Cc: git

Hi,

On Tue, Jan 29, 2019 at 10:30 AM Ντέντος Σταύρος <stdedos@gmail.com> wrote:

> So, I follow the recommendation to add '--', since I know that I won't
> be adding any paths:
>
> $ git rev-parse version.3 --
> fatal: bad revision 'version.3'
>
> However, what happens with the correct tags is, I get the trailing
> double dash in:
> $  git rev-parse version-0.false --
> d43292476ea9ab8c3d32940352b680549b64e8d8
> --
> $

Yeah, it looks like a bug to me.

> A further leading argument, e.g. '' makes the situation worse:
> $ git rev-parse version-0.false -- ''
> d43292476ea9ab8c3d32940352b680549b64e8d8
> --
>
> $

This also.

> `--verify`s error message is even more cryptic:
> $ git rev-parse --verify version.3
> fatal: Needed a single revision

Yeah, but it works.

The error message could perhaps be improved. On the other hand it has
been the same for a very very long time and very few people complained
about it.

As you are writing a script, you can at least easily redirect it to
/dev/null and output something else.

In fact as `git rev-parse` is a "plumbing command" it's supposed to be
used mostly by scripts and power user who can easily deal with such an
error message, which explains why there has not been much incentive to
change this error message.

> $ git rev-parse --verify version-0.false
> 80f20b100cca5166b22cbcc1f4a6ac1eae64a0d0

This also works correctly.

And:

$ git rev-parse --verify v2.2.0 --
74d2a8cf12bf102a8cedaf66736503bb3fe88dfb
$

also works correctly.

Best,
Christian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: No clear API/Error message to validate a "revision object" using git rev-parse
  2019-01-29 10:51 ` Christian Couder
@ 2019-01-29 12:01   ` Ντέντος Σταύρος
  0 siblings, 0 replies; 3+ messages in thread
From: Ντέντος Σταύρος @ 2019-01-29 12:01 UTC (permalink / raw)
  To: Christian Couder; +Cc: git

On Tue, Jan 29, 2019 at 12:51 PM Christian Couder
<christian.couder@gmail.com> wrote:
> > `--verify`s error message is even more cryptic:
> > $ git rev-parse --verify version.3
> > fatal: Needed a single revision
>
> Yeah, but it works.
>
> The error message could perhaps be improved. On the other hand it has
> been the same for a very very long time and very few people complained
> about it.
>
> [...]
>
> In fact as `git rev-parse` is a "plumbing command" it's supposed to be
> used mostly by scripts and power user who can easily deal with such an
> error message, which explains why there has not been much incentive to
> change this error message.

I understand the points here, and I understand how minor this "issue"
is in a sense.
Maintainers / fixer can decide on it, but I thought I should bring it
to lists' attention.

> As you are writing a script, you can at least easily redirect it to
> /dev/null and output something else.

I like the "expected" output in that way, since:
```
'version.0-false' is not matching. I am asking git ...
80d790c17c9a3f10c156561efc323ac5d4684b16
'version.0' is not matching. I am asking git ... fatal: bad revision 'version.0'
```
it "complements" the previous output, and sounds "fluent enough".
And also that I don't have to patchwork it (I can, obviously).

The reason I mentioned:

> $ git rev-parse --verify version.3
> fatal: Needed a single revision

is that the message sounds counter-intuitive. I already gave (what I
thought was) a revision, and it is "already" one.
I "could" claim that `git rev-parse` is reading 2 arguments
(`--verify` and `version.3`),
and somehow `git rev-parse --verify` checks that `argc == 1`, and
failing due to a bug in the code.

I would understand that message in this context:
> $ git rev-parse --verify version.3 version.4
> fatal: Needed a single revision
since I gave 2 arguments instead of 1.

With regards,
Ντέντος Σταύρος

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-29 12:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-29  9:25 No clear API/Error message to validate a "revision object" using git rev-parse Ντέντος Σταύρος
2019-01-29 10:51 ` Christian Couder
2019-01-29 12:01   ` Ντέντος Σταύρος

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.