Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-04-25 12:45:47 +0300
committerJunio C Hamano <gitster@pobox.com>2019-05-07 07:04:47 +0300
commitbe8ed5022b84fa75c24f24bbf64bb5ad6652c64f (patch)
treeb13462a0ee1248fa402388b378e164d2213ef773 /builtin/checkout.c
parentc9c935f6d4519c53f27f50113bea2c17deb8b71e (diff)
restore: make pathspec mandatory
"git restore" without arguments does not make much sense when it's about restoring files (what files now?). We could default to either git restore . or git restore :/ Neither is intuitive. Make the user always give pathspec, force the user to think the scope of restore they want because this is a destructive operation. "git restore -p" without pathspec is an exception to this because it really is a separate mode. It will be treated as running patch mode on the whole worktree. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 5aba345712d..77db5236f03 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -65,6 +65,7 @@ struct checkout_opts {
int only_merge_on_switching_branches;
int can_switch_when_in_progress;
int orphan_from_empty_tree;
+ int empty_pathspec_ok;
const char *new_branch;
const char *new_branch_force;
@@ -1515,6 +1516,10 @@ 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 &&
+ !opts->patch_mode) /* patch mode is special */
+ die(_("you must specify path(s) to restore"));
+
if (argc) {
parse_pathspec(&opts->pathspec, 0,
opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
@@ -1601,6 +1606,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.implicit_detach = 1;
opts.can_switch_when_in_progress = 1;
opts.orphan_from_empty_tree = 0;
+ opts.empty_pathspec_ok = 1;
options = parse_options_dup(checkout_options);
options = add_common_options(&opts, options);
@@ -1664,6 +1670,7 @@ int cmd_restore(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);