@@ -59,6 +59,7 @@ struct checkout_opts {
int accept_ref;
int accept_pathspec;
int switch_branch_doing_nothing_not_ok;
+ int empty_pathspec_ok;
/*
* If new checkout options are added, skip_merge_working_tree
@@ -1436,6 +1437,9 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
die(_("reference is not a tree: %s"), opts->from_treeish);
}
+ if (opts->accept_pathspec && !opts->empty_pathspec_ok && !argc)
+ die(_("pathspec is required"));
+
if (argc) {
parse_pathspec(&opts->pathspec, 0,
opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
@@ -1515,6 +1519,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.accept_ref = 1;
opts.accept_pathspec = 1;
opts.implicit_detach = 1;
+ opts.empty_pathspec_ok = 1;
options = parse_options_dup(checkout_options);
options = add_common_options(&opts, options);
@@ -1570,6 +1575,7 @@ int cmd_restore_files(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
opts.accept_ref = 0;
opts.accept_pathspec = 1;
+ opts.empty_pathspec_ok = 0;
options = parse_options_dup(restore_options);
options = add_common_options(&opts, options);
"git restore-files" without arguments does not make much sense when it's about restoring files (what files now?). We could default to either git restore-files . or git restore-files :/ Neither is intuitive. Make the user always give pathspec, force the user to think the scope of restore they want. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- builtin/checkout.c | 6 ++++++ 1 file changed, 6 insertions(+)