[PATCH v3 08/11] stash: do not attempt to remove startup_info->original_cwd
- From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 26, 2021, 22:40 UTC
- Message-ID
- <0110462a19c0ad1f11bbb6449f2ec84fe14c1442.1637966463.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1140.v3.git.git.1637966463.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
Since stash spawns a `clean` subprocess, make sure we run that from the startup_info->original_cwd directory, so that the `clean` processs knows to protect that directory. Also, since the `clean` command might no longer run from the toplevel, pass the ':/' magic pathspec to ensure we still clean from the toplevel.
Signed-off-by: Elijah Newren <newren@gmail.com> --- builtin/stash.c | 5 ++++- t/t2501-cwd-empty.sh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c index a0ccc8654df..4d89cc7f969 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1485,8 +1485,11 @@ 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 && + !is_absolute_path(startup_info->original_cwd)) + cp.dir = startup_info->original_cwd; strvec_pushl(&cp.args, "clean", "--force", - "--quiet", "-d", NULL); + "--quiet", "-d", ":/", NULL); if (include_untracked == INCLUDE_ALL_FILES) strvec_push(&cp.args, "-x"); if (run_command(&cp)) { diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh index acf9646ec6e..6788a0d267f 100755 --- a/t/t2501-cwd-empty.sh +++ b/t/t2501-cwd-empty.sh @@ -227,7 +227,7 @@ test_expect_success 'clean does not remove cwd incidentally' ' ' test_expect_success 'stash does not remove cwd incidentally' ' - test_incidental_untracked_dir_removal failure \ + test_incidental_untracked_dir_removal success \ git stash --include-untracked '
-- gitgitgadget