Subject: [PATCH v2 0/2] checkout: die() on ambiguous tracking branches

From: "Alexandr Miloslavskiy via GitGitGadget" <[email-masked]>
Date: Wed, 27 Nov 2019 16:43:08 +0000

Please refer to commit messages for details.

Rationale: this issue was standing in my way while working on my 
--pathspec-from-file patches. Since this looks like an oversight, I decided
to fix it.

----------------------------------------------------------------------------

Changes from v1:

1) As suggested, removed parentheses in '&& (num_matches > 1)' 2) As
suggested, added additional checks in test. 3) Added some code comments in
test

Alexandr Miloslavskiy (2):
  parse_branchname_arg(): extract part as new function
  checkout: die() on ambiguous tracking branches

 builtin/checkout.c       | 71 ++++++++++++++++++++++------------------
 t/t2024-checkout-dwim.sh | 28 ++++++++++++++--
 2 files changed, 65 insertions(+), 34 deletions(-)

base-commit: d9f6f3b6195a0ca35642561e530798ad1469bd41
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-477%2FSyntevoAlex%2F%230224(git)_deny_ambiguous_checkout-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-477/SyntevoAlex/#0224(git)_deny_ambiguous_checkout-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/477

Range-diff vs v1:

 1:  c5b92ce3ed = 1:  1e40cc485b parse_branchname_arg(): extract part as new function
 2:  7dde1a3b4e ! 2:  575eeb97ba checkout: die() on ambiguous tracking branches
     @@ -54,7 +54,7 @@
       		    arg);
       	}
       
     -+	if (!remote && (num_matches > 1)) {
     ++	if (!remote && num_matches > 1) {
      +	    if (advice_checkout_ambiguous_remote_branch_name) {
      +		    advise(_("If you meant to check out a remote tracking branch on, e.g. 'origin',\n"
      +			     "you can do so by fully qualifying the name with the --track option:\n"
     @@ -174,17 +174,22 @@
       '
       
      +test_expect_success 'when arg matches multiple remotes, do not fallback to interpreting as pathspec' '
     ++	# create a file with name matching remote branch name
      +	git checkout -b t_ambiguous_branch_and_file &&
      +	>ambiguous_branch_and_file &&
      +	git add ambiguous_branch_and_file &&
      +	git commit -m "ambiguous_branch_and_file" &&
      +
     ++	# modify file to verify that it will not be touched by checkout
      +	test_when_finished "git checkout -- ambiguous_branch_and_file" &&
      +	echo "file contents" >ambiguous_branch_and_file &&
      +	cp ambiguous_branch_and_file expect &&
      +
     -+	test_must_fail git checkout ambiguous_branch_and_file &&
     ++	test_must_fail git checkout ambiguous_branch_and_file 2>err &&
      +
     ++	test_i18ngrep "matched multiple (2) remote tracking branches" err &&
     ++	
     ++	# file must not be altered
      +	test_cmp expect ambiguous_branch_and_file
      +'
      +

-- 
gitgitgadget