summaryrefslogtreecommitdiff
path: root/t/lib-submodule-update.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/lib-submodule-update.sh')
-rw-r--r--t/lib-submodule-update.sh133
1 files changed, 84 insertions, 49 deletions
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 64fc648..36f767c 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
git init submodule_update_repo &&
(
cd submodule_update_repo &&
+ branch=$(git symbolic-ref --short HEAD) &&
echo "expect" >>.gitignore &&
echo "actual" >>.gitignore &&
echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
git checkout -b valid_sub1 &&
git revert HEAD &&
- git checkout master
+ git checkout "$branch"
)
}
@@ -167,28 +168,26 @@ replace_gitfile_with_git_dir () {
# Note that this only supports submodules at the root level of the
# superproject, with the default name, i.e. same as its path.
test_git_directory_is_unchanged () {
- (
- cd ".git/modules/$1" &&
- # does core.worktree point at the right place?
- test "$(git config core.worktree)" = "../../../$1" &&
- # remove it temporarily before comparing, as
- # "$1/.git/config" lacks it...
- git config --unset core.worktree
- ) &&
+ # does core.worktree point at the right place?
+ echo "../../../$1" >expect &&
+ git -C ".git/modules/$1" config core.worktree >actual &&
+ test_cmp expect actual &&
+ # remove it temporarily before comparing, as
+ # "$1/.git/config" lacks it...
+ git -C ".git/modules/$1" config --unset core.worktree &&
diff -r ".git/modules/$1" "$1/.git" &&
- (
- # ... and then restore.
- cd ".git/modules/$1" &&
- git config core.worktree "../../../$1"
- )
+ # ... and then restore.
+ git -C ".git/modules/$1" config core.worktree "../../../$1"
}
-test_git_directory_exists() {
+test_git_directory_exists () {
test -e ".git/modules/$1" &&
if test -f sub1/.git
then
# does core.worktree point at the right place?
- test "$(git -C .git/modules/$1 config core.worktree)" = "../../../$1"
+ echo "../../../$1" >expect &&
+ git -C ".git/modules/$1" config core.worktree >actual &&
+ test_cmp expect actual
fi
}
@@ -196,7 +195,7 @@ test_git_directory_exists() {
# the submodule repo if it doesn't exist and configures the most problematic
# settings for diff.ignoreSubmodules.
prolog () {
- test_oid_init &&
+ test_config_global protocol.file.allow always &&
(test -d submodule_update_repo || create_lib_submodule_repo) &&
test_config_global diff.ignoreSubmodules all &&
test_config diff.ignoreSubmodules all
@@ -207,7 +206,7 @@ prolog () {
# should be updated to an existing commit.
reset_work_tree_to () {
rm -rf submodule_update &&
- git clone submodule_update_repo submodule_update &&
+ git clone --template= submodule_update_repo submodule_update &&
(
cd submodule_update &&
rm -rf sub1 &&
@@ -303,24 +302,21 @@ test_submodule_content () {
# update" is run. And even then that command doesn't delete the work tree of
# a removed submodule.
#
+# The first argument of the callback function will be the name of the submodule.
+#
# Removing a submodule containing a .git directory must fail even when forced
-# to protect the history!
+# to protect the history! If we are testing this case, the second argument of
+# the callback function will be 'test_must_fail', else it will be the empty
+# string.
#
-# Internal function; use test_submodule_switch() or
-# test_submodule_forced_switch() instead.
-test_submodule_switch_common() {
+# Internal function; use test_submodule_switch_func(), test_submodule_switch(),
+# or test_submodule_forced_switch() instead.
+test_submodule_switch_common () {
command="$1"
######################### Appearing submodule #########################
# Switching to a commit letting a submodule appear creates empty dir ...
- 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" '
+ test_expect_success "$command: added submodule creates empty directory" '
prolog &&
reset_work_tree_to no_submodule &&
(
@@ -334,6 +330,13 @@ test_submodule_switch_common() {
)
'
# ... and doesn't care if it already exists.
+ 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 leaves existing empty directory alone" '
prolog &&
reset_work_tree_to no_submodule &&
@@ -443,7 +446,7 @@ test_submodule_switch_common() {
(
cd submodule_update &&
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
- test_must_fail $command replace_sub1_with_directory &&
+ $command replace_sub1_with_directory test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_submodule_content sub1 origin/add_sub1
)
@@ -456,7 +459,7 @@ test_submodule_switch_common() {
cd submodule_update &&
git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&
replace_gitfile_with_git_dir sub1 &&
- test_must_fail $command replace_sub1_with_directory &&
+ $command replace_sub1_with_directory test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_git_directory_is_unchanged sub1 &&
test_submodule_content sub1 origin/add_sub1
@@ -470,7 +473,7 @@ test_submodule_switch_common() {
(
cd submodule_update &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
- test_must_fail $command replace_sub1_with_file &&
+ $command replace_sub1_with_file test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_submodule_content sub1 origin/add_sub1
)
@@ -484,7 +487,7 @@ test_submodule_switch_common() {
cd submodule_update &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
replace_gitfile_with_git_dir sub1 &&
- test_must_fail $command replace_sub1_with_file &&
+ $command replace_sub1_with_file test_must_fail &&
test_superproject_content origin/add_sub1 &&
test_git_directory_is_unchanged sub1 &&
test_submodule_content sub1 origin/add_sub1
@@ -559,15 +562,28 @@ test_submodule_switch_common() {
# conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests
# below to 1.
#
-# Use as follows:
+# The first argument of the callback function will be the name of the submodule.
+#
+# Removing a submodule containing a .git directory must fail even when forced
+# to protect the history! If we are testing this case, the second argument of
+# the callback function will be 'test_must_fail', else it will be the empty
+# string.
+#
+# The following example uses `git some-command` as an example command to be
+# tested. It updates the worktree and index to match a target, but not any
+# submodule directories.
#
# my_func () {
-# target=$1
-# # Do something here that updates the worktree and index to match target,
-# # but not any submodule directories.
+# ...prepare for `git some-command` to be run...
+# $2 git some-command "$1" &&
+# if test -n "$2"
+# then
+# return
+# fi &&
+# ...check the state after git some-command is run...
# }
-# test_submodule_switch "my_func"
-test_submodule_switch () {
+# test_submodule_switch_func "my_func"
+test_submodule_switch_func () {
command="$1"
test_submodule_switch_common "$command"
@@ -580,17 +596,33 @@ test_submodule_switch () {
cd submodule_update &&
git branch -t add_sub1 origin/add_sub1 &&
>sub1 &&
- test_must_fail $command add_sub1 &&
+ $command add_sub1 test_must_fail &&
test_superproject_content origin/no_submodule &&
test_must_be_empty sub1
)
'
}
+# Ensures that the that the arg either contains "test_must_fail" or is empty.
+may_only_be_test_must_fail () {
+ test -z "$1" || test "$1" = test_must_fail || die
+}
+
+git_test_func () {
+ may_only_be_test_must_fail "$2" &&
+ $2 git $gitcmd "$1"
+}
+
+test_submodule_switch () {
+ gitcmd="$1"
+ test_submodule_switch_func "git_test_func"
+}
+
# Same as test_submodule_switch(), except that throwing away local changes in
# the superproject is allowed.
test_submodule_forced_switch () {
- command="$1"
+ gitcmd="$1"
+ command="git_test_func"
KNOWN_FAILURE_FORCED_SWITCH_TESTS=1
test_submodule_switch_common "$command"
@@ -631,8 +663,8 @@ test_submodule_forced_switch () {
# Internal function; use test_submodule_switch_recursing_with_args() or
# test_submodule_forced_switch_recursing_with_args() instead.
-test_submodule_recursing_with_args_common() {
- command="$1"
+test_submodule_recursing_with_args_common () {
+ command="$1 --recurse-submodules"
######################### Appearing submodule #########################
# Switching to a commit letting a submodule appear checks it out ...
@@ -770,7 +802,7 @@ test_submodule_recursing_with_args_common() {
git branch -t no_submodule origin/no_submodule &&
$command no_submodule &&
test_superproject_content origin/no_submodule &&
- ! test_path_is_dir sub1 &&
+ test_path_is_missing sub1 &&
test_must_fail git config -f .git/modules/sub1/config core.worktree &&
test_must_fail git config -f .git/modules/sub1/modules/sub2/config core.worktree
)
@@ -798,7 +830,7 @@ test_submodule_recursing_with_args_common() {
cd submodule_update &&
git branch -t invalid_sub1 origin/invalid_sub1 &&
test_must_fail $command invalid_sub1 2>err &&
- test_i18ngrep sub1 err &&
+ test_grep sub1 err &&
test_superproject_content origin/add_sub1 &&
test_submodule_content sub1 origin/add_sub1
)
@@ -840,7 +872,7 @@ test_submodule_recursing_with_args_common() {
# test_submodule_switch_recursing_with_args "$GIT_COMMAND"
test_submodule_switch_recursing_with_args () {
cmd_args="$1"
- command="git $cmd_args --recurse-submodules"
+ command="git $cmd_args"
test_submodule_recursing_with_args_common "$command"
RESULTDS=success
@@ -869,13 +901,14 @@ test_submodule_switch_recursing_with_args () {
'
# ... but an ignored file is fine.
test_expect_$RESULTOI "$command: added submodule removes an untracked ignored file" '
- test_when_finished "rm submodule_update/.git/info/exclude" &&
+ test_when_finished "rm -rf submodule_update/.git/info" &&
prolog &&
reset_work_tree_to_interested no_submodule &&
(
cd submodule_update &&
git branch -t add_sub1 origin/add_sub1 &&
: >sub1 &&
+ mkdir .git/info &&
echo sub1 >.git/info/exclude &&
$command add_sub1 &&
test_superproject_content origin/add_sub1 &&
@@ -918,7 +951,9 @@ test_submodule_switch_recursing_with_args () {
reset_work_tree_to_interested add_sub1 &&
(
cd submodule_update &&
+ rm -rf .git/modules/sub1/info &&
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
+ mkdir .git/modules/sub1/info &&
echo ignored >.git/modules/sub1/info/exclude &&
: >sub1/ignored &&
$command replace_sub1_with_file &&
@@ -957,7 +992,7 @@ test_submodule_switch_recursing_with_args () {
# away local changes in the superproject is allowed.
test_submodule_forced_switch_recursing_with_args () {
cmd_args="$1"
- command="git $cmd_args --recurse-submodules"
+ command="git $cmd_args"
test_submodule_recursing_with_args_common "$command"
RESULT=success