switch: stop accepting pathspec
This command is about switching branch (or creating a new one) and should not accept pathspec. This helps simplify ambiguation handling. The other two ("git checkout" and "git restore") of course do accept pathspec as before. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
492ededc26
commit
5c06e26903
@ -54,6 +54,7 @@ struct checkout_opts {
|
|||||||
int overlay_mode;
|
int overlay_mode;
|
||||||
int no_dwim_new_local_branch;
|
int no_dwim_new_local_branch;
|
||||||
int discard_changes;
|
int discard_changes;
|
||||||
|
int accept_pathspec;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If new checkout options are added, skip_merge_working_tree
|
* If new checkout options are added, skip_merge_working_tree
|
||||||
@ -1176,10 +1177,16 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
if (!argc)
|
if (!argc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!opts->accept_pathspec) {
|
||||||
|
if (argc > 1)
|
||||||
|
die(_("only one reference expected"));
|
||||||
|
has_dash_dash = 1; /* helps disambiguate */
|
||||||
|
}
|
||||||
|
|
||||||
arg = argv[0];
|
arg = argv[0];
|
||||||
dash_dash_pos = -1;
|
dash_dash_pos = -1;
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "--")) {
|
if (opts->accept_pathspec && !strcmp(argv[i], "--")) {
|
||||||
dash_dash_pos = i;
|
dash_dash_pos = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1213,11 +1220,12 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
recover_with_dwim = 0;
|
recover_with_dwim = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Accept "git checkout foo" and "git checkout foo --"
|
* Accept "git checkout foo", "git checkout foo --"
|
||||||
* as candidates for dwim.
|
* and "git switch foo" as candidates for dwim.
|
||||||
*/
|
*/
|
||||||
if (!(argc == 1 && !has_dash_dash) &&
|
if (!(argc == 1 && !has_dash_dash) &&
|
||||||
!(argc == 2 && has_dash_dash))
|
!(argc == 2 && has_dash_dash) &&
|
||||||
|
opts->accept_pathspec)
|
||||||
recover_with_dwim = 0;
|
recover_with_dwim = 0;
|
||||||
|
|
||||||
if (recover_with_dwim) {
|
if (recover_with_dwim) {
|
||||||
@ -1262,7 +1270,7 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
*/
|
*/
|
||||||
if (argc)
|
if (argc)
|
||||||
verify_non_filename(opts->prefix, arg);
|
verify_non_filename(opts->prefix, arg);
|
||||||
} else {
|
} else if (opts->accept_pathspec) {
|
||||||
argcount++;
|
argcount++;
|
||||||
argv++;
|
argv++;
|
||||||
argc--;
|
argc--;
|
||||||
@ -1585,6 +1593,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
opts.no_dwim_new_local_branch = 0;
|
opts.no_dwim_new_local_branch = 0;
|
||||||
|
opts.accept_pathspec = 1;
|
||||||
|
|
||||||
options = parse_options_dup(checkout_options);
|
options = parse_options_dup(checkout_options);
|
||||||
options = add_common_options(&opts, options);
|
options = add_common_options(&opts, options);
|
||||||
@ -1614,6 +1623,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
opts.no_dwim_new_local_branch = 0;
|
opts.no_dwim_new_local_branch = 0;
|
||||||
|
opts.accept_pathspec = 0;
|
||||||
|
|
||||||
options = parse_options_dup(switch_options);
|
options = parse_options_dup(switch_options);
|
||||||
options = add_common_options(&opts, options);
|
options = add_common_options(&opts, options);
|
||||||
|
Loading…
Reference in New Issue
Block a user