int overlay_mode;
int no_dwim_new_local_branch;
int discard_changes;
+ int accept_pathspec;
/*
* If new checkout options are added, skip_merge_working_tree
if (!argc)
return 0;
+ if (!opts->accept_pathspec) {
+ if (argc > 1)
+ die(_("only one reference expected"));
+ has_dash_dash = 1; /* helps disambiguate */
+ }
+
arg = argv[0];
dash_dash_pos = -1;
for (i = 0; i < argc; i++) {
- if (!strcmp(argv[i], "--")) {
+ if (opts->accept_pathspec && !strcmp(argv[i], "--")) {
dash_dash_pos = i;
break;
}
recover_with_dwim = 0;
/*
- * Accept "git checkout foo" and "git checkout foo --"
- * as candidates for dwim.
+ * Accept "git checkout foo", "git checkout foo --"
+ * and "git switch foo" as candidates for dwim.
*/
if (!(argc == 1 && !has_dash_dash) &&
- !(argc == 2 && has_dash_dash))
+ !(argc == 2 && has_dash_dash) &&
+ opts->accept_pathspec)
recover_with_dwim = 0;
if (recover_with_dwim) {
*/
if (argc)
verify_non_filename(opts->prefix, arg);
- } else {
+ } else if (opts->accept_pathspec) {
argcount++;
argv++;
argc--;
memset(&opts, 0, sizeof(opts));
opts.no_dwim_new_local_branch = 0;
+ opts.accept_pathspec = 1;
options = parse_options_dup(checkout_options);
options = add_common_options(&opts, options);
memset(&opts, 0, sizeof(opts));
opts.no_dwim_new_local_branch = 0;
+ opts.accept_pathspec = 0;
options = parse_options_dup(switch_options);
options = add_common_options(&opts, options);