git checkout --no-guess
authorJunio C Hamano <gitster@pobox.com>
Sun, 18 Oct 2009 07:49:23 +0000 (00:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Oct 2009 22:17:24 +0000 (15:17 -0700)
Porcelains may want to make sure their calls to "git checkout" will
reliably fail regardless of the presense of random remote tracking
branches by the new DWIMmery introduced.

Luckily all existing in-tree callers have extra checks to make sure they
feed local branch name when they want to switch, or they explicitly ask to
detach HEAD at the given commit, so there is no need to add this option
for them.

As this is strictly script-only option, do not even bother to document it,
and do bother to hide it from "git checkout -h".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-checkout.c
index fb7e68ac5f2f0f7d224da93ae57867b24247c7ca..da04eed39104446c7c82dd846f8ddfd785d761e2 100644 (file)
@@ -616,6 +616,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        struct tree *source_tree = NULL;
        char *conflict_style = NULL;
        int patch_mode = 0;
+       int dwim_new_local_branch = 1;
        struct option options[] = {
                OPT__QUIET(&opts.quiet),
                OPT_STRING('b', NULL, &opts.new_branch, "new branch", "branch"),
@@ -631,6 +632,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                OPT_STRING(0, "conflict", &conflict_style, "style",
                           "conflict style (merge or diff3)"),
                OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
+               { OPTION_BOOLEAN, 0, "guess", &dwim_new_local_branch, NULL,
+                 "second guess 'git checkout no-such-branch'",
+                 PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
                OPT_END(),
        };
        int has_dash_dash;
@@ -715,6 +719,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                        if (has_dash_dash)          /* case (1) */
                                die("invalid reference: %s", arg);
                        if (!patch_mode &&
+                           dwim_new_local_branch &&
                            opts.track == BRANCH_TRACK_UNSPECIFIED &&
                            !opts.new_branch &&
                            !check_filename(NULL, arg) &&