Skip to content

Commit 0493d97

Browse files
authored
Git: simplify submodule checks (#10635)
We are always querying for submodules, even when the user explicitly listed the submodules to include. We also have the option to include all submodules, instead of listing each one of them, we can just omit them, git will automatically default to include all of them. Ref #10594 (comment)
1 parent 7bbe3e2 commit 0493d97

File tree

6 files changed

+76
-158
lines changed

6 files changed

+76
-158
lines changed

readthedocs/projects/exceptions.py

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class RepositoryError(BuildUserError):
3939
"ensure that your repository URL is correct and your repository is public. "
4040
"Private repositories are not supported.",
4141
)
42-
INVALID_SUBMODULES = _(
43-
"One or more submodule URLs are not valid: {}, "
44-
"git/ssh URL schemas for submodules are not supported."
45-
)
4642
DUPLICATED_RESERVED_VERSIONS = _(
4743
"You can not have two versions with the name latest or stable."
4844
" Ensure you don't have both a branch and a tag with this name."

readthedocs/projects/tests/mockers.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,9 @@ def _mock_git_repository(self):
149149
'readthedocs.vcs_support.backends.git.Backend.submodules',
150150
new_callable=mock.PropertyMock,
151151
return_value=[
152-
mock.Mock(
153-
path='one',
154-
url='https://github.com/submodule/one',
155-
),
156-
mock.Mock(
157-
path='two',
158-
url='https://github.com/submodule/two',
159-
),
160-
mock.Mock(
161-
path='three',
162-
url='https://github.com/submodule/three',
163-
),
152+
"one",
153+
"two",
154+
"three",
164155
],
165156
)
166157

readthedocs/projects/tests/test_build_tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ def test_python_install_pip_several_options(self, load_yaml_config):
16111611
@pytest.mark.parametrize(
16121612
"value,expected",
16131613
[
1614-
(ALL, ["one", "two", "three"]),
1614+
(ALL, []),
16151615
(["one", "two"], ["one", "two"]),
16161616
],
16171617
)

readthedocs/projects/validators.py

-20
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,7 @@ def __call__(self, value):
7979
raise ValidationError(_("Invalid scheme for URL"))
8080

8181

82-
class SubmoduleURLValidator(RepositoryURLValidator):
83-
84-
"""
85-
A URL validator for repository submodules.
86-
87-
If a repository has a relative submodule, the URL path is effectively the
88-
supermodule's remote ``origin`` URL with the relative path applied.
89-
90-
From the git docs::
91-
92-
``<repository>`` is the URL of the new submodule's origin repository.
93-
This may be either an absolute URL, or (if it begins with ``./`` or
94-
``../``), the location relative to the superproject's default remote
95-
repository
96-
"""
97-
98-
disallow_relative_url = False
99-
100-
10182
validate_repository_url = RepositoryURLValidator()
102-
validate_submodule_url = SubmoduleURLValidator()
10383

10484

10585
def validate_build_config_file(path):

readthedocs/rtd_tests/tests/test_backend.py

+13-26
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,6 @@ def test_check_for_submodules(self):
181181
repo.checkout("submodule")
182182
self.assertTrue(repo.are_submodules_available(self.dummy_conf))
183183

184-
def test_check_invalid_submodule_urls(self):
185-
"""Test that a branch with an invalid submodule fails correctly."""
186-
repo = self.project.vcs_repo(
187-
environment=self.build_environment,
188-
version_type=BRANCH,
189-
version_identifier="invalidsubmodule",
190-
)
191-
repo.update()
192-
repo.checkout("invalidsubmodule")
193-
with self.assertRaises(RepositoryError) as e:
194-
repo.update_submodules(self.dummy_conf)
195-
# `invalid` is created in `make_test_git`
196-
# it's a url in ssh form.
197-
self.assertEqual(
198-
str(e.exception),
199-
RepositoryError.INVALID_SUBMODULES.format(["invalid"]),
200-
)
201-
202184
def test_check_submodule_urls(self):
203185
"""Test that a valid submodule is found in the 'submodule' branch."""
204186
repo = self.project.vcs_repo(
@@ -208,7 +190,7 @@ def test_check_submodule_urls(self):
208190
)
209191
repo.update()
210192
repo.checkout("submodule")
211-
valid, _ = repo.validate_submodules(self.dummy_conf)
193+
valid, _ = repo.get_available_submodules(self.dummy_conf)
212194
self.assertTrue(valid)
213195

214196
@patch("readthedocs.vcs_support.backends.git.Backend.fetch")
@@ -231,7 +213,7 @@ def test_git_update_with_external_version(self, fetch):
231213
repo.update()
232214
fetch.assert_called_once()
233215

234-
def test_invalid_submodule_is_ignored(self):
216+
def test_submodule_without_url_is_included(self):
235217
"""Test that an invalid submodule isn't listed."""
236218
repo = self.project.vcs_repo(
237219
environment=self.build_environment,
@@ -252,9 +234,8 @@ def test_invalid_submodule_is_ignored(self):
252234
)
253235
f.write(content)
254236

255-
valid, submodules = repo.validate_submodules(self.dummy_conf)
256-
self.assertTrue(valid)
257-
self.assertEqual(list(submodules), ["foobar"])
237+
submodules = list(repo.submodules)
238+
self.assertEqual(submodules, ["foobar", "not-valid-path"])
258239

259240
def test_parse_submodules(self):
260241
repo = self.project.vcs_repo(
@@ -296,10 +277,16 @@ def test_parse_submodules(self):
296277
)
297278
f.write(content)
298279

299-
valid, submodules = repo.validate_submodules(self.dummy_conf)
300-
self.assertTrue(valid)
280+
submodules = list(repo.submodules)
301281
self.assertEqual(
302-
list(submodules), ["foobar", "path with spaces", "another-submodule"]
282+
submodules,
283+
[
284+
"foobar",
285+
"not-valid-path",
286+
"path with spaces",
287+
"another-submodule",
288+
"invalid-submodule-key",
289+
],
303290
)
304291

305292
def test_skip_submodule_checkout(self):

0 commit comments

Comments
 (0)