@@ -45,6 +45,7 @@ struct checkout_opts {
int merge;
int force;
int force_detach;
+ int implicit_detach;
int writeout_stage;
int overwrite_ignore;
int ignore_skipworktree;
@@ -1341,6 +1342,14 @@ static int checkout_branch(struct checkout_opts *opts,
!opts->force_detach)
die(_("missing branch or commit argument"));
+ if (!opts->implicit_detach &&
+ !opts->force_detach &&
+ !opts->new_branch &&
+ !opts->new_branch_force &&
+ new_branch_info->name &&
+ !new_branch_info->path)
+ die(_("a branch is expected, got %s"), new_branch_info->name);
+
if (new_branch_info->path && !opts->force_detach && !opts->new_branch &&
!opts->ignore_other_worktrees) {
int flag;
@@ -1596,6 +1605,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.no_dwim_new_local_branch = 0;
opts.switch_branch_doing_nothing_is_ok = 1;
opts.accept_pathspec = 1;
+ opts.implicit_detach = 1;
options = parse_options_dup(checkout_options);
options = add_common_options(&opts, options);
@@ -1625,6 +1635,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
opts.no_dwim_new_local_branch = 0;
opts.accept_pathspec = 0;
opts.switch_branch_doing_nothing_is_ok = 0;
+ opts.implicit_detach = 0;
options = parse_options_dup(switch_options);
options = add_common_options(&opts, options);