checkout: add advice for ambiguous "checkout <branch>"
[gitweb.git] / builtin / checkout.c
index 8c93c55cbc2a2f09954f3574712a85749c3ec61b..baa027455ad74df72700b90893291ae4dc545254 100644 (file)
@@ -22,6 +22,7 @@
 #include "resolve-undo.h"
 #include "submodule-config.h"
 #include "submodule.h"
+#include "advice.h"
 
 static const char * const checkout_usage[] = {
        N_("git checkout [<options>] <branch>"),
@@ -1267,6 +1268,18 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        UNLEAK(opts);
        if (opts.patch_mode || opts.pathspec.nr) {
                int ret = checkout_paths(&opts, new_branch_info.name);
+               if (ret && dwim_remotes_matched > 1 &&
+                   advice_checkout_ambiguous_remote_branch_name)
+                       advise(_("'%s' matched more than one remote tracking branch.\n"
+                                "We found %d remotes with a reference that matched. So we fell back\n"
+                                "on trying to resolve the argument as a path, but failed there too!\n"
+                                "\n"
+                                "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>"),
+                              argv[0],
+                              dwim_remotes_matched);
                return ret;
        } else {
                return checkout_branch(&opts, &new_branch_info);