git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Bug or unexpected behaviour in git show <rev>:a\b

From
DBDavid Burström <davidburstrom@spotify.com>
Date
Jan 25, 2020, 13:21 UTC
Message-ID
<CAA-mk2-X9kdS1h+6P0Y5wASHjFPJBKK-Dw9C1+OJL5U-nouVRg@mail.gmail.com>
In-Reply-To
<20200125000051.GA566074@coredump.intra.peff.net>
On Sat, 25 Jan 2020 at 01:00, Jeff King <peff@peff.net> wrote:
Show 22 quoted lines
> > > We _could_ also say "even though this could technically be a pathspec
> > > because of its metacharacter, it looks vaguely enough like a
> > > path-in-tree revision that we shouldn't guess". That I'm less
> > > comfortable with, just because it makes the heuristics even more
> > > magical.
> >
> > Not just it becomes more magical, I am afraid that the code to
> > implement such a heuristics would be fragile and become a source of
> > unnecessary bugs.  Let's not go there.
>
> OK. It does mean that:
>
>   git show HEAD:a*
>
> will still quietly produce no output instead of saying "hey, there is no
> a* in HEAD". But I think given the lack of bug reports over the years
> that this case (and the backslash one I'm fixing) are probably
> relatively rare.  The backslash one seems a lot more likely, just
> because Windows folks may treat it like a path separator (I'm not sure
> if that even works, considering its meaning in a glob, but certainly I
> can imagine somebody doing so as an experiment and getting confused by
> the result).

I'm normally in a Unix environment but needed to address a potential issue in Windows, which indeed got me confused about the results.

Upon experimenting in said Unix environment with what you outlined above on making revision and pathspec explicit, I figured that it becomes a little odd in the case where one would use a glob meta character in a filename (why anybody would want that except for academic reasons is beyond me), but it could still be a source of bugs in tooling interacting with git:

Given a repository initialized with

$ git init && echo a > a && echo '*' > '*' && git add a '*' && git commit -m "first" && git rm a '*' && git commit -m "second"

there's a bit of a discrepancy when using git show to dump the contents per revision. In the beginning, everything is normal for HEAD^ but for HEAD, it's a requirement to use disambiguation to avoid believing that '*' was an empty file. At the same time, the disambiguation causes the error message change its nature, for obvious reasons:

$ git show 'HEAD^:a' a $ git show 'HEAD^:a' -- a $ git show 'HEAD^:*' # presumably get_oid finds the object * $ git show 'HEAD^:*' -- * $ git show 'HEAD:a' fatal: Path 'a' does not exist in 'HEAD' $ git show 'HEAD:a' -- fatal: bad revision 'HEAD:a' $ git show 'HEAD:*' $ git show 'HEAD:*' -- fatal: bad revision 'HEAD:*'

Indeed, it seems to be working as designed or at least explainably. I'll make sure to add '--' in my tool integration to deal with this corner case.

Previous: Jeff KingNext: Junio C Hamano
Message 5 of 15 in “Bug or unexpected behaviour in git show <rev>:a\b”
  1. David BurströmJan 24, 2020
  2. Jeff KingJan 24, 2020
  3. Junio C HamanoJan 24, 2020
  4. Jeff KingJan 25, 2020
  5. David BurströmJan 25, 2020
  6. Junio C HamanoJan 27, 2020
  7. Jeff KingJan 25, 2020
  8. 1/3 t1400: avoid "test" string comparisonsJeff King, Jan 25, 2020
  9. 2/3 t1506: drop space after redirection operatorJeff King, Jan 25, 2020
  10. 3/3 sha1-name: mark get_oid() error messages for translationJeff King, Jan 25, 2020
  11. Junio C HamanoJan 29, 2020
  12. Junio C HamanoJan 29, 2020
  13. Jeff KingJan 30, 2020
  14. Junio C HamanoJan 30, 2020
  15. Jeff KingJan 31, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.