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

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

From
AGAlexandr Miloslavskiy via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 27, 2019, 16:43 UTC
Message-ID
<pull.477.v2.git.1574872991.gitgitgadget@gmail.com>
In-Reply-To
<pull.477.git.1574848137.gitgitgadget@gmail.com>
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
Previous: Alexandr MiloslavskiyNext: Alexandr Miloslavskiy via GitGitGadget
Message 9 of 13 in “checkout: die() on ambiguous tracking branches”
  1. 0/2 checkout: die() on ambiguous tracking branchesAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  2. 1/2 parse_branchname_arg(): extract part as new functionAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  3. 2/2 checkout: die() on ambiguous tracking branchesAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  4. Derrick StoleeNov 27, 2019
  5. Alexandr MiloslavskiyNov 27, 2019
  6. Ævar Arnfjörð BjarmasonNov 27, 2019
  7. Alexandr MiloslavskiyNov 27, 2019
  8. Alexandr MiloslavskiyDec 5, 2019
  9. 0/2 checkout: die() on ambiguous tracking branchesAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  10. 2/2 checkout: die() on ambiguous tracking branchesAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  11. 1/2 parse_branchname_arg(): extract part as new functionAlexandr Miloslavskiy via GitGitGadget, Nov 27, 2019
  12. Junio C HamanoDec 1, 2019
  13. Alexandr MiloslavskiyDec 1, 2019

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.