Skip to content

Implement repo_exists for all VCS backends #7025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ def sync_versions(self, version_repo):
version_post_data = {'repo': version_repo.repo_url}
tags = None
branches = None
if all([
version_repo.supports_lsremote,
not version_repo.repo_exists(),
self.project.has_feature(Feature.VCS_REMOTE_LISTING),
]):
if (
version_repo.supports_lsremote and
not version_repo.repo_exists() and
self.project.has_feature(Feature.VCS_REMOTE_LISTING)
Comment on lines +253 to +255
Copy link
Member Author

@stsewd stsewd May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to short-circuit here, so we only execute the command if supports_lsremote is true.

):
# Do not use ``ls-remote`` if the VCS does not support it or if we
# have already cloned the repository locally. The latter happens
# when triggering a normal build.
Expand Down
7 changes: 5 additions & 2 deletions readthedocs/vcs_support/backends/bzr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class Backend(BaseVCS):

def update(self):
super().update()
retcode = self.run('bzr', 'status', record=False)[0]
if retcode == 0:
if self.repo_exists():
return self.up()
return self.clone()

def repo_exists(self):
retcode = self.run('bzr', 'status', record=False)[0]
return retcode == 0

def up(self):
retcode = self.run('bzr', 'revert')[0]
if retcode != 0:
Expand Down
7 changes: 5 additions & 2 deletions readthedocs/vcs_support/backends/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class Backend(BaseVCS):

def update(self):
super().update()
retcode = self.run('hg', 'status', record=False)[0]
if retcode == 0:
if self.repo_exists():
return self.pull()
return self.clone()

def repo_exists(self):
retcode = self.run('hg', 'status', record=False)[0]
return retcode == 0

def pull(self):
(pull_retcode, _, _) = self.run('hg', 'pull')
if pull_retcode != 0:
Expand Down
11 changes: 7 additions & 4 deletions readthedocs/vcs_support/backends/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def __init__(self, *args, **kwargs):

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

def repo_exists(self):
# For some reason `svn status` gives me retcode 0 in non-svn
# directories that's why I use `svn info` here.
retcode, *_ = self.run('svn', 'info', record=False)
return retcode == 0

def up(self):
retcode = self.run('svn', 'revert', '--recursive', '.')[0]
if retcode != 0:
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/vcs_support/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ def update_submodules(self, config):
:type config: readthedocs.config.BuildConfigBase
"""
raise NotImplementedError

def repo_exists(self):
raise NotImplementedError