Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Steve Heyns <notzippy@gmail.com>
Subject: Re: "git checkout" resets modified files
Date: Sat, 29 Aug 2015 00:58:01 -0700	[thread overview]
Message-ID: <xmqqh9nizfue.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqlhcuzhsu.fsf@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Sat, 29 Aug 2015 00:15:45 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> I do not think this behaviour depends on the vintage of Git.  An
> empty string as pathspec has always matched "everything in here"
> AFAIR.

Having said all that, I think the DWIM used by "git checkout" has
some room for improvement, namely, its "we didn't see a double-dash;
is it a ref or is it a pathspec?" disambiguation should become
similar to the revision parser's.

Notice that

    $ git log ""

will error out, saying that an empty string does not name either a
revision or an existing path in the working tree.  I think the same
"refusal due to ambiguity" should be in "git checkout" when the user
says

    $ git checkout ""

Right now, when there is no double-dash, the code checks if the
first token X can be DWIMmed as a ref.  It may either name an
existing branch X, or it may be a non-existing branch name, but
there is a single remotes/Y/X and the user is too lazy to say 'git
checkout -t -b remotes/Y/X X' and instead said 'git checkout X'.

And if the first token X cannot be DWIMmed as a ref according to the
above logic, unlike the revision parser, we do not check it (and all
the subsequent tokens) name existing filesystem entity.

I think we really should.  With that, Steve's command line would
have correctly diagnosed as a liely error.

Of course, that still allows people to say

    $ git checkout -- ""

if they really mean it, but they can type

    $ git checkout -- :/

just as easily, so there is no big loss.

After following the existing code myself, I think this is a rather
easy low-hanging fruit for any aspiring Git hacker.  Hint, hint...


> [Footnote]
>
> *1* Checking out a branch whose name is an empty string can be asked
>     explicitly by disambiguating double-dash like this:
>
>     $ git checkout "" --
>
> And it will be answered (correctly) with:
>
>     fatal: invalid reference

      reply	other threads:[~2015-08-29  7:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-29  6:15 "git checkout" resets modified files Steve Heyns
2015-08-29  7:15 ` Junio C Hamano
2015-08-29  7:58   ` Junio C Hamano [this message]

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

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

  git send-email \
    --in-reply-to=xmqqh9nizfue.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=notzippy@gmail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox