git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] checkout: disambiguate dwim tracking branches and local files
Date: Mon, 12 Nov 2018 15:44:14 +0900	[thread overview]
Message-ID: <xmqq36s63idd.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20181110120707.25846-1-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Sat, 10 Nov 2018 13:07:07 +0100")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> @@ -1079,9 +1079,15 @@ static int parse_branchname_arg(int argc, const char **argv,
>  		 */
>  		int recover_with_dwim = dwim_new_local_branch_ok;
>  
> -		if (!has_dash_dash &&
> -		    (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
> -			recover_with_dwim = 0;
> +		/*
> +		 * If both refs/remotes/origin/master and the file
> +		 * 'master'. Don't blindly go for 'master' file
> +		 * because it's ambiguous. Leave it for the user to
> +		 * decide.
> +		 */
> +		int disambi_local_file = !has_dash_dash &&
> +			(check_filename(opts->prefix, arg) || !no_wildcard(arg));

What you are computing on the right hand side is if the arg is
ambiguous.  And the code that looks at this variable does not
disambiguate, but it just punts and makes it responsibility to the
user (which is by the way the correct thing to do).

When a file with exact name is in the working tree, we do not
declare it is a pathspec and not a rev, as we may be allowed to dwim
and create a rev with that name and at that point we'd be in an
ambigous situation.  If the arg _has_ wildcard, however, it is a
strong sign that it *is* a pathspec, isn't it?  It is iffy that a
single variable that cannot be used to distinguish these two cases
is introduced---one of these cases will be mishandled.

Also how does the patch ensures that this new logic does not kick in
for those who refuse to let the command dwim to create a new branch?

>  		/*
>  		 * Accept "git checkout foo" and "git checkout foo --"
>  		 * as candidates for dwim.
> @@ -1094,6 +1100,9 @@ static int parse_branchname_arg(int argc, const char **argv,
>  			const char *remote = unique_tracking_name(arg, rev,
>  								  dwim_remotes_matched);
>  			if (remote) {
> +				if (disambi_local_file)
> +					die(_("'%s' could be both a local file and a tracking branch.\n"
> +					      "Please use -- to disambiguate"), arg);

Ah, the only user of this variable triggers when recover_with_dwim
is true, so that is how dwim-less case is handled, OK.

That still leaves the question if it is OK to handle these two cases
the same way in a repository without 'next' branch whose origin has
one:

    $ >next; git checkout --guess next
    $ >next; git checkout --guess 'n??t'

Perhaps the variable should be named "local_file_crashes_with_rev"
and its the scope narrowed to the same block as "remote" is
computed.  Or just remove the variable and check the condition right
there where you need to.  I.e.

	if (remote) {
		if (!has_dash_dash &&
		    check_filename(opts->prefix, arg))
			die("did you mean a branch or path?: '%s'", arg);
		...


  reply	other threads:[~2018-11-12  6:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-10 12:07 [PATCH] checkout: disambiguate dwim tracking branches and local files Nguyễn Thái Ngọc Duy
2018-11-12  6:44 ` Junio C Hamano [this message]
2018-11-12 17:26   ` Duy Nguyen
2018-11-12 19:44     ` Junio C Hamano
2018-11-13 17:52 ` [PATCH v2 0/1] " Nguyễn Thái Ngọc Duy
2018-11-13 17:52   ` [PATCH v2 1/1] checkout: " Nguyễn Thái Ngọc Duy

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=xmqq36s63idd.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --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).