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

Re: [PATCH v2 2/2] checkout: tell "parse_remote_branch" which command is calling it

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 6, 2026, 16:05 UTC
Message-ID
<aYYRRBdCrbWmy1Gj@pks.im>
In-Reply-To
<20260129190616.645471-3-gitster@pobox.com>
On Thu, Jan 29, 2026 at 11:06:16AM -0800, Junio C Hamano wrote:
Show 22 quoted lines
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 4f189fde48..17f31c30b2 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1299,14 +1300,30 @@ static char *parse_remote_branch(const char *arg,
>  
>  	if (!remote && num_matches > 1) {
>  	    if (advice_enabled(ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME)) {
> +		    const char *cmdname;
> +
> +		    switch (which_command) {
> +		    case CHECKOUT_CHECKOUT:
> +			    cmdname = "checkout";
> +			    break;
> +		    case CHECKOUT_SWITCH:
> +			    cmdname = "switch";
> +			    break;
> +		    default:
> +			    BUG("command <%d> should not reach parse_remote_branch",
> +				which_command);
> +			    break;
> +		    }

`parse_remote_branch()` is only called by `parse_branchname_arg()`, which in turn is only called if `opts->accept_ref` is truish. And as that value only gets set to 1 in git-checkout(1) and git-switch(1) we know that we indeed don't have to care about git-restore(1).

Show 14 quoted lines
>  		    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"
>  			     "\n"
> -			     "    git checkout --track origin/<name>\n"
> +			     "    git %s --track origin/<name>\n"
>  			     "\n"
>  			     "If you'd like to always have checkouts of an ambiguous <name> prefer\n"
>  			     "one remote, e.g. the 'origin' remote, consider setting\n"
> -			     "checkout.defaultRemote=origin in your config."));
> +			     "checkout.defaultRemote=origin in your config."),
> +			   cmdname);
>  	    }
>  
>  	    die(_("'%s' matched multiple (%d) remote tracking branches"),
Yup, makes sense.

Overall this patch series looks good to me. There's been the one micronit in the preceding commit, but I really don't think it warrants a new version.

Thanks!
Patrick
Previous: Junio C Hamano
Message 11 of 11 in “Improving advise messages from "switch"”
  1. 0/2 Improving advise messages from "switch"Junio C Hamano, Jan 27, 2026
  2. 1/2 checkout: pass program-readable token to unified "main"Junio C Hamano, Jan 27, 2026
  3. 2/2 checkout: tell "parse_remote_branch" which command is calling itJunio C Hamano, Jan 27, 2026
  4. Kristoffer HaugsbakkJan 27, 2026
  5. Junio C HamanoJan 27, 2026
  6. 0/2 Improving advise messages from "switch"Junio C Hamano, Jan 29, 2026
  7. 1/2 checkout: pass program-readable token to unified "main"Junio C Hamano, Jan 29, 2026
  8. Patrick SteinhardtFeb 6, 2026
  9. Junio C HamanoFeb 19, 2026
  10. 2/2 checkout: tell "parse_remote_branch" which command is calling itJunio C Hamano, Jan 29, 2026
  11. Patrick SteinhardtFeb 6, 2026

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.