git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "David Burström" <davidburstrom@spotify.com>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: Bug or unexpected behaviour in git show <rev>:a\b
Date: Sat, 25 Jan 2020 14:21:25 +0100	[thread overview]
Message-ID: <CAA-mk2-X9kdS1h+6P0Y5wASHjFPJBKK-Dw9C1+OJL5U-nouVRg@mail.gmail.com> (raw)
In-Reply-To: <20200125000051.GA566074@coredump.intra.peff.net>

On Sat, 25 Jan 2020 at 01:00, Jeff King <peff@peff.net> wrote:
> > > 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.

  reply	other threads:[~2020-01-25 13:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 12:45 Bug or unexpected behaviour in git show <rev>:a\b David Burström
2020-01-24 19:01 ` Jeff King
2020-01-24 19:27   ` Junio C Hamano
2020-01-25  0:00     ` Jeff King
2020-01-25 13:21       ` David Burström [this message]
2020-01-27 18:47       ` Junio C Hamano
2020-01-25  0:05   ` Jeff King
2020-01-25  0:06     ` [PATCH 1/3] t1400: avoid "test" string comparisons Jeff King
2020-01-25  0:06     ` [PATCH 2/3] t1506: drop space after redirection operator Jeff King
2020-01-25  0:13     ` [PATCH 3/3] sha1-name: mark get_oid() error messages for translation Jeff King
2020-01-29 21:30       ` Junio C Hamano
2020-01-29 21:42         ` Junio C Hamano
2020-01-30  7:17           ` Jeff King
2020-01-30 19:16             ` Junio C Hamano
2020-01-31  0:15               ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAA-mk2-X9kdS1h+6P0Y5wASHjFPJBKK-Dw9C1+OJL5U-nouVRg@mail.gmail.com \
    --to=davidburstrom@spotify.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).