diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2019-04-25 12:45:52 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-05-07 07:04:47 +0300 |
commit | 3a733ce5237570460bbb63e20002b92e903ad65f (patch) | |
tree | 14e5cd0e77b763e3fd4187bd025fea66c23bcc74 /builtin/checkout.c | |
parent | e3ddd3b5e583e62d874f56f8c88603ad0ebafd5e (diff) |
restore: default to --source=HEAD when only --staged is specified
"git restore --staged" without --source does not make much sense since
by default we restore from the index. Instead of copying the index to
itself, set the default source to HEAD in this case, yielding behavior
that matches "git reset -- <paths>".
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 | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 71e25893408..09a03f1ff87 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1524,6 +1524,12 @@ static int checkout_main(int argc, const char **argv, const char *prefix, } if (opts->checkout_index < 0 || opts->checkout_worktree < 0) BUG("these flags should be non-negative by now"); + /* + * convenient shortcut: "git restore --staged" equals + * "git restore --staged --source HEAD" + */ + if (!opts->from_treeish && opts->checkout_index && !opts->checkout_worktree) + opts->from_treeish = "HEAD"; /* * From here on, new_branch will contain the branch to be checked out, |