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 <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Jun 19, 2014 at 22:12 UTC da7fe3fb6d810507bef586e76a01bb34758d4472
2 files changed +42 -5
t/lib-submodule-update.sh
+18 -5
@@ -227,7 +227,14 @@ test_submodule_switch () {
227 command="$1"
228 ######################### Appearing submodule #########################
229 # 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" '
238 prolog &&
239 reset_work_tree_to no_submodule &&
240 (
@@ -241,7 +248,7 @@ test_submodule_switch () {
248 )
249 '
250 # ... 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" '
252 prolog &&
253 reset_work_tree_to no_submodule &&
254 (
@@ -270,7 +277,7 @@ test_submodule_switch () {
277 '
278 # Replacing a tracked file with a submodule produces an empty
279 # 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" '
281 prolog &&
282 reset_work_tree_to replace_sub1_with_file &&
283 (
@@ -310,7 +317,13 @@ test_submodule_switch () {
317
318 ######################## Disappearing submodule #######################
319 # 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" '
327 prolog &&
328 reset_work_tree_to add_sub1 &&
329 (
@@ -322,7 +335,7 @@ test_submodule_switch () {
335 )
336 '
337 # ... 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" '
339 prolog &&
340 reset_work_tree_to add_sub1 &&
341 (
t/t3906-stash-submodule.sh new
+24
@@ -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