Web lists-archives.com

Re: [PATCH v1 03/11] restore: make pathspec mandatory




On Fri, Mar 8, 2019 at 2:17 AM Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
>
> "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.

This all sounds very good.

>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  builtin/checkout.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 838343d6aa..c52ce13d2a 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -61,6 +61,7 @@ struct checkout_opts {
>         int accept_pathspec;
>         int switch_branch_doing_nothing_is_ok;
>         int only_merge_on_switching_branches;
> +       int empty_pathspec_ok;
>
>         const char *new_branch;
>         const char *new_branch_force;
> @@ -1427,6 +1428,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(_("pathspec is required"));

Maybe
   die(_("you must specify path(s) to restore"));
?  While "pathspec" is something we use in a few places, I don't think
users intuitively know what it is.  Also, I just looked up the manpage
again, and it looks like you use "pathspec" in the restore manpage,
but don't define it.

> +
>         if (argc) {
>                 parse_pathspec(&opts->pathspec, 0,
>                                opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
> @@ -1511,6 +1516,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 +1576,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);
> --
> 2.21.0.rc1.337.gdf7f8d0522