Skip to content

Commit 47286d7

Browse files
authored
Merge pull request #7025 from readthedocs/implement-repo-exists
Implement repo_exists for all VCS backends
2 parents 1f1357d + c01dc3e commit 47286d7

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

readthedocs/projects/tasks.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ def sync_versions(self, version_repo):
249249
version_post_data = {'repo': version_repo.repo_url}
250250
tags = None
251251
branches = None
252-
if all([
253-
version_repo.supports_lsremote,
254-
not version_repo.repo_exists(),
255-
self.project.has_feature(Feature.VCS_REMOTE_LISTING),
256-
]):
252+
if (
253+
version_repo.supports_lsremote and
254+
not version_repo.repo_exists() and
255+
self.project.has_feature(Feature.VCS_REMOTE_LISTING)
256+
):
257257
# Do not use ``ls-remote`` if the VCS does not support it or if we
258258
# have already cloned the repository locally. The latter happens
259259
# when triggering a normal build.

readthedocs/vcs_support/backends/bzr.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ class Backend(BaseVCS):
1919

2020
def update(self):
2121
super().update()
22-
retcode = self.run('bzr', 'status', record=False)[0]
23-
if retcode == 0:
22+
if self.repo_exists():
2423
return self.up()
2524
return self.clone()
2625

26+
def repo_exists(self):
27+
retcode = self.run('bzr', 'status', record=False)[0]
28+
return retcode == 0
29+
2730
def up(self):
2831
retcode = self.run('bzr', 'revert')[0]
2932
if retcode != 0:

readthedocs/vcs_support/backends/hg.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ class Backend(BaseVCS):
1515

1616
def update(self):
1717
super().update()
18-
retcode = self.run('hg', 'status', record=False)[0]
19-
if retcode == 0:
18+
if self.repo_exists():
2019
return self.pull()
2120
return self.clone()
2221

22+
def repo_exists(self):
23+
retcode = self.run('hg', 'status', record=False)[0]
24+
return retcode == 0
25+
2326
def pull(self):
2427
(pull_retcode, _, _) = self.run('hg', 'pull')
2528
if pull_retcode != 0:

readthedocs/vcs_support/backends/svn.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ def __init__(self, *args, **kwargs):
2929

3030
def update(self):
3131
super().update()
32-
# For some reason `svn status` gives me retcode 0 in non-svn
33-
# directories that's why I use `svn info` here.
34-
retcode, _, _ = self.run('svn', 'info', record=False)
35-
if retcode == 0:
32+
if self.repo_exists():
3633
return self.up()
3734
return self.co()
3835

36+
def repo_exists(self):
37+
# For some reason `svn status` gives me retcode 0 in non-svn
38+
# directories that's why I use `svn info` here.
39+
retcode, *_ = self.run('svn', 'info', record=False)
40+
return retcode == 0
41+
3942
def up(self):
4043
retcode = self.run('svn', 'revert', '--recursive', '.')[0]
4144
if retcode != 0:

readthedocs/vcs_support/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,6 @@ def update_submodules(self, config):
160160
:type config: readthedocs.config.BuildConfigBase
161161
"""
162162
raise NotImplementedError
163+
164+
def repo_exists(self):
165+
raise NotImplementedError

0 commit comments

Comments
 (0)