From c01dc3e61d60f5383995ea279d29d30490886d03 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 5 May 2020 15:55:55 -0500 Subject: [PATCH] Implement repo_exists for all VCS backends --- readthedocs/projects/tasks.py | 10 +++++----- readthedocs/vcs_support/backends/bzr.py | 7 +++++-- readthedocs/vcs_support/backends/hg.py | 7 +++++-- readthedocs/vcs_support/backends/svn.py | 11 +++++++---- readthedocs/vcs_support/base.py | 3 +++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index c15922023b9..122c730776a 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -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) + ): # 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. diff --git a/readthedocs/vcs_support/backends/bzr.py b/readthedocs/vcs_support/backends/bzr.py index b7c16c3e2e0..9fbcc8dcea3 100644 --- a/readthedocs/vcs_support/backends/bzr.py +++ b/readthedocs/vcs_support/backends/bzr.py @@ -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: diff --git a/readthedocs/vcs_support/backends/hg.py b/readthedocs/vcs_support/backends/hg.py index 0690ccfcb21..53666753904 100644 --- a/readthedocs/vcs_support/backends/hg.py +++ b/readthedocs/vcs_support/backends/hg.py @@ -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: diff --git a/readthedocs/vcs_support/backends/svn.py b/readthedocs/vcs_support/backends/svn.py index 9d460661963..03204ca1d9b 100644 --- a/readthedocs/vcs_support/backends/svn.py +++ b/readthedocs/vcs_support/backends/svn.py @@ -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: diff --git a/readthedocs/vcs_support/base.py b/readthedocs/vcs_support/base.py index dbc0018d35e..302b8ba4863 100644 --- a/readthedocs/vcs_support/base.py +++ b/readthedocs/vcs_support/base.py @@ -160,3 +160,6 @@ def update_submodules(self, config): :type config: readthedocs.config.BuildConfigBase """ raise NotImplementedError + + def repo_exists(self): + raise NotImplementedError