diff mbox series

[v1,07/11] restore: default to --source=HEAD when only --index is specified

Message ID 20190308101655.9767-8-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series And new command "restore" | expand

Commit Message

Duy Nguyen March 8, 2019, 10:16 a.m. UTC
"git restore --index" does not make much sense since we're told to
restore the index from the (by default) index. Set default source to
HEAD in this case. This is basically the same as "git reset -- <paths>".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/checkout.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Elijah Newren March 9, 2019, 6:58 p.m. UTC | #1
On Fri, Mar 8, 2019 at 2:17 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>
> "git restore --index" does not make much sense since we're told to
> restore the index from the (by default) index. Set default source to
> HEAD in this case. This is basically the same as "git reset -- <paths>".

Can I suggest a slight rewording to the commit message?

"git restore --index" 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>".


The rest looks good to me.
diff mbox series

Patch

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 07b431be51..f06439dbeb 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1426,6 +1426,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 --index" equals
+	 * "git restore --index --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,