summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-10-04 12:30:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-06 00:04:56 (GMT)
commitdfd557c9783433bd6273987982f0665d99e52df2 (patch)
tree3f667e1537920860737c4480be9282c10d7327d2 /builtin
parent5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff)
downloadgit-dfd557c9783433bd6273987982f0665d99e52df2.zip
git-dfd557c9783433bd6273987982f0665d99e52df2.tar.gz
git-dfd557c9783433bd6273987982f0665d99e52df2.tar.bz2
stash apply: report status correctly even in a worktree's subdirectory
When Git wants to spawn a child Git process inside a worktree's subdirectory while `GIT_DIR` is set, we need to take care of specifying the work tree's top-level directory explicitly because it cannot be discovered: the current directory is _not_ the top-level directory of the work tree, and neither is it inside the parent directory of `GIT_DIR`. This fixes the problem where `git stash apply` would report pretty much everything deleted or untracked when run inside a worktree's subdirectory. To make sure that we do not introduce the "reverse problem", i.e. when `GIT_WORK_TREE` is defined but `GIT_DIR` is not, we simply make sure that both are set. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/stash.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/builtin/stash.c b/builtin/stash.c
index b5a301f..b108f09 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -497,6 +497,10 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
*/
cp.git_cmd = 1;
cp.dir = prefix;
+ argv_array_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
+ absolute_path(get_git_work_tree()));
+ argv_array_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s",
+ absolute_path(get_git_dir()));
argv_array_push(&cp.args, "status");
run_command(&cp);
}