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