Skip to content

Commit 0fce211

Browse files
newrengitster
authored andcommitted
stash: do not attempt to remove startup_info->original_cwd
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. Acked-by: Derrick Stolee <[email protected]> Acked-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc3ae46 commit 0fce211

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

builtin/stash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
14851485
struct child_process cp = CHILD_PROCESS_INIT;
14861486

14871487
cp.git_cmd = 1;
1488+
if (startup_info->original_cwd)
1489+
cp.dir = startup_info->original_cwd;
14881490
strvec_pushl(&cp.args, "clean", "--force",
1489-
"--quiet", "-d", NULL);
1491+
"--quiet", "-d", ":/", NULL);
14901492
if (include_untracked == INCLUDE_ALL_FILES)
14911493
strvec_push(&cp.args, "-x");
14921494
if (run_command(&cp)) {

t/t2501-cwd-empty.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ test_expect_success 'clean does not remove cwd incidentally' '
236236
'
237237

238238
test_expect_success 'stash does not remove cwd incidentally' '
239-
test_incidental_untracked_dir_removal failure \
239+
test_incidental_untracked_dir_removal success \
240240
git stash --include-untracked
241241
'
242242

0 commit comments

Comments
 (0)