summaryrefslogtreecommitdiff
path: root/t/t7406-submodule-update.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t7406-submodule-update.sh')
-rwxr-xr-xt/t7406-submodule-update.sh256
1 files changed, 218 insertions, 38 deletions
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index aa19ff3..8491b8c 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -9,19 +9,23 @@ This test verifies that "git submodule update" detaches the HEAD of the
submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
compare_head()
{
- sha_master=$(git rev-list --max-count=1 master)
+ sha_main=$(git rev-list --max-count=1 main)
sha_head=$(git rev-list --max-count=1 HEAD)
- test "$sha_master" = "$sha_head"
+ test "$sha_main" = "$sha_head"
}
test_expect_success 'setup a submodule tree' '
+ git config --global protocol.file.allow always &&
echo file > file &&
git add file &&
test_tick &&
@@ -152,9 +156,9 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
cd tmp &&
git submodule update --init --recursive ../super >../../actual 2>../../actual2
) &&
- test_i18ncmp expect actual &&
+ test_cmp expect actual &&
sort actual2 >actual2.sorted &&
- test_i18ncmp expect2 actual2.sorted
+ test_cmp expect2 actual2.sorted
'
cat <<EOF >expect2
@@ -171,7 +175,7 @@ test_expect_success 'submodule update --init from and of subdirectory' '
git submodule update --init sub 2>../../actual2
)
) &&
- test_i18ncmp expect2 actual2
+ test_cmp expect2 actual2
'
test_expect_success 'submodule update does not fetch already present commits' '
@@ -189,7 +193,7 @@ test_expect_success 'submodule update does not fetch already present commits' '
(cd super &&
git submodule update > ../actual 2> ../actual.err
) &&
- test_i18ncmp expected actual &&
+ test_cmp expected actual &&
test_must_be_empty actual.err
'
@@ -202,8 +206,18 @@ test_expect_success 'submodule update should fail due to local changes' '
(cd submodule &&
compare_head
) &&
- test_must_fail git submodule update submodule
- )
+ test_must_fail git submodule update submodule 2>../actual.raw
+ ) &&
+ sed "s/^> //" >expect <<-\EOF &&
+ > error: Your local changes to the following files would be overwritten by checkout:
+ > file
+ > Please commit your changes or stash them before you switch branches.
+ > Aborting
+ > fatal: Unable to checkout OID in submodule path '\''submodule'\''
+ EOF
+ sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
+ test_cmp expect actual
+
'
test_expect_success 'submodule update should throw away changes with --force ' '
(cd super &&
@@ -262,14 +276,14 @@ test_expect_success 'submodule update --remote should fetch upstream changes wit
cd super &&
git submodule update --remote --force submodule &&
git -C submodule log -1 --oneline >actual &&
- git -C ../submodule log -1 --oneline master >expect &&
+ git -C ../submodule log -1 --oneline main >expect &&
test_cmp expect actual &&
git checkout -b test-branch &&
git submodule update --remote --force submodule &&
git -C submodule log -1 --oneline >actual &&
git -C ../submodule log -1 --oneline test-branch >expect &&
test_cmp expect actual &&
- git checkout master &&
+ git checkout main &&
git branch -d test-branch &&
git reset --hard HEAD^
)
@@ -282,7 +296,7 @@ test_expect_success 'local config should override .gitmodules branch' '
git add file &&
test_tick &&
git commit -m "upstream line5" &&
- git checkout master
+ git checkout main
) &&
(cd super &&
git config submodule.submodule.branch test-branch &&
@@ -292,9 +306,9 @@ test_expect_success 'local config should override .gitmodules branch' '
)
'
-test_expect_success 'submodule update --rebase staying on master' '
+test_expect_success 'submodule update --rebase staying on main' '
(cd super/submodule &&
- git checkout master
+ git checkout main
) &&
(cd super &&
(cd submodule &&
@@ -306,7 +320,7 @@ test_expect_success 'submodule update --rebase staying on master' '
)
'
-test_expect_success 'submodule update --merge staying on master' '
+test_expect_success 'submodule update --merge staying on main' '
(cd super/submodule &&
git reset --hard HEAD~1
) &&
@@ -445,7 +459,7 @@ test_expect_success 'fsck detects command in .gitmodules' '
'
cat << EOF >expect
-Execution of 'false $submodulesha1' failed in submodule path 'submodule'
+fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
EOF
test_expect_success 'submodule update - command in .git/config catches failure' '
@@ -458,11 +472,11 @@ test_expect_success 'submodule update - command in .git/config catches failure'
(cd super &&
test_must_fail git submodule update submodule 2>../actual
) &&
- test_i18ncmp actual expect
+ test_cmp actual expect
'
cat << EOF >expect
-Execution of 'false $submodulesha1' failed in submodule path '../submodule'
+fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
EOF
test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
@@ -476,22 +490,22 @@ test_expect_success 'submodule update - command in .git/config catches failure -
mkdir tmp && cd tmp &&
test_must_fail git submodule update ../submodule 2>../../actual
) &&
- test_i18ncmp actual expect
+ test_cmp actual expect
'
test_expect_success 'submodule update - command run for initial population of submodule' '
cat >expect <<-EOF &&
- Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
+ fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
EOF
rm -rf super/submodule &&
test_must_fail git -C super submodule update 2>actual &&
- test_i18ncmp expect actual &&
+ test_cmp expect actual &&
git -C super submodule update --checkout
'
cat << EOF >expect
-Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
-Failed to recurse into submodule path '../super'
+fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
+fatal: Failed to recurse into submodule path '../super'
EOF
test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
@@ -506,7 +520,7 @@ test_expect_success 'recursive submodule update - command in .git/config catches
mkdir -p tmp && cd tmp &&
test_must_fail git submodule update --recursive ../super 2>../../actual
) &&
- test_i18ncmp actual expect
+ test_cmp actual expect
'
test_expect_success 'submodule init does not copy command into .git/config' '
@@ -609,7 +623,7 @@ test_expect_success 'submodule update - update=none in .git/config' '
(cd super &&
git config submodule.submodule.update none &&
(cd submodule &&
- git checkout master &&
+ git checkout main &&
compare_head
) &&
git diff --name-only >out &&
@@ -629,7 +643,7 @@ test_expect_success 'submodule update - update=none in .git/config but --checkou
(cd super &&
git config submodule.submodule.update none &&
(cd submodule &&
- git checkout master &&
+ git checkout main &&
compare_head
) &&
git diff --name-only >out &&
@@ -657,6 +671,39 @@ test_expect_success 'submodule update --init skips submodule with update=none' '
)
'
+test_expect_success 'submodule update with pathspec warns against uninitialized ones' '
+ test_when_finished "rm -fr selective" &&
+ git clone super selective &&
+ (
+ cd selective &&
+ git submodule init submodule &&
+
+ git submodule update submodule 2>err &&
+ ! grep "Submodule path .* not initialized" err &&
+
+ git submodule update rebasing 2>err &&
+ grep "Submodule path .rebasing. not initialized" err &&
+
+ test_path_exists submodule/.git &&
+ test_path_is_missing rebasing/.git
+ )
+
+'
+
+test_expect_success 'submodule update without pathspec updates only initialized ones' '
+ test_when_finished "rm -fr selective" &&
+ git clone super selective &&
+ (
+ cd selective &&
+ git submodule init submodule &&
+ git submodule update 2>err &&
+ test_path_exists submodule/.git &&
+ test_path_is_missing rebasing/.git &&
+ ! grep "Submodule path .* not initialized" err
+ )
+
+'
+
test_expect_success 'submodule update continues after checkout error' '
(cd super &&
git reset --hard HEAD &&
@@ -689,7 +736,7 @@ test_expect_success 'submodule update continues after checkout error' '
test_expect_success 'submodule update continues after recursive checkout error' '
(cd super &&
git reset --hard HEAD &&
- git checkout master &&
+ git checkout main &&
git submodule update &&
(cd submodule &&
git submodule add ../submodule subsubmodule &&
@@ -723,7 +770,7 @@ test_expect_success 'submodule update continues after recursive checkout error'
echo "" > file
)
) &&
- test_must_fail git submodule update --recursive &&
+ test_expect_code 1 git submodule update --recursive &&
(cd submodule2 &&
git rev-parse --verify HEAD >../actual
) &&
@@ -733,7 +780,7 @@ test_expect_success 'submodule update continues after recursive checkout error'
test_expect_success 'submodule update exit immediately in case of merge conflict' '
(cd super &&
- git checkout master &&
+ git checkout main &&
git reset --hard HEAD &&
(cd submodule &&
(cd subsubmodule &&
@@ -751,7 +798,7 @@ test_expect_success 'submodule update exit immediately in case of merge conflict
git add submodule2 &&
git commit -m "two_new_submodule_commits" &&
(cd submodule &&
- git checkout master &&
+ git checkout main &&
test_commit "conflict" file &&
echo "conflict" > file
) &&
@@ -770,7 +817,7 @@ test_expect_success 'submodule update exit immediately in case of merge conflict
test_expect_success 'submodule update exit immediately after recursive rebase error' '
(cd super &&
- git checkout master &&
+ git checkout main &&
git reset --hard HEAD &&
(cd submodule &&
git reset --hard HEAD &&
@@ -786,7 +833,7 @@ test_expect_success 'submodule update exit immediately after recursive rebase er
git add submodule2 &&
git commit -m "two_new_submodule_commits" &&
(cd submodule &&
- git checkout master &&
+ git checkout main &&
test_commit "conflict2" file &&
echo "conflict" > file
) &&
@@ -878,27 +925,27 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re
git clone subsubsuper_update_r subsubsuper_update_r2 &&
(cd subsubsuper_update_r2 &&
test_commit "update_subsubsuper" file &&
- git push origin master
+ git push origin main
) &&
git clone subsuper_update_r subsuper_update_r2 &&
(cd subsuper_update_r2 &&
test_commit "update_subsuper" file &&
git submodule add ../subsubsuper_update_r subsubmodule &&
git commit -am "subsubmodule" &&
- git push origin master
+ git push origin main
) &&
git clone super_update_r super_update_r2 &&
(cd super_update_r2 &&
test_commit "update_super" file &&
git submodule add ../subsuper_update_r submodule &&
git commit -am "submodule" &&
- git push origin master
+ git push origin main
) &&
rm -rf super_update_r2 &&
git clone super_update_r super_update_r2 &&
(cd super_update_r2 &&
git submodule update --init --recursive >actual &&
- test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
+ test_grep "Submodule path .submodule/subsubmodule.: checked out" actual &&
(cd submodule/subsubmodule &&
git log > ../../expected
) &&
@@ -911,7 +958,7 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re
test_expect_success 'submodule add properly re-creates deeper level submodules' '
(cd super &&
- git reset --hard master &&
+ git reset --hard main &&
rm -rf deeper/ &&
git submodule add --force ../submodule deeper/submodule
)
@@ -978,7 +1025,7 @@ test_expect_success 'submodule update clone shallow submodule outside of depth'
# unadvertised objects, so restrict this test to v0.
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
git submodule update --init --depth=1 2>actual &&
- test_i18ngrep "Direct fetching of that commit failed." actual &&
+ test_grep "Direct fetching of that commit failed." actual &&
git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
git submodule update --init --depth=1 >actual &&
git -C submodule log --oneline >out &&
@@ -992,7 +1039,7 @@ test_expect_success 'submodule update --recursive drops module name before recur
git checkout HEAD^
) &&
git submodule update --recursive deeper/submodule >actual &&
- test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
+ test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
)
'
@@ -1022,4 +1069,137 @@ test_expect_success 'git clone passes the parallel jobs config on to submodules'
rm -rf super4
'
+test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '
+ (cd super &&
+ test_commit -C rebasing message &&
+ git submodule update --rebase --quiet >out 2>err &&
+ test_must_be_empty out &&
+ test_must_be_empty err &&
+ git submodule update --rebase >out 2>err &&
+ test_file_not_empty out &&
+ test_must_be_empty err
+ )
+'
+
+test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' '
+ test_when_finished "rm -rf super4 super5 super6" &&
+ git clone . super4 &&
+ (cd super4 &&
+ git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
+ git commit -am "setup submodule3"
+ ) &&
+ (cd submodule &&
+ test_commit line6 file
+ ) &&
+ git clone super4 super5 &&
+ (cd super5 &&
+ git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
+ test_must_be_empty out &&
+ test_must_be_empty err
+ ) &&
+ git clone super4 super6 &&
+ (cd super6 &&
+ git submodule update --init --depth=1 submodule3 >out 2>err &&
+ test_file_not_empty out &&
+ test_file_not_empty err
+ )
+'
+
+test_expect_success 'submodule update --filter requires --init' '
+ test_expect_code 129 git -C super submodule update --filter blob:none
+'
+
+test_expect_success 'submodule update --filter sets partial clone settings' '
+ test_when_finished "rm -rf super-filter" &&
+ git clone cloned super-filter &&
+ git -C super-filter submodule update --init --filter blob:none &&
+ test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
+ test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
+'
+
+# NEEDSWORK: Clean up the tests so that we can reuse the test setup.
+# Don't reuse the existing repos because the earlier tests have
+# intentionally disruptive configurations.
+test_expect_success 'setup clean recursive superproject' '
+ git init bottom &&
+ test_commit -C bottom "bottom" &&
+ git init middle &&
+ git -C middle submodule add ../bottom bottom &&
+ git -C middle commit -m "middle" &&
+ git init top &&
+ git -C top submodule add ../middle middle &&
+ git -C top commit -m "top" &&
+ git clone --recurse-submodules top top-clean
+'
+
+test_expect_success 'submodule update should skip unmerged submodules' '
+ test_when_finished "rm -fr top-cloned" &&
+ cp -r top-clean top-cloned &&
+
+ # Create an upstream commit in each repo, starting with bottom
+ test_commit -C bottom upstream_commit &&
+ # Create middle commit
+ git -C middle/bottom fetch &&
+ git -C middle/bottom checkout -f FETCH_HEAD &&
+ git -C middle add bottom &&
+ git -C middle commit -m "upstream_commit" &&
+ # Create top commit
+ git -C top/middle fetch &&
+ git -C top/middle checkout -f FETCH_HEAD &&
+ git -C top add middle &&
+ git -C top commit -m "upstream_commit" &&
+
+ # Create a downstream conflict
+ test_commit -C top-cloned/middle/bottom downstream_commit &&
+ git -C top-cloned/middle add bottom &&
+ git -C top-cloned/middle commit -m "downstream_commit" &&
+ git -C top-cloned/middle fetch --recurse-submodules origin &&
+ test_must_fail git -C top-cloned/middle merge origin/main &&
+
+ # Make the update of "middle" a no-op, otherwise we error out
+ # because of its unmerged state
+ test_config -C top-cloned submodule.middle.update !true &&
+ git -C top-cloned submodule update --recursive 2>actual.err &&
+ cat >expect.err <<-\EOF &&
+ Skipping unmerged submodule middle/bottom
+ EOF
+ test_cmp expect.err actual.err
+'
+
+test_expect_success 'submodule update --recursive skip submodules with strategy=none' '
+ test_when_finished "rm -fr top-cloned" &&
+ cp -r top-clean top-cloned &&
+
+ test_commit -C top-cloned/middle/bottom downstream_commit &&
+ git -C top-cloned/middle config submodule.bottom.update none &&
+ git -C top-cloned submodule update --recursive 2>actual.err &&
+ cat >expect.err <<-\EOF &&
+ Skipping submodule '\''middle/bottom'\''
+ EOF
+ test_cmp expect.err actual.err
+'
+
+add_submodule_commit_and_validate () {
+ HASH=$(git rev-parse HEAD) &&
+ git update-index --add --cacheinfo 160000,$HASH,sub &&
+ git commit -m "create submodule" &&
+ echo "160000 commit $HASH sub" >expect &&
+ git ls-tree HEAD -- sub >actual &&
+ test_cmp expect actual
+}
+
+test_expect_success 'commit with staged submodule change' '
+ add_submodule_commit_and_validate
+'
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' '
+ test_config diff.ignoreSubmodules dirty &&
+ add_submodule_commit_and_validate
+'
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules all' '
+ test_config diff.ignoreSubmodules all &&
+ add_submodule_commit_and_validate
+'
+
test_done