]> git.ipfire.org Git - thirdparty/git.git/commitdiff
restore: default to --source=HEAD when only --staged is specified
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 25 Apr 2019 09:45:52 +0000 (16:45 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2019 04:04:47 +0000 (13:04 +0900)
"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>
builtin/checkout.c

index 71e25893408fce5d6992f8535ee7895cf3dfcaa0..09a03f1ff874683d02fc3deb1608a29e310149b1 100644 (file)
@@ -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,