git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/3] checkout: fix ambiguity check in subdir
Date: Wed,  7 Sep 2016 18:19:41 +0700	[thread overview]
Message-ID: <20160907111941.2342-4-pclouds@gmail.com> (raw)
In-Reply-To: <20160907111941.2342-1-pclouds@gmail.com>

The two functions in parse_branchname_arg(), verify_non_filename and
check_filename, need correct prefix in order to reconstruct the paths
and check for their existence. With NULL prefix, they just check paths
at top dir instead.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/checkout.c            |  4 ++--
 t/t2010-checkout-ambiguous.sh |  9 +++++++++
 t/t2024-checkout-dwim.sh      | 12 ++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1f71d06..53c7284 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -985,7 +985,7 @@ 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(NULL, arg) || !no_wildcard(arg)))
+		    (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
 			recover_with_dwim = 0;
 		/*
 		 * Accept "git checkout foo" and "git checkout foo --"
@@ -1046,7 +1046,7 @@ static int parse_branchname_arg(int argc, const char **argv,
 		 * it would be extremely annoying.
 		 */
 		if (argc)
-			verify_non_filename(NULL, arg);
+			verify_non_filename(opts->prefix, arg);
 	} else {
 		argcount++;
 		argv++;
diff --git a/t/t2010-checkout-ambiguous.sh b/t/t2010-checkout-ambiguous.sh
index e76e84a..2e47fe0 100755
--- a/t/t2010-checkout-ambiguous.sh
+++ b/t/t2010-checkout-ambiguous.sh
@@ -41,6 +41,15 @@ test_expect_success 'check ambiguity' '
 	test_must_fail git checkout world all
 '
 
+test_expect_success 'check ambiguity in subdir' '
+	mkdir sub &&
+	# not ambiguous because sub/world does not exist
+	git -C sub checkout world ../all &&
+	echo hello >sub/world &&
+	# ambiguous because sub/world does exist
+	test_must_fail git -C sub checkout world ../all
+'
+
 test_expect_success 'disambiguate checking out from a tree-ish' '
 	echo bye > world &&
 	git checkout world -- world &&
diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh
index 468a000..3e5ac81 100755
--- a/t/t2024-checkout-dwim.sh
+++ b/t/t2024-checkout-dwim.sh
@@ -174,6 +174,18 @@ test_expect_success 'checkout of branch with a file having the same name fails'
 	test_branch master
 '
 
+test_expect_success 'checkout of branch with a file in subdir having the same name fails' '
+	git checkout -B master &&
+	test_might_fail git branch -D spam &&
+
+	>spam &&
+	mkdir sub &&
+	mv spam sub/spam &&
+	test_must_fail git -C sub checkout spam &&
+	test_must_fail git rev-parse --verify refs/heads/spam &&
+	test_branch master
+'
+
 test_expect_success 'checkout <branch> -- succeeds, even if a file with the same name exists' '
 	git checkout -B master &&
 	test_might_fail git branch -D spam &&
-- 
2.8.2.524.g6ff3d78


  parent reply	other threads:[~2016-09-07 11:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-22 12:35 [PATCH] checkout: swap the order of ambiguity check for :/ syntax Nguyễn Thái Ngọc Duy
2016-08-24 16:35 ` Junio C Hamano
2016-08-25  9:21   ` Duy Nguyen
2016-08-25 17:19     ` Junio C Hamano
2016-08-26 13:34       ` Duy Nguyen
2016-09-07 11:19 ` [PATCH 0/3] fix checkout ambiguation in subdir Nguyễn Thái Ngọc Duy
2016-09-07 11:19   ` [PATCH 1/3] checkout: add some spaces between code and comment Nguyễn Thái Ngọc Duy
2016-09-07 11:19   ` [PATCH 2/3] checkout.txt: document a common case that ignores ambiguation rules Nguyễn Thái Ngọc Duy
2016-09-08 20:03     ` Junio C Hamano
2016-09-09 19:21       ` Junio C Hamano
2016-09-07 11:19   ` Nguyễn Thái Ngọc Duy [this message]
2016-09-08 20:04     ` [PATCH 3/3] checkout: fix ambiguity check in subdir Junio C Hamano

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=20160907111941.2342-4-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).