Skip to content

Commit

Permalink
manifest_xml: fix url normalization for inits and remotes
Browse files Browse the repository at this point in the history
Before the change, repo normalizes the urls
with a following format only:

    [email protected]:foo/bar

It doesn't cover the following case:

   <remote name="org" fetch="[email protected]:org/" />
   <project name="somerepo" remote="org" />

Results to:
   error: Cannot fetch somerepo
     from ssh://[email protected]/org/[email protected]:org/somerepo

Current change fixes it by normalizing this format:

    [email protected]:foo

Test: ./run_tests tests/test_manifest_xml.py
Change-Id: I1ad0f5df0d52c0b7229ba4c9a4db4eecb5c1a003
Signed-off-by: Vitalii Dmitriev <[email protected]>
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/398337
Commit-Queue: Vitalii Dmitriev <[email protected]>
Tested-by: Vitalii Dmitriev <[email protected]>
Reviewed-by: Mike Frysinger <[email protected]>
  • Loading branch information
dmitvitalii authored and LUCI committed Dec 20, 2023
1 parent e5fb6e5 commit 449b23b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions manifest_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def normalize_url(url: str) -> str:
url = url.rstrip("/")
parsed_url = urllib.parse.urlparse(url)

# This matches patterns like "[email protected]:foo/bar".
scp_like_url_re = r"^[^/:]+@[^/:]+:[^/]+/"
# This matches patterns like "[email protected]:foo".
scp_like_url_re = r"^[^/:]+@[^/:]+:[^/]+"

# If our URL is missing a schema and matches git's
# SCP-like syntax we should convert it to a proper
Expand Down
36 changes: 36 additions & 0 deletions tests/test_manifest_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,9 @@ def test_has_trailing_slash(self):
"http://foo.com/bar/baz", manifest_xml.normalize_url(url)
)

url = "http://foo.com/bar/"
self.assertEqual("http://foo.com/bar", manifest_xml.normalize_url(url))

def test_has_leading_slash(self):
"""SCP-like syntax except a / comes before the : which git disallows."""
url = "/[email protected]:bar/baf"
Expand All @@ -1157,9 +1160,15 @@ def test_has_no_scheme(self):
url = "foo.com/baf/bat"
self.assertEqual(url, manifest_xml.normalize_url(url))

url = "foo.com/baf"
self.assertEqual(url, manifest_xml.normalize_url(url))

url = "[email protected]/baf/bat"
self.assertEqual(url, manifest_xml.normalize_url(url))

url = "[email protected]/baf"
self.assertEqual(url, manifest_xml.normalize_url(url))

url = "/file/path/here"
self.assertEqual(url, manifest_xml.normalize_url(url))

Expand All @@ -1168,3 +1177,30 @@ def test_has_no_scheme_matches_scp_like_syntax(self):
self.assertEqual(
"ssh://[email protected]/bar/baf", manifest_xml.normalize_url(url)
)

url = "[email protected]:bar/"
self.assertEqual(
"ssh://[email protected]/bar", manifest_xml.normalize_url(url)
)

def test_remote_url_resolution(self):
remote = manifest_xml._XmlRemote(
name="foo",
fetch="[email protected]:org2/",
manifestUrl="[email protected]:org2/custom_manifest.git",
)
self.assertEqual("ssh://[email protected]/org2", remote.resolvedFetchUrl)

remote = manifest_xml._XmlRemote(
name="foo",
fetch="ssh://[email protected]/org2/",
manifestUrl="[email protected]:org2/custom_manifest.git",
)
self.assertEqual("ssh://[email protected]/org2", remote.resolvedFetchUrl)

remote = manifest_xml._XmlRemote(
name="foo",
fetch="[email protected]:org2/",
manifestUrl="ssh://[email protected]/org2/custom_manifest.git",
)
self.assertEqual("ssh://[email protected]/org2", remote.resolvedFetchUrl)

0 comments on commit 449b23b

Please sign in to comment.