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

Re: [PATCH v2 1/2] checkout: allow dwim for branch creation for "git checkout $branch --"

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Sep 26, 2013, 09:03 UTC
Message-ID
<vpqa9j0kl9f.fsf@anie.imag.fr>
In-Reply-To
<20130925223334.GB9464@google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 10 quoted lines
> 	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).

Show 9 quoted lines
> 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/
Previous: Matthieu Moy
Message 7 of 7 in “checkout: allow dwim for branch creation for "git checkout $branch --"”
  1. 1/2 checkout: allow dwim for branch creation for "git checkout $branch --"Matthieu Moy, Sep 25, 2013
  2. 2/2 checkout: proper error message on 'git checkout foo bar --'Matthieu Moy, Sep 25, 2013
  3. Jonathan NiederSep 25, 2013
  4. Matthieu MoySep 26, 2013
  5. Jonathan NiederSep 25, 2013
  6. Matthieu MoySep 26, 2013
  7. Matthieu MoySep 26, 2013

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.