git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Glen Choo <chooglen@google.com>, Jacob Keller <jacob.keller@gmail.com>
Subject: [PATCH] tests: add test highlighting submodule remote breakage
Date: Tue, 11 Oct 2022 17:06:30 -0700	[thread overview]
Message-ID: <20221012000630.1442340-1-jacob.e.keller@intel.com> (raw)

From: Jacob Keller <jacob.keller@gmail.com>

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 <jacob.keller@gmail.com>
---
 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


                 reply	other threads:[~2022-10-12  0:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221012000630.1442340-1-jacob.e.keller@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=jacob.keller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).