Skip to content

Commit 46148dd

Browse files
committed
git checkout --no-guess
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 <[email protected]>
1 parent 70c9ac2 commit 46148dd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin-checkout.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
616616
struct tree *source_tree = NULL;
617617
char *conflict_style = NULL;
618618
int patch_mode = 0;
619+
int dwim_new_local_branch = 1;
619620
struct option options[] = {
620621
OPT__QUIET(&opts.quiet),
621622
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)
631632
OPT_STRING(0, "conflict", &conflict_style, "style",
632633
"conflict style (merge or diff3)"),
633634
OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
635+
{ OPTION_BOOLEAN, 0, "guess", &dwim_new_local_branch, NULL,
636+
"second guess 'git checkout no-such-branch'",
637+
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
634638
OPT_END(),
635639
};
636640
int has_dash_dash;
@@ -715,6 +719,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
715719
if (has_dash_dash) /* case (1) */
716720
die("invalid reference: %s", arg);
717721
if (!patch_mode &&
722+
dwim_new_local_branch &&
718723
opts.track == BRANCH_TRACK_UNSPECIFIED &&
719724
!opts.new_branch &&
720725
!check_filename(NULL, arg) &&

0 commit comments

Comments
 (0)