diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2019-04-25 16:45:45 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-05-07 13:04:47 +0900 |
commit | 46e91b663badd99b3807ab34decfd32f3cbf15e7 (patch) | |
tree | d01c087e69f6abe1fde5b3c9e220151b18c802cf /builtin/checkout.c | |
parent | doc: promote "git switch" (diff) | |
download | tgif-46e91b663badd99b3807ab34decfd32f3cbf15e7.tar.xz |
checkout: split part of it to new command 'restore'
Previously the switching branch business of 'git checkout' becomes a
new command 'switch'. This adds the restore command for the checking
out paths path.
Similar to git-switch, a new man page is added to describe what the
command will become. The implementation will be updated shortly to
match the man page.
A couple main differences from 'git checkout <paths>':
- 'restore' by default will only update worktree. This matters more
when --source is specified ('checkout <tree> <paths>' updates both
worktree and index).
- 'restore --staged' can be used to restore the index. This command
overlaps with 'git reset <paths>'.
- both worktree and index could also be restored at the same time
(from a tree) when both --staged and --worktree are specified. This
overlaps with 'git checkout <tree> <paths>'
- default source for restoring worktree and index is the index and
HEAD respectively. A different (tree) source could be specified as
with --source (*).
- when both index and worktree are restored, --source must be
specified since the default source for these two individual targets
are different (**)
- --no-overlay is enabled by default, if an entry is missing in the
source, restoring means deleting the entry
(*) I originally went with --from instead of --source. I still think
--from is a better name. The short option -f however is already
taken by force. And I do think short option is good to have, e.g. to
write -s@ or -s@^ instead of --source=HEAD.
(**) If you sit down and think about it, moving worktree's source from
the index to HEAD makes sense, but nobody is really thinking it
through when they type the commands.
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.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 0351735c6e..98dc2ded38 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -38,6 +38,11 @@ static const char * const switch_branch_usage[] = { NULL, }; +static const char * const restore_usage[] = { + N_("git restore [<options>] [<branch>] -- <file>..."), + NULL, +}; + struct checkout_opts { int patch_mode; int quiet; @@ -1622,3 +1627,24 @@ int cmd_switch(int argc, const char **argv, const char *prefix) FREE_AND_NULL(options); return ret; } + +int cmd_restore(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts opts; + struct option *options = NULL; + int ret; + + memset(&opts, 0, sizeof(opts)); + opts.dwim_new_local_branch = 1; + opts.switch_branch_doing_nothing_is_ok = 0; + opts.accept_pathspec = 1; + + options = parse_options_dup(options); + options = add_common_options(&opts, options); + options = add_checkout_path_options(&opts, options); + + ret = checkout_main(argc, argv, prefix, &opts, + options, restore_usage); + FREE_AND_NULL(options); + return ret; +} |