Skip to content

Commit be8ed50

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9c935f commit be8ed50

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

builtin/checkout.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct checkout_opts {
6565
int only_merge_on_switching_branches;
6666
int can_switch_when_in_progress;
6767
int orphan_from_empty_tree;
68+
int empty_pathspec_ok;
6869

6970
const char *new_branch;
7071
const char *new_branch_force;
@@ -1515,6 +1516,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15151516
die(_("reference is not a tree: %s"), opts->from_treeish);
15161517
}
15171518

1519+
if (opts->accept_pathspec && !opts->empty_pathspec_ok && !argc &&
1520+
!opts->patch_mode) /* patch mode is special */
1521+
die(_("you must specify path(s) to restore"));
1522+
15181523
if (argc) {
15191524
parse_pathspec(&opts->pathspec, 0,
15201525
opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
@@ -1601,6 +1606,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
16011606
opts.implicit_detach = 1;
16021607
opts.can_switch_when_in_progress = 1;
16031608
opts.orphan_from_empty_tree = 0;
1609+
opts.empty_pathspec_ok = 1;
16041610

16051611
options = parse_options_dup(checkout_options);
16061612
options = add_common_options(&opts, options);
@@ -1664,6 +1670,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
16641670
memset(&opts, 0, sizeof(opts));
16651671
opts.accept_ref = 0;
16661672
opts.accept_pathspec = 1;
1673+
opts.empty_pathspec_ok = 0;
16671674

16681675
options = parse_options_dup(restore_options);
16691676
options = add_common_options(&opts, options);

0 commit comments

Comments
 (0)