[PATCH 7/8] stash: do not attempt to remove current working directory
From: Elijah Newren <newren@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
builtin/stash.c | 13 ++++++++-----
t/t2501-cwd-empty.sh | 2 +-
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c
index a0ccc8654df..556287cdb56 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1404,7 +1404,8 @@ static int create_stash(int argc, const char **argv, const char *prefix)
return ret;
}
-static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int quiet,
+static int do_push_stash(const struct pathspec *ps, const char *stash_msg,
+ const char *prefix, int quiet,
int keep_index, int patch_mode, int include_untracked)
{
int ret = 0;
@@ -1485,8 +1486,10 @@ 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 (prefix)
+ strvec_pushl(&cp.args, "-C", prefix, NULL);
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)) {
@@ -1656,8 +1659,8 @@ static int push_stash(int argc, const char **argv, const char *prefix,
die(_("--pathspec-file-nul requires --pathspec-from-file"));
}
- return do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
- include_untracked);
+ return do_push_stash(&ps, stash_msg, prefix, quiet, keep_index,
+ patch_mode, include_untracked);
}
static int save_stash(int argc, const char **argv, const char *prefix)
@@ -1693,7 +1696,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
stash_msg = strbuf_join_argv(&stash_msg_buf, argc, argv, ' ');
memset(&ps, 0, sizeof(ps));
- ret = do_push_stash(&ps, stash_msg, quiet, keep_index,
+ ret = do_push_stash(&ps, stash_msg, prefix, quiet, keep_index,
patch_mode, include_untracked);
strbuf_release(&stash_msg_buf);
diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh
index 20e1b6adede..ff4e7cd89fa 100755
--- a/t/t2501-cwd-empty.sh
+++ b/t/t2501-cwd-empty.sh
@@ -236,7 +236,7 @@ test_expect_success 'clean does not remove cwd incidentally' '
test_path_is_dir untracked
'
-test_expect_failure 'stash does not remove cwd incidentally' '
+test_expect_success 'stash does not remove cwd incidentally' '
git checkout foo/bar/baz &&
test_when_finished "git clean -fdx" &&
--
gitgitgadget