diff options
| -rw-r--r-- | project.py | 2 | ||||
| -rw-r--r-- | tests/test_project.py | 82 |
2 files changed, 83 insertions, 1 deletions
diff --git a/project.py b/project.py index 5f2a98e18..b86367317 100644 --- a/project.py +++ b/project.py | |||
| @@ -2448,7 +2448,7 @@ class Project: | |||
| 2448 | result.extend(project.GetDerivedSubprojects()) | 2448 | result.extend(project.GetDerivedSubprojects()) |
| 2449 | continue | 2449 | continue |
| 2450 | 2450 | ||
| 2451 | if url.startswith(".."): | 2451 | if url.startswith(("./", "../")): |
| 2452 | url = urllib.parse.urljoin("%s/" % self.remote.url, url) | 2452 | url = urllib.parse.urljoin("%s/" % self.remote.url, url) |
| 2453 | remote = RemoteSpec( | 2453 | remote = RemoteSpec( |
| 2454 | self.remote.name, | 2454 | self.remote.name, |
diff --git a/tests/test_project.py b/tests/test_project.py index 728d5a54c..131dccd9f 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -127,6 +127,88 @@ class ProjectTests(unittest.TestCase): | |||
| 127 | ).strip() | 127 | ).strip() |
| 128 | self.assertEqual(expected, fakeproj.work_git.GetHead()) | 128 | self.assertEqual(expected, fakeproj.work_git.GetHead()) |
| 129 | 129 | ||
| 130 | def _get_derived_subproject_url(self, submodule_url): | ||
| 131 | with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir: | ||
| 132 | |||
| 133 | class FakeManifest: | ||
| 134 | def __init__(self, topdir): | ||
| 135 | self.topdir = topdir | ||
| 136 | self.globalConfig = None | ||
| 137 | self.is_multimanifest = False | ||
| 138 | self.path_prefix = "" | ||
| 139 | self.paths = {} | ||
| 140 | |||
| 141 | def GetSubprojectName(self, parent, path): | ||
| 142 | return path | ||
| 143 | |||
| 144 | def GetSubprojectPaths(self, parent, name, path): | ||
| 145 | relpath = path | ||
| 146 | worktree = os.path.join(self.topdir, path) | ||
| 147 | gitdir = os.path.join(self.topdir, f"{path}.git") | ||
| 148 | objdir = os.path.join(self.topdir, f"{path}.obj") | ||
| 149 | os.makedirs(worktree, exist_ok=True) | ||
| 150 | os.makedirs(gitdir, exist_ok=True) | ||
| 151 | os.makedirs(objdir, exist_ok=True) | ||
| 152 | return relpath, worktree, gitdir, objdir | ||
| 153 | |||
| 154 | manifest = FakeManifest(tempdir) | ||
| 155 | worktree = os.path.join(tempdir, "parent") | ||
| 156 | gitdir = os.path.join(tempdir, "parent.git") | ||
| 157 | objdir = os.path.join(tempdir, "parent.obj") | ||
| 158 | os.makedirs(worktree) | ||
| 159 | os.makedirs(gitdir) | ||
| 160 | os.makedirs(objdir) | ||
| 161 | |||
| 162 | parent = project.Project( | ||
| 163 | manifest=manifest, | ||
| 164 | name="parent", | ||
| 165 | remote=project.RemoteSpec( | ||
| 166 | "origin", url="https://example.com/platform/superproject" | ||
| 167 | ), | ||
| 168 | gitdir=gitdir, | ||
| 169 | objdir=objdir, | ||
| 170 | worktree=worktree, | ||
| 171 | relpath="parent", | ||
| 172 | revisionExpr="refs/heads/main", | ||
| 173 | revisionId=None, | ||
| 174 | ) | ||
| 175 | |||
| 176 | def fake_get_submodules(current): | ||
| 177 | if current is parent: | ||
| 178 | return [("subrev", "child", submodule_url, "false")] | ||
| 179 | return [] | ||
| 180 | |||
| 181 | with mock.patch.object( | ||
| 182 | project.Project, "_GetSubmodules", autospec=True | ||
| 183 | ) as get_submodules: | ||
| 184 | get_submodules.side_effect = fake_get_submodules | ||
| 185 | result = parent.GetDerivedSubprojects() | ||
| 186 | |||
| 187 | self.assertEqual(1, len(result)) | ||
| 188 | return result[0].remote.url | ||
| 189 | |||
| 190 | def test_derived_subproject_joins_only_git_relative_urls(self): | ||
| 191 | tests = ( | ||
| 192 | ( | ||
| 193 | "./submodule", | ||
| 194 | "https://example.com/platform/superproject/submodule", | ||
| 195 | ), | ||
| 196 | ("../sibling", "https://example.com/platform/sibling"), | ||
| 197 | ) | ||
| 198 | for submodule_url, expected in tests: | ||
| 199 | with self.subTest(submodule_url=submodule_url): | ||
| 200 | self.assertEqual( | ||
| 201 | expected, self._get_derived_subproject_url(submodule_url) | ||
| 202 | ) | ||
| 203 | |||
| 204 | def test_derived_subproject_leaves_dot_prefixed_names_unchanged(self): | ||
| 205 | for submodule_url in (".foo", "..bar"): | ||
| 206 | with self.subTest(submodule_url=submodule_url): | ||
| 207 | self.assertEqual( | ||
| 208 | submodule_url, | ||
| 209 | self._get_derived_subproject_url(submodule_url), | ||
| 210 | ) | ||
| 211 | |||
| 130 | 212 | ||
| 131 | class CopyLinkTestCase(unittest.TestCase): | 213 | class CopyLinkTestCase(unittest.TestCase): |
| 132 | """TestCase for stub repo client checkouts. | 214 | """TestCase for stub repo client checkouts. |
