forked from GerritCodeReview/git-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manifest_xml: fix url normalization for inits and remotes
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
1 parent
e5fb6e5
commit 449b23b
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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)) | ||
|
||
|
@@ -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) |