]> git.ipfire.org Git - thirdparty/git.git/commitdiff
stash: do not attempt to remove startup_info->original_cwd
authorElijah Newren <newren@gmail.com>
Thu, 9 Dec 2021 05:08:32 +0000 (05:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Dec 2021 21:33:13 +0000 (13:33 -0800)
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 <stolee@gmail.com>
Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/stash.c
t/t2501-cwd-empty.sh

index a0ccc8654dff70bd3014dca9d804a75bdd4c3cbc..de0e432a4ff901ce48508d879d35dc9d4238b457 100644 (file)
@@ -1485,8 +1485,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 (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)) {
index 52335a8afe9cee06f50cb6d5c58a978fe076dc5d..be9ef903bd4de6e1b0feddd8bbb0d4e71dfbe0c8 100755 (executable)
@@ -236,7 +236,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
 '