Skip to content

Commit

Permalink
stash: add t3906 for submodule updates
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jlehmann authored and gitster committed Jul 14, 2014
1 parent 23e2f38 commit da7fe3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
23 changes: 18 additions & 5 deletions t/lib-submodule-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ test_submodule_switch () {
command="$1"
######################### Appearing submodule #########################
# Switching to a commit letting a submodule appear creates empty dir ...
test_expect_success "$command: added submodule creates empty directory" '
if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1
then
# Restoring stash fails to restore submodule index entry
RESULT="failure"
else
RESULT="success"
fi
test_expect_$RESULT "$command: added submodule creates empty directory" '
prolog &&
reset_work_tree_to no_submodule &&
(
Expand All @@ -241,7 +248,7 @@ test_submodule_switch () {
)
'
# ... and doesn't care if it already exists ...
test_expect_success "$command: added submodule leaves existing empty directory alone" '
test_expect_$RESULT "$command: added submodule leaves existing empty directory alone" '
prolog &&
reset_work_tree_to no_submodule &&
(
Expand Down Expand Up @@ -270,7 +277,7 @@ test_submodule_switch () {
'
# Replacing a tracked file with a submodule produces an empty
# directory ...
test_expect_success "$command: replace tracked file with submodule creates empty directory" '
test_expect_$RESULT "$command: replace tracked file with submodule creates empty directory" '
prolog &&
reset_work_tree_to replace_sub1_with_file &&
(
Expand Down Expand Up @@ -310,7 +317,13 @@ test_submodule_switch () {

######################## Disappearing submodule #######################
# Removing a submodule doesn't remove its work tree ...
test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" '
if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1
then
RESULT="failure"
else
RESULT="success"
fi
test_expect_$RESULT "$command: removed submodule leaves submodule directory and its contents in place" '
prolog &&
reset_work_tree_to add_sub1 &&
(
Expand All @@ -322,7 +335,7 @@ test_submodule_switch () {
)
'
# ... especially when it contains a .git directory.
test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" '
test_expect_$RESULT "$command: removed submodule leaves submodule containing a .git directory alone" '
prolog &&
reset_work_tree_to add_sub1 &&
(
Expand Down
24 changes: 24 additions & 0 deletions t/t3906-stash-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

test_description='stash apply can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

git_stash () {
git status -su >expect &&
ls -1pR * >>expect &&
git read-tree -u -m "$1" &&
git stash &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git stash apply
}

KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
test_submodule_switch "git_stash"

test_done

0 comments on commit da7fe3f

Please sign in to comment.