aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/stash.c
diff options
context:
space:
mode:
authorD. Ben Knoble <ben.knoble+github@gmail.com>2025-09-21 21:39:06 -0400
committerJunio C Hamano <gitster@pobox.com>2025-09-21 20:23:23 -0700
commit9842c0c7492d2858d64ef81128f7b1f0b38e326b (patch)
treefee23eea8f05af177597ca9af2899faf3f3c6b20 /builtin/stash.c
parentstash: refactor private config globals (diff)
downloadgit-9842c0c7492d2858d64ef81128f7b1f0b38e326b.tar.gz
git-9842c0c7492d2858d64ef81128f7b1f0b38e326b.zip
stash: honor stash.index in apply, pop modes
With stash.index=true, git-stash(1) command now tries to reinstate the index by default in the "apply" and "pop" modes. Not doing so creates a common trap [1], [2]: "git stash apply" is not the reverse of "git stash push" because carefully staged indices are lost and have to be manually recreated. OTOH, this mode is not always desirable and may create more conflicts when applying stashes. As usual, "--no-index" will disable this behavior if you set "stash.index". [1]: https://lore.kernel.org/git/CAPx1GvcxyDDQmCssMjEnt6JoV6qPc5ZUpgPLX3mpUC_4PNYA1w@mail.gmail.com/ [2]: https://lore.kernel.org/git/c5a811ac-8cd3-c389-ac6d-29020a648c87@gmail.com/ Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/stash.c')
-rw-r--r--builtin/stash.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/builtin/stash.c b/builtin/stash.c
index d9b478d1d1..8a0eef3c70 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -130,6 +130,7 @@ static struct strbuf stash_index_path = STRBUF_INIT;
static int show_stat = 1;
static int show_patch;
static int show_include_untracked;
+static int use_index;
/*
* w_commit is set to the commit containing the working tree
@@ -662,7 +663,7 @@ static int apply_stash(int argc, const char **argv, const char *prefix,
{
int ret = -1;
int quiet = 0;
- int index = 0;
+ int index = use_index;
struct stash_info info = STASH_INFO_INIT;
struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
@@ -759,7 +760,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int ret = -1;
- int index = 0;
+ int index = use_index;
int quiet = 0;
struct stash_info info = STASH_INFO_INIT;
struct option options[] = {
@@ -864,6 +865,10 @@ static int git_stash_config(const char *var, const char *value,
show_include_untracked = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "stash.index")) {
+ use_index = git_config_bool(var, value);
+ return 0;
+ }
return git_diff_basic_config(var, value, ctx, cb);
}