Skip to content

Commit da7fe3f

Browse files
jlehmanngitster
authored andcommitted
stash: add t3906 for submodule updates
Test that the stash apply command updates the work tree as expected for changes which don't result in conflicts. To make that work add a helper function that uses read-tree to apply the changes of the target commit to the work tree, then stashes these changes and at last applies that stash. Implement the KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES switch and reuse two other already present switches to expect the known failure that stash does ignore submodule changes. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23e2f38 commit da7fe3f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

t/lib-submodule-update.sh

+18-5
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,14 @@ test_submodule_switch () {
227227
command="$1"
228228
######################### Appearing submodule #########################
229229
# Switching to a commit letting a submodule appear creates empty dir ...
230-
test_expect_success "$command: added submodule creates empty directory" '
230+
if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1
231+
then
232+
# Restoring stash fails to restore submodule index entry
233+
RESULT="failure"
234+
else
235+
RESULT="success"
236+
fi
237+
test_expect_$RESULT "$command: added submodule creates empty directory" '
231238
prolog &&
232239
reset_work_tree_to no_submodule &&
233240
(
@@ -241,7 +248,7 @@ test_submodule_switch () {
241248
)
242249
'
243250
# ... and doesn't care if it already exists ...
244-
test_expect_success "$command: added submodule leaves existing empty directory alone" '
251+
test_expect_$RESULT "$command: added submodule leaves existing empty directory alone" '
245252
prolog &&
246253
reset_work_tree_to no_submodule &&
247254
(
@@ -270,7 +277,7 @@ test_submodule_switch () {
270277
'
271278
# Replacing a tracked file with a submodule produces an empty
272279
# directory ...
273-
test_expect_success "$command: replace tracked file with submodule creates empty directory" '
280+
test_expect_$RESULT "$command: replace tracked file with submodule creates empty directory" '
274281
prolog &&
275282
reset_work_tree_to replace_sub1_with_file &&
276283
(
@@ -310,7 +317,13 @@ test_submodule_switch () {
310317

311318
######################## Disappearing submodule #######################
312319
# Removing a submodule doesn't remove its work tree ...
313-
test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" '
320+
if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1
321+
then
322+
RESULT="failure"
323+
else
324+
RESULT="success"
325+
fi
326+
test_expect_$RESULT "$command: removed submodule leaves submodule directory and its contents in place" '
314327
prolog &&
315328
reset_work_tree_to add_sub1 &&
316329
(
@@ -322,7 +335,7 @@ test_submodule_switch () {
322335
)
323336
'
324337
# ... especially when it contains a .git directory.
325-
test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" '
338+
test_expect_$RESULT "$command: removed submodule leaves submodule containing a .git directory alone" '
326339
prolog &&
327340
reset_work_tree_to add_sub1 &&
328341
(

t/t3906-stash-submodule.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
test_description='stash apply can handle submodules'
4+
5+
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-submodule-update.sh
7+
8+
git_stash () {
9+
git status -su >expect &&
10+
ls -1pR * >>expect &&
11+
git read-tree -u -m "$1" &&
12+
git stash &&
13+
git status -su >actual &&
14+
ls -1pR * >>actual &&
15+
test_cmp expect actual &&
16+
git stash apply
17+
}
18+
19+
KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
20+
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
21+
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
22+
test_submodule_switch "git_stash"
23+
24+
test_done

0 commit comments

Comments
 (0)