Skip to content

Commit bb52def

Browse files
committed
Merge branch 'jj/stash-reset-only-toplevel'
"git stash save" lost local changes to submodules, which has been corrected. * jj/stash-reset-only-toplevel: stash: avoid recursive hard reset on submodules
2 parents f1afbb0 + 556895d commit bb52def

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
13921392
struct child_process cp = CHILD_PROCESS_INIT;
13931393
cp.git_cmd = 1;
13941394
argv_array_pushl(&cp.args, "reset", "--hard", "-q",
1395-
NULL);
1395+
"--no-recurse-submodules", NULL);
13961396
if (run_command(&cp)) {
13971397
ret = -1;
13981398
goto done;

git-legacy-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ push_stash () {
370370
git diff-index -p --cached --binary HEAD -- "$@" |
371371
git apply --index -R
372372
else
373-
git reset --hard -q
373+
git reset --hard -q --no-recurse-submodules
374374
fi
375375

376376
if test "$keep_index" = "t" && test -n "$i_tree"

t/t3906-stash-submodule.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
test_description='stash apply can handle submodules'
3+
test_description='stash can handle submodules'
44

55
. ./test-lib.sh
66
. "$TEST_DIRECTORY"/lib-submodule-update.sh
@@ -21,4 +21,44 @@ KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
2121
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
2222
test_submodule_switch "git_stash"
2323

24+
setup_basic () {
25+
test_when_finished "rm -rf main sub" &&
26+
git init sub &&
27+
(
28+
cd sub &&
29+
test_commit sub_file
30+
) &&
31+
git init main &&
32+
(
33+
cd main &&
34+
git submodule add ../sub &&
35+
test_commit main_file
36+
)
37+
}
38+
39+
test_expect_success 'stash push with submodule.recurse=true preserves dirty submodule worktree' '
40+
setup_basic &&
41+
(
42+
cd main &&
43+
git config submodule.recurse true &&
44+
echo "x" >main_file.t &&
45+
echo "y" >sub/sub_file.t &&
46+
git stash push &&
47+
test_must_fail git -C sub diff --quiet
48+
)
49+
'
50+
51+
test_expect_success 'stash push and pop with submodule.recurse=true preserves dirty submodule worktree' '
52+
setup_basic &&
53+
(
54+
cd main &&
55+
git config submodule.recurse true &&
56+
echo "x" >main_file.t &&
57+
echo "y" >sub/sub_file.t &&
58+
git stash push &&
59+
git stash pop &&
60+
test_must_fail git -C sub diff --quiet
61+
)
62+
'
63+
2464
test_done

0 commit comments

Comments
 (0)