git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Ambiguous reference weirdness
@ 2012-02-22  1:46 Phil Hord
  2012-02-22  7:00 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Hord @ 2012-02-22  1:46 UTC (permalink / raw)
  To: git, Ramkumar Ramachandra, Junio C Hamano, Jonathan Nieder

I accidentally ran into this today:
    $ git cherry-pick 1147
    fatal: BUG: expected exactly one commit from walk

git log shows no output:
    $ git log 1147

Neither of these are very helpful or reassuring.  I tried a few things
but I haven't looked the code yet.  I found lots of inconsistencies
along the way.

$ git clone https://github.com/git/git
$ cd git

$git log 114
fatal: ambiguous argument '114': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions

$ git checkout 114
error: pathspec '114' did not match any file(s) known to git.
$ git merge 114
fatal: '114' does not point to a commit
$ git cherry-pick 114
fatal: ambiguous argument '114': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions

$ git checkout 1147
fatal: reference is not a tree: 1147
$ git merge 1147
error: 1147: expected commit type, but the object dereferences to blob type
fatal: '1147' does not point to a commit
$ git cherry-pick 1147
fatal: BUG: expected exactly one commit from walk
$ git log 1147

$ git checkout 1146
error: short SHA1 1146 is ambiguous.
error: pathspec '1146' did not match any file(s) known to git.
$ git merge 1146
error: short SHA1 1146 is ambiguous.
fatal: '1146' does not point to a commit
$ git cherry-pick 1146
error: short SHA1 1146 is ambiguous.
error: short SHA1 1146 is ambiguous.
fatal: ambiguous argument '1146': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions
$ git log 1146
error: short SHA1 1146 is ambiguous.
error: short SHA1 1146 is ambiguous.
fatal: ambiguous argument '1146': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions

I can understand some of the inconsistent error reporting (checkout
may expect filenames, but cherry-pick and merge do not).  But this
seems too varied to me.

And the first two look like bugs.

Any comments or suggestions?

Phil

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

* Re: Ambiguous reference weirdness
  2012-02-22  1:46 Ambiguous reference weirdness Phil Hord
@ 2012-02-22  7:00 ` Jeff King
  2012-02-22 14:48   ` Phil Hord
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2012-02-22  7:00 UTC (permalink / raw)
  To: Phil Hord; +Cc: git, Ramkumar Ramachandra, Junio C Hamano, Jonathan Nieder

On Tue, Feb 21, 2012 at 08:46:24PM -0500, Phil Hord wrote:

> I accidentally ran into this today:
>     $ git cherry-pick 1147
>     fatal: BUG: expected exactly one commit from walk
> 
> git log shows no output:
>     $ git log 1147

What is 1147? Is it supposed to be a partial sha1, or is it a ref you
have?

Have you looked at the object that it resolves to? I suspect it is the
partial sha1 of a non-commit object. E.g.:

  $ git cat-file -t HEAD^{tree}
  tree
  $ git cherry-pick HEAD^{tree}
  fatal: BUG: expected exactly one commit from walk
  $ git log HEAD^{tree} | wc -l
  0

Both cases have a similar source: they feed the arguments to the
revision walking machinery, which of course finds no actual revisions to
walk.

In the cherry-pick case, the code is checking the right thing, but the
message is horrible. It is not a bug, but merely unexpected input, and
it should provide a usage message.

In the log case, we totally ignore any pending non-revision arguments.
So it is correct to produce no output (there is nothing to show, which
is not unusual in itself; many queries end up producing empty output).
But we should probably notice that there are pending objects left over
and produce some kind of diagnostic.

I've reordered some of your example commands below to fit the flow of my
explanation better.

> $git log 114
> fatal: ambiguous argument '114': unknown revision or path not in the
> working tree.
> Use '--' to separate paths from revisions

Right. I think we require at least 4 characters in a partial sha1, so we
don't treat that as a possibility. So we are left guessing whether you
mean to do:

  git log 114 --

or

  git log HEAD -- 114

since it exists as neither a revision nor a path, and the error message
reflects that (the first one is an error, as there is no such revision.
The second is a correct query, though one that does not produce any
results).

> $ git checkout 114
> error: pathspec '114' did not match any file(s) known to git.

I think checkout has the same "is this a path or a revision" ambiguity
to resolve. But rather than be explicit that you might have meant "114"
as a tree, the error message assumes you meant a path. That might be
worth improving, similar to the above example.

Again, you can disambiguate with:

  $ git checkout -- 1147
  error: pathspec '1147' did not match any file(s) known to git.

  $ git checkout 1147 --
  fatal: reference is not a tree: 1147

> $ git checkout 1147
> fatal: reference is not a tree: 1147

In this case the name does resolve to an object, so we try to use it as
such (even though we later find that it is useless for the operation).
We _could_ realize that it is not a tree and disambiguate to:

  $ git checkout -- 1147

but the current rule is at least consistent and simple.

> $ git checkout 1146
> error: short SHA1 1146 is ambiguous.
> error: pathspec '1146' did not match any file(s) known to git.

The sha1 is ambiguous, and therefore it does not resolve to anything. So
you get the same case as "git checkout 1147", but with the extra
ambiguity warning.

> $ git merge 114
> fatal: '114' does not point to a commit

It might be nice for this error message to be split into two cases:

  1. the name does not resolve _at all_ (i.e., you made a typo)

  2. the name does resolve to something, but it is not a commit

In the latter case, we actually do get an extra error message from
elsewhere in the code:

> $ git merge 1147
> error: 1147: expected commit type, but the object dereferences to blob type
> fatal: '1147' does not point to a commit

But in case 1, it's not clear which is which (maybe even rewording it as
"114 cannot be resolved as a commit" would be less confusing).

> $ git cherry-pick 114
> fatal: ambiguous argument '114': unknown revision or path not in the
> working tree.
> Use '--' to separate paths from revisions
> [...]
> $ git cherry-pick 1147
> fatal: BUG: expected exactly one commit from walk

This is the "does not resolve" versus "is not actually a commit". In the
first case, though, I wonder if the error message is accurate. I'm not
sure if you can do "git cherry-pick <rev> -- <paths>", so the error
message is misleading (if anything, I would expect it to limit the
revision walk, but trying "git cherry-pick HEAD -- 114" seems to still
complain about the absence of 114).

> [more examples]

These are all variants that hopefully make sense in light of the
explanations above.

> I can understand some of the inconsistent error reporting (checkout
> may expect filenames, but cherry-pick and merge do not).  But this
> seems too varied to me.
> 
> And the first two look like bugs.
> 
> Any comments or suggestions?

I think the outcomes are all working as intended, but the error messages
could stand to be improved.

-Peff

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

* Re: Ambiguous reference weirdness
  2012-02-22  7:00 ` Jeff King
@ 2012-02-22 14:48   ` Phil Hord
  2012-02-22 20:38     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Hord @ 2012-02-22 14:48 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Ramkumar Ramachandra, Junio C Hamano, Jonathan Nieder

On Wed, Feb 22, 2012 at 2:00 AM, Jeff King <peff@peff.net> wrote:
> On Tue, Feb 21, 2012 at 08:46:24PM -0500, Phil Hord wrote:
>
>> I accidentally ran into this today:
>>     $ git cherry-pick 1147
>>     fatal: BUG: expected exactly one commit from walk
>>
>> git log shows no output:
>>     $ git log 1147
>
> What is 1147? Is it supposed to be a partial sha1, or is it a ref you
> have?

1147 was a typo.  It was a Gerritt changeset ID I forgot to expand.
When I type "git cherry-pick 1147<TAB>", autocompletion expands this
for me to "git cherry-pick origin/changes/47/1147/1".  Except in this
case I misfired the TAB and got the weird "BUG:" report.  But I didn't
see the same problem with other invalid refs, so I went searching for
the variants and to see what caused it.

> Have you looked at the object that it resolves to? I suspect it is the
> partial sha1 of a non-commit object. E.g.:

All of these examples were run in current git.git, so you can try them
yourself if needed.  But I did figure out that 1147 resolves to a
blob, and that's apparently the difference between these three:

$ git cherry-pick 1147
fatal: BUG: expected exactly one commit from walk

$ git cherry-pick 1146
error: short SHA1 1146 is ambiguous.
error: short SHA1 1146 is ambiguous.
fatal: ambiguous argument '1146': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions

$ git cherry-pick 114333
fatal: ambiguous argument '114333': unknown revision or path not in
the working tree.
Use '--' to separate paths from revisions

I consider the first two responses to be UI bugs.   The second one is
minor (the twice-reported error message), and the first one is pretty
rude.   I would expect all three to report the same conclusion,
"fatal: ambiguous argument 'XXXXX': unknown revision or path not in
the working tree."  But the first one doesn't.



>  $ git cat-file -t HEAD^{tree}
>  tree
>  $ git cherry-pick HEAD^{tree}
>  fatal: BUG: expected exactly one commit from walk
>  $ git log HEAD^{tree} | wc -l
>  0

Thanks.  I'm not familiar with the {tree} syntax -- in fact I'd like
to find a dictionary for all the reference spelling variants -- but
this is elucidating.

> In the cherry-pick case, the code is checking the right thing, but the
> message is horrible. It is not a bug, but merely unexpected input, and
> it should provide a usage message.

Bug is too strong a word in one sense, but from the user perspective I
consider this "horrible message" a bug.

> In the log case, we totally ignore any pending non-revision arguments.
> So it is correct to produce no output (there is nothing to show, which
> is not unusual in itself; many queries end up producing empty output).
> But we should probably notice that there are pending objects left over
> and produce some kind of diagnostic.

I think you're right about this.  I tried log as an afterthought and
was surprised by the varying results.

> I've reordered some of your example commands below to fit the flow of my
> explanation better.
>
>> $git log 114
>> fatal: ambiguous argument '114': unknown revision or path not in the
>> working tree.
>> Use '--' to separate paths from revisions
>
> Right. I think we require at least 4 characters in a partial sha1, so we
> don't treat that as a possibility. So we are left guessing whether you
> mean to do:
>
>  git log 114 --
>
> or
>
>  git log HEAD -- 114
>
> since it exists as neither a revision nor a path, and the error message
> reflects that (the first one is an error, as there is no such revision.
> The second is a correct query, though one that does not produce any
> results).
>
>> $ git checkout 114
>> error: pathspec '114' did not match any file(s) known to git.
>
> I think checkout has the same "is this a path or a revision" ambiguity
> to resolve. But rather than be explicit that you might have meant "114"
> as a tree, the error message assumes you meant a path. That might be
> worth improving, similar to the above example.
>
> Again, you can disambiguate with:
>
>  $ git checkout -- 1147
>  error: pathspec '1147' did not match any file(s) known to git.
>
>  $ git checkout 1147 --
>  fatal: reference is not a tree: 1147
>
>> $ git checkout 1147
>> fatal: reference is not a tree: 1147

Yes, I understand this.  This was a typo and it was ambiguous.  But
shouldn't we tell the user the same thing when encountering the same
failure?

> In this case the name does resolve to an object, so we try to use it as
> such (even though we later find that it is useless for the operation).
> We _could_ realize that it is not a tree and disambiguate to:
>
>  $ git checkout -- 1147
>
> but the current rule is at least consistent and simple.
>
>> $ git checkout 1146
>> error: short SHA1 1146 is ambiguous.
>> error: pathspec '1146' did not match any file(s) known to git.
>
> The sha1 is ambiguous, and therefore it does not resolve to anything. So
> you get the same case as "git checkout 1147", but with the extra
> ambiguity warning.

This one I like.  I only included it to demonstrate the different
error messages git produces.

>> $ git merge 114
>> fatal: '114' does not point to a commit
>
> It might be nice for this error message to be split into two cases:
>
>  1. the name does not resolve _at all_ (i.e., you made a typo)
>
>  2. the name does resolve to something, but it is not a commit
>
> In the latter case, we actually do get an extra error message from
> elsewhere in the code:
>
>> $ git merge 1147
>> error: 1147: expected commit type, but the object dereferences to blob type
>> fatal: '1147' does not point to a commit
>
> But in case 1, it's not clear which is which (maybe even rewording it as
> "114 cannot be resolved as a commit" would be less confusing).
>
>> $ git cherry-pick 114
>> fatal: ambiguous argument '114': unknown revision or path not in the
>> working tree.
>> Use '--' to separate paths from revisions
>> [...]
>> $ git cherry-pick 1147
>> fatal: BUG: expected exactly one commit from walk
>
> This is the "does not resolve" versus "is not actually a commit". In the
> first case, though, I wonder if the error message is accurate. I'm not
> sure if you can do "git cherry-pick <rev> -- <paths>", so the error
> message is misleading

Good point.  I missed that one completely.


> (if anything, I would expect it to limit the
> revision walk, but trying "git cherry-pick HEAD -- 114" seems to still
> complain about the absence of 114).
>
>> [more examples]
>
> These are all variants that hopefully make sense in light of the
> explanations above.
>
>> I can understand some of the inconsistent error reporting (checkout
>> may expect filenames, but cherry-pick and merge do not).  But this
>> seems too varied to me.
>>
>> And the first two look like bugs.
>>
>> Any comments or suggestions?
>
> I think the outcomes are all working as intended, but the error messages
> could stand to be improved.

Yes, I agree.  I only meant to complain about the error messages, not
the results.  Thanks for the discussion.  I'll try to look for where
these come from and see if they can be improved within reason.

Phil

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

* Re: Ambiguous reference weirdness
  2012-02-22 14:48   ` Phil Hord
@ 2012-02-22 20:38     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2012-02-22 20:38 UTC (permalink / raw)
  To: Phil Hord; +Cc: git, Ramkumar Ramachandra, Junio C Hamano, Jonathan Nieder

On Wed, Feb 22, 2012 at 09:48:23AM -0500, Phil Hord wrote:

> > What is 1147? Is it supposed to be a partial sha1, or is it a ref you
> > have?
> 
> 1147 was a typo.  It was a Gerritt changeset ID I forgot to expand.
> When I type "git cherry-pick 1147<TAB>", autocompletion expands this
> for me to "git cherry-pick origin/changes/47/1147/1".  Except in this
> case I misfired the TAB and got the weird "BUG:" report.  But I didn't
> see the same problem with other invalid refs, so I went searching for
> the variants and to see what caused it.

Ah. It's a little annoying that Gerrit names refs that look kind of
like partial sha1s. But I guess most of the time it's not that big a
deal (it is only because you were using the partial Gerrit ref with tab
completion). And I don't think we're about to change how Gerrit names
things. :)

> > Have you looked at the object that it resolves to? I suspect it is the
> > partial sha1 of a non-commit object. E.g.:
> 
> All of these examples were run in current git.git, so you can try them
> yourself if needed.  But I did figure out that 1147 resolves to a
> blob, and that's apparently the difference between these three:

Yeah. I figured that after reading more, but didn't go back and revise
the first part of my message. I was able to easily get the same results
as you (actually, in my git.git, 1147 is ambiguous because I happen to
have some extra refs, but it was easy to replicate with a fresh clone).

> $ git cherry-pick 1147
> fatal: BUG: expected exactly one commit from walk
> 
> $ git cherry-pick 1146
> error: short SHA1 1146 is ambiguous.
> error: short SHA1 1146 is ambiguous.
> fatal: ambiguous argument '1146': unknown revision or path not in the
> working tree.
> Use '--' to separate paths from revisions
> 
> $ git cherry-pick 114333
> fatal: ambiguous argument '114333': unknown revision or path not in
> the working tree.
> Use '--' to separate paths from revisions
> 
> I consider the first two responses to be UI bugs.   The second one is
> minor (the twice-reported error message), and the first one is pretty
> rude.   I would expect all three to report the same conclusion,
> "fatal: ambiguous argument 'XXXXX': unknown revision or path not in
> the working tree."  But the first one doesn't.

Right. Because cherry-pick's logic is:

  if the arguments do not resolve to any objects at all
      complain of unknown revision
  if the resolved object is not a single commit
      die of BUG

And I think you just want to collapse those two conditions into a single
conditional, which seems reasonable (the error message does say "unknown
revision", not "unknown object". It's a little more complicated than
that, because you are crossing a boundary between reusable library code
and cherry-pick specific code.

As for the doubled "ambiguous" warning, I'm not sure what the cause is
for that. I suspect it is because cherry-pick tries to parse one way (as
a revision walk specifier, like "a..b"), and then parses again (as a
single commit) when that fails, due to historical reasons. Obviously
it would be nice to see that improved, but I suspect it will be annoying
to do so; the error message is emitted by a low-level, and cherry-pick
has no idea that it has happened (it only sees "this didn't result in
parsing anything").

> Thanks.  I'm not familiar with the {tree} syntax -- in fact I'd like
> to find a dictionary for all the reference spelling variants -- but
> this is elucidating.

See "git help rev-parse", section "Specifying Revisions".

> > In the cherry-pick case, the code is checking the right thing, but the
> > message is horrible. It is not a bug, but merely unexpected input, and
> > it should provide a usage message.
> 
> Bug is too strong a word in one sense, but from the user perspective I
> consider this "horrible message" a bug.

Sorry, I meant git is wrong to use the word "BUG". For us, die("BUG:
...") is the equivalent of an assert. It means something totally
unexpected happened that should never happen, and therefore there is a
bug in git. But this is not a bug in git (well, it is, but not that
kind). It is a totally reasonable and expected malformed input that git
should diagnose and report correctly.

So it is a bug that git says "BUG". It should say "you gave me objects,
but they are not revisions" or something similar.

> > I think checkout has the same "is this a path or a revision" ambiguity
> > to resolve. But rather than be explicit that you might have meant "114"
> > as a tree, the error message assumes you meant a path. That might be
> > worth improving, similar to the above example.
> >
> > Again, you can disambiguate with:
> >
> >  $ git checkout -- 1147
> >  error: pathspec '1147' did not match any file(s) known to git.
> >
> >  $ git checkout 1147 --
> >  fatal: reference is not a tree: 1147
> >
> >> $ git checkout 1147
> >> fatal: reference is not a tree: 1147
> 
> Yes, I understand this.  This was a typo and it was ambiguous.  But
> shouldn't we tell the user the same thing when encountering the same
> failure?

No, because there are really three cases here:

  1. The user told us 1147 is a path.

  2. The user told us 1147 is a tree.

  3. The user did not tell us which, and we must guess.

We guess (1) if the name does not resolve at all, and (2) otherwise. And
the error message only indicates the particular guess we made.

So while I don't think they should all have the same error message,
there are two improvements I can see:

  a. If we are guessing, and 1147 resolves but is _not_ a tree, we
     could guess path instead.

  b. When our guess results in an error, it would be better to be
     explicit about the fact that we guessed (i.e., say "this is neither
     a tree nor a path that git knows about", similar to git-log).

> > I think the outcomes are all working as intended, but the error messages
> > could stand to be improved.
> 
> Yes, I agree.  I only meant to complain about the error messages, not
> the results.  Thanks for the discussion.  I'll try to look for where
> these come from and see if they can be improved within reason.

Great. I look forward to it.

-Peff

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

end of thread, other threads:[~2012-02-22 20:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-22  1:46 Ambiguous reference weirdness Phil Hord
2012-02-22  7:00 ` Jeff King
2012-02-22 14:48   ` Phil Hord
2012-02-22 20:38     ` Jeff King

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