[PATCH] tests: add test highlighting submodule remote breakage
From: Jacob Keller <jacob.e.keller@intel.com>
Date: 2022-10-12 00:06:42
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Jacob Keller <redacted>
If a user renames the "origin" remote of a submodule, recursive fetching
can sometimes fail with an error similar to:
From git/git/t/trash directory.t5526-fetch-submodules/.
210db27..1fc7e77 super -> origin/super
Fetching submodule submodule
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Errors during submodule fetch:
submodule
This occurs because of the way that recursive submodule fetch tries to
guess the remote name. It will fall back to the origin term even if that
remote doesn't exist.
Add a test which sets up this environment and shows the failure. The
problem only exists if there are multiple remotes, so add both a test
for a single remote and a test for multiple remotes which is marked as
test_expect_failure.
Signed-off-by: Jacob Keller <redacted>
---
t/t5526-fetch-submodules.sh | 54 ++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 4 deletions(-)
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh
index a301b56db894..1c45f1d72c94 100755
--- a/t/t5526-fetch-submodules.sh
+++ b/t/t5526-fetch-submodules.sh@@ -10,16 +10,21 @@ export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB pwd=$(pwd) -write_expected_sub () { - NEW_HEAD=$1 && - SUPER_HEAD=$2 && +write_expected_sub_remote () { + REMOTE=$1 && + NEW_HEAD=$2 && + SUPER_HEAD=$3 && cat >"$pwd/expect.err.sub" <<-EOF Fetching submodule submodule${SUPER_HEAD:+ at commit $SUPER_HEAD} From $pwd/submodule - OLD_HEAD..$NEW_HEAD sub -> origin/sub + OLD_HEAD..$NEW_HEAD sub -> $REMOTE/sub EOF } +write_expected_sub () { + write_expected_sub_remote origin $1 $2 +} + write_expected_sub2 () { NEW_HEAD=$1 && SUPER_HEAD=$2 &&
@@ -718,6 +723,47 @@ test_expect_success 'fetching submodules respects parallel settings' ' ) ' +test_expect_success 'fetching submodules works after remote rename' ' + test_when_finished "git -C downstream/submodule remote rename upstream origin" && + add_submodule_commits && + add_superproject_commits && + ( + cd submodule && + new_head=$(git rev-parse --short HEAD) && + write_expected_sub_remote upstream $new_head + ) && + ( + cd downstream && + git -C submodule remote rename origin upstream && + git fetch --recurse-submodules >../actual.out 2>../actual.err + ) && + test_must_be_empty actual.out && + verify_fetch_result actual.err +' + +test_expect_failure 'fetching submodules works after remote rename with multiple remotes' ' + test_when_finished "git -C downstream/submodule remote rename upstream origin" && + test_when_finished "git -C downstream/submodule remote rm other" && + add_submodule_commits && + add_superproject_commits && + ( + cd submodule && + new_head=$(git rev-parse --short HEAD) && + write_expected_sub_remote upstream $new_head + ) && + ( + cd downstream && + ( + cd submodule && + git remote rename origin upstream && + git remote add other http://other.invalid + ) && + git fetch --recurse-submodules >../actual.out 2>../actual.err + ) && + test_must_be_empty actual.out && + verify_fetch_result actual.err +' + test_expect_success 'fetching submodule into a broken repository' ' # Prepare src and src/sub nested in it git init src &&
--
2.38.0.83.gd420dda05763