Skip to content

Commit fbd56d2

Browse files
committed
Raise RepositoryError onf failed checkout
1 parent 5386e84 commit fbd56d2

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

readthedocs/projects/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class RepositoryError(BuildEnvironmentError):
4747
'You can not have two versions with the name latest or stable.'
4848
)
4949

50+
FAILED_TO_CHECKOUT = _(
51+
'Failed to checkout revision: {}'
52+
)
53+
5054
def get_default_message(self):
5155
if settings.ALLOW_PRIVATE_REPOS:
5256
return self.PRIVATE_ALLOWED

readthedocs/rtd_tests/tests/test_backend.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ def test_git_update_and_checkout(self):
120120
self.assertEqual(code, 0)
121121
self.assertTrue(exists(repo.working_dir))
122122

123+
def test_git_checkout_invalid_revision(self):
124+
repo = self.project.vcs_repo()
125+
repo.update()
126+
version = 'invalid-revision'
127+
with self.assertRaises(RepositoryError) as e:
128+
repo.checkout(version)
129+
self.assertEqual(
130+
str(e.exception),
131+
RepositoryError.FAILED_TO_CHECKOUT.format(version)
132+
)
133+
123134
def test_git_tags(self):
124135
repo_path = self.project.repo
125136
create_git_tag(repo_path, 'v01')

readthedocs/vcs_support/backends/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def checkout_revision(self, revision=None):
147147

148148
code, out, err = self.run('git', 'checkout', '--force', revision)
149149
if code != 0:
150-
log.warning("Failed to checkout revision '%s': %s", revision, code)
150+
raise RepositoryError(
151+
RepositoryError.FAILED_TO_CHECKOUT.format(revision)
152+
)
151153
return [code, out, err]
152154

153155
def clone(self):

0 commit comments

Comments
 (0)