{"thread":{"id":"58604","subject":"[PATCH] tests: add test highlighting submodule remote breakage","startedAt":"2022-10-12T00:06:42Z","lastAt":"2022-10-12T00:06:42Z","messageCount":1,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"464643","messageId":"20221012000630.1442340-1-jacob.e.keller@intel.com","threadId":"58604","inReplyTo":null,"subject":"[PATCH] tests: add test highlighting submodule remote breakage","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2022-10-12T00:06:30Z","receivedAt":"2022-10-12T00:06:42Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nIf a user renames the \"origin\" remote of a submodule, recursive fetching\ncan sometimes fail with an error similar to:\n\n  From git/git/t/trash directory.t5526-fetch-submodules/.\n     210db27..1fc7e77  super      -> origin/super\n  Fetching submodule submodule\n  fatal: 'origin' does not appear to be a git repository\n  fatal: Could not read from remote repository.\n\n  Please make sure you have the correct access rights\n  and the repository exists.\n  Errors during submodule fetch:\n          submodule\n\nThis occurs because of the way that recursive submodule fetch tries to\nguess the remote name. It will fall back to the origin term even if that\nremote doesn't exist.\n\nAdd a test which sets up this environment and shows the failure. The\nproblem only exists if there are multiple remotes, so add both a test\nfor a single remote and a test for multiple remotes which is marked as\ntest_expect_failure.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t5526-fetch-submodules.sh | 54 ++++++++++++++++++++++++++++++++++---\n 1 file changed, 50 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh\nindex a301b56db894..1c45f1d72c94 100755\n--- a/t/t5526-fetch-submodules.sh\n+++ b/t/t5526-fetch-submodules.sh\n@@ -10,16 +10,21 @@ export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB\n \n pwd=$(pwd)\n \n-write_expected_sub () {\n-\tNEW_HEAD=$1 &&\n-\tSUPER_HEAD=$2 &&\n+write_expected_sub_remote () {\n+\tREMOTE=$1 &&\n+\tNEW_HEAD=$2 &&\n+\tSUPER_HEAD=$3 &&\n \tcat >\"$pwd/expect.err.sub\" <<-EOF\n \tFetching submodule submodule${SUPER_HEAD:+ at commit $SUPER_HEAD}\n \tFrom $pwd/submodule\n-\t   OLD_HEAD..$NEW_HEAD  sub        -> origin/sub\n+\t   OLD_HEAD..$NEW_HEAD  sub        -> $REMOTE/sub\n \tEOF\n }\n \n+write_expected_sub () {\n+\twrite_expected_sub_remote origin $1 $2\n+}\n+\n write_expected_sub2 () {\n \tNEW_HEAD=$1 &&\n \tSUPER_HEAD=$2 &&\n@@ -718,6 +723,47 @@ test_expect_success 'fetching submodules respects parallel settings' '\n \t)\n '\n \n+test_expect_success 'fetching submodules works after remote rename' '\n+\ttest_when_finished \"git -C downstream/submodule remote rename upstream origin\" &&\n+\tadd_submodule_commits &&\n+\tadd_superproject_commits &&\n+\t(\n+\t\tcd submodule &&\n+\t\tnew_head=$(git rev-parse --short HEAD) &&\n+\t\twrite_expected_sub_remote upstream $new_head\n+\t) &&\n+\t(\n+\t\tcd downstream &&\n+\t\tgit -C submodule remote rename origin upstream &&\n+\t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err\n+\t) &&\n+\ttest_must_be_empty actual.out &&\n+\tverify_fetch_result actual.err\n+'\n+\n+test_expect_failure 'fetching submodules works after remote rename with multiple remotes' '\n+\ttest_when_finished \"git -C downstream/submodule remote rename upstream origin\" &&\n+\ttest_when_finished \"git -C downstream/submodule remote rm other\" &&\n+\tadd_submodule_commits &&\n+\tadd_superproject_commits &&\n+\t(\n+\t\tcd submodule &&\n+\t\tnew_head=$(git rev-parse --short HEAD) &&\n+\t\twrite_expected_sub_remote upstream $new_head\n+\t) &&\n+\t(\n+\t\tcd downstream &&\n+\t\t(\n+\t\t\tcd submodule &&\n+\t\t\tgit remote rename origin upstream &&\n+\t\t\tgit remote add other http://other.invalid\n+\t\t) &&\n+\t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err\n+\t) &&\n+\ttest_must_be_empty actual.out &&\n+\tverify_fetch_result actual.err\n+'\n+\n test_expect_success 'fetching submodule into a broken repository' '\n \t# Prepare src and src/sub nested in it\n \tgit init src &&\n-- \n2.38.0.83.gd420dda05763\n\n"}]}