From 3a733ce5237570460bbb63e20002b92e903ad65f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 25 Apr 2019 16:45:52 +0700 Subject: restore: default to --source=HEAD when only --staged is specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "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 -- ". Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/builtin/checkout.c b/builtin/checkout.c index 71e2589..09a03f1 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, -- cgit v0.10.2-6-g49f6