Skip to content

Commit 538e291

Browse files
committed
Better msg when gitpython fails
Currently we show a generic message. Related: readthedocs#4371 This can be removed when gitpython-developers/GitPython#818 gets merged.
1 parent e574168 commit 538e291

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

readthedocs/projects/exceptions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class RepositoryError(BuildEnvironmentError):
3838
'Private repositories are not supported.',
3939
)
4040

41-
INVALID_SUBMODULES = _('One or more submodule URLs are not valid: {}.',)
41+
INVALID_SUBMODULES = _('One or more submodule URLs are not valid: {}.')
42+
INVALID_SUBMODULES_PATH = _(
43+
'One or more submodule paths are not valid. '
44+
'Check that all your submodules in .gitmodules are used.'
45+
)
4246

4347
DUPLICATED_RESERVED_VERSIONS = _(
4448
'You can not have two versions with the name latest or stable.',

readthedocs/rtd_tests/tests/test_backend.py

+15
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ def test_check_invalid_submodule_urls(self):
189189
RepositoryError.INVALID_SUBMODULES.format(['invalid']),
190190
)
191191

192+
def test_invalid_submodule_path(self):
193+
repo_path = self.project.repo
194+
gitmodules_path = os.path.join(repo_path, '.gitmodules')
195+
196+
with open(gitmodules_path, 'w+') as f:
197+
content = textwrap.dedent("""
198+
[submodule "not-valid-path"]
199+
path = not-valid-path
200+
url = https://github.com/readthedocs/readthedocs.org
201+
""")
202+
f.write(content)
203+
204+
with self.assertRaises(RepositoryError, msg=RepositoryError.INVALID_SUBMODULES_PATH):
205+
repo.update_submodules(self.dummy_conf)
206+
192207
@patch('readthedocs.projects.models.Project.checkout_path')
193208
def test_fetch_clean_tags_and_branches(self, checkout_path):
194209
upstream_repo = self.project.repo

readthedocs/vcs_support/backends/git.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ def validate_submodules(self, config):
105105
Returns the list of invalid submodules.
106106
"""
107107
repo = git.Repo(self.working_dir)
108-
submodules = {sub.path: sub for sub in repo.submodules}
108+
try:
109+
submodules = {sub.path: sub for sub in repo.submodules}
110+
except InvalidGitRepositoryError:
111+
raise RepositoryError(
112+
RepositoryError.INVALID_SUBMODULES_PATH,
113+
)
109114

110115
for sub_path in config.submodules.exclude:
111116
path = sub_path.rstrip('/')

0 commit comments

Comments
 (0)