git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, pclouds@gmail.com,
	jc@sahnwaldt.de
Subject: Re: [PATCH v2 1/2] checkout: allow dwim for branch creation for "git checkout $branch --"
Date: Thu, 26 Sep 2013 11:03:24 +0200	[thread overview]
Message-ID: <vpqa9j0kl9f.fsf@anie.imag.fr> (raw)
In-Reply-To: <20130925223334.GB9464@google.com> (Jonathan Nieder's message of "Wed, 25 Sep 2013 15:33:34 -0700")

Jonathan Nieder <jrnieder@gmail.com> writes:

> 	case 3: git checkout <something> [--]
>
> 	  If <something> is a commit, [...]
>
> 	  If <something> is _not_ a commit, either "--" is present or
> 	  <something> is not a path, no -t nor -b was given, and [...]
>
> 	  Otherwise, if "--" is present, treat it like case (1).
>
> 	  Otherwise behave like case (4).

Actually, no. Below, we have

		/*
		 * Do not complain the most common case
		 *	git checkout branch
		 * even if there happen to be a file called 'branch';
		 * it would be extremely annoying.
		 */

Which is a subcase of (3). The guess done in (3) is permissive, and the
one done with more arguments (4) is strict.

> 	case 4: git checkout <something> <paths>
>
> 	  The first argument must not be ambiguous.

I wasn't very convinced by your version at first, but I gave it a try.
I'm not sure the comment is actually better now, but I think it exposes
the complexity of the guess, and the difficulty to map the code and the
comment more. Other people should take this as an incentive to improve
the situation (but I'm really getting short of Git time budget, sorry).

> Then can come the "invalid reference" check for case (1):
>
> 		} else if (has_dash_dash)	/* case (1) */
> 			die(...);
>
> Then case (4).
>
> 		else	/* case (4) */
> 			return argcount;

Actually, the comments are wrong here. The comment <-> code mapping is
more complex than this. At this point of the code, you know that the
first argument is not a commit, and that dwim has been ruled-out. But
that may be case 3 also:

git checkout --no-guess <non-branch> [--]

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

      parent reply	other threads:[~2013-09-26  9:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-25 19:31 [PATCH v2 1/2] checkout: allow dwim for branch creation for "git checkout $branch --" Matthieu Moy
2013-09-25 19:31 ` [PATCH v2 2/2] checkout: proper error message on 'git checkout foo bar --' Matthieu Moy
2013-09-25 22:43   ` Jonathan Nieder
2013-09-26  8:59     ` Matthieu Moy
2013-09-25 22:33 ` [PATCH v2 1/2] checkout: allow dwim for branch creation for "git checkout $branch --" Jonathan Nieder
2013-09-26  8:03   ` Matthieu Moy
2013-09-26  9:03   ` Matthieu Moy [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=vpqa9j0kl9f.fsf@anie.imag.fr \
    --to=matthieu.moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jc@sahnwaldt.de \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@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;
as well as URLs for NNTP newsgroup(s).