diff options
author | Elijah Newren <newren@gmail.com> | 2022-01-26 01:43:45 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-01-26 12:01:54 -0800 |
commit | ff5b7913f0af62c26682b0376d0aa2d7f5d74b2e (patch) | |
tree | aad74a2cbc13e6a73598b131a115977a56b08689 /builtin/stash.c | |
parent | t2501: simplify the tests since we can now assume desired behavior (diff) | |
download | tgif-ff5b7913f0af62c26682b0376d0aa2d7f5d74b2e.tar.xz |
sequencer, stash: fix running from worktree subdir
In commits bc3ae46b42 ("rebase: do not attempt to remove
startup_info->original_cwd", 2021-12-09) and 0fce211ccc ("stash: do not
attempt to remove startup_info->original_cwd", 2021-12-09), we wanted to
allow the subprocess to know which directory the parent process was
running from, so that the subprocess could protect it. However...
When run from a non-main worktree, setup_git_directory() will note
that the discovered git directory
(/PATH/TO/.git/worktree/non-main-worktree) does not match
DEFAULT_GIT_DIR_ENVIRONMENT (see setup_discovered_git_dir()), and
decide to set GIT_DIR in the environment. This matters because...
Whenever git is run with the GIT_DIR environment variable set, and
GIT_WORK_TREE not set, it presumes that '.' is the working tree. So...
This combination results in the subcommand being very confused about
the working tree. Fix it by also setting the GIT_WORK_TREE environment
variable along with setting cmd.dir.
A possibly more involved fix we could consider for later would be to
make setup.c set GIT_WORK_TREE whenever (a) it discovers both the git
directory and the working tree and (b) it decides to set GIT_DIR in the
environment. I did not attempt that here as such would be too big of a
change for a 2.35.1 release.
Test-case-by: Glen Choo <chooglen@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/stash.c')
-rw-r--r-- | builtin/stash.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin/stash.c b/builtin/stash.c index de0e432a4f..a8a543855e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1485,8 +1485,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - if (startup_info->original_cwd) + if (startup_info->original_cwd) { cp.dir = startup_info->original_cwd; + strvec_pushf(&cp.env_array, "%s=%s", + GIT_WORK_TREE_ENVIRONMENT, + the_repository->worktree); + } strvec_pushl(&cp.args, "clean", "--force", "--quiet", "-d", ":/", NULL); if (include_untracked == INCLUDE_ALL_FILES) |