From dfd557c9783433bd6273987982f0665d99e52df2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 4 Oct 2019 05:30:59 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/stash.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'builtin/stash.c') diff --git a/builtin/stash.c b/builtin/stash.c index b5a301f24d..b108f099fa 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); } -- cgit v1.2.3