[PATCH v10 1/4] checkout: extract function to display advice for ambiguous remotes
- From
Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Aug 27, 2026, 14:41 UTC
- Message-ID
- <7650c38d6bf4c68cae4894d1cad5d96dd55e4b92.1787841717.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2197.v10.git.1787841717.gitgitgadget@gmail.com>
From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Fix incorrect indentation and reduce nesting. We are going to extend this function in subsequent commits.
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com> --- builtin/checkout.c | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c index 55e3a89a85..3cd5fff709 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1343,6 +1343,34 @@ enum checkout_command { CHECKOUT_RESTORE = 3, }; +static void advise_disambiguating_remotes(enum checkout_command which_command) +{ + 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 advise_disambiguating_remotes", + which_command); + break; + } + + 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 %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."), + cmdname); +} + static char *parse_remote_branch(const char *arg, struct object_id *rev, int could_be_checkout_paths, @@ -1358,35 +1386,11 @@ 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; - } - - 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 %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."), - cmdname); - } - - die(_("'%s' matched multiple (%d) remote tracking branches"), - arg, num_matches); + if (advice_enabled(ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME)) + advise_disambiguating_remotes(which_command); + + die(_("'%s' matched multiple (%d) remote tracking branches"), + arg, num_matches); } return remote;
-- gitgitgadget