Skip to content
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

Add temporary method for skipping submodule checkout #3821

Merged
merged 3 commits into from
Mar 22, 2018
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
2 changes: 2 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,12 +1067,14 @@ def add_features(sender, **kwargs):
USE_SETUPTOOLS_LATEST = 'use_setuptools_latest'
ALLOW_DEPRECATED_WEBHOOKS = 'allow_deprecated_webhooks'
PIP_ALWAYS_UPGRADE = 'pip_always_upgrade'
SKIP_SUBMODULES = 'skip_submodules'

FEATURES = (
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
(USE_SETUPTOOLS_LATEST, _('Use latest version of setuptools')),
(ALLOW_DEPRECATED_WEBHOOKS, _('Allow deprecated webhook views')),
(PIP_ALWAYS_UPGRADE, _('Always run pip install --upgrade')),
(SKIP_SUBMODULES, _('Skip git submodule checkout')),
)

projects = models.ManyToManyField(
Expand Down
19 changes: 16 additions & 3 deletions readthedocs/rtd_tests/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from os.path import exists

from django.contrib.auth.models import User
import django_dynamic_fixture as fixture

from readthedocs.projects.models import Project
from readthedocs.projects.models import Project, Feature
from readthedocs.rtd_tests.base import RTDTestCase

from readthedocs.rtd_tests.utils import make_test_git, make_test_hg
Expand Down Expand Up @@ -82,11 +83,23 @@ def test_check_for_submodules(self):
repo = self.project.vcs_repo()

repo.checkout()
self.assertFalse(repo.submodules_exists())
self.assertFalse(repo.are_submodules_available())

# The submodule branch contains one submodule
repo.checkout('submodule')
self.assertTrue(repo.submodules_exists())
self.assertTrue(repo.are_submodules_available())

def test_skip_submodule_checkout(self):
repo = self.project.vcs_repo()
repo.checkout('submodule')
self.assertTrue(repo.are_submodules_available())
feature = fixture.get(
Feature,
projects=[self.project],
feature_id=Feature.SKIP_SUBMODULES,
)
self.assertTrue(self.project.has_feature(Feature.SKIP_SUBMODULES))
self.assertFalse(repo.are_submodules_available())


class TestHgBackend(RTDTestCase):
Expand Down
37 changes: 33 additions & 4 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,20 @@ def repo_exists(self):
code, _, _ = self.run('git', 'status', record=False)
return code == 0

def submodules_exists(self):
def are_submodules_available(self):
"""
Test whether git submodule checkout step should be performed.

.. note::

Temporarily, we support skipping these steps as submodule step can
fail if using private submodules. This will eventually be
configureable with our YAML config.
"""
# TODO remove with https://github.com/rtfd/readthedocs-build/issues/30
from readthedocs.projects.models import Feature
if self.project.has_feature(Feature.SKIP_SUBMODULES):
return False
code, out, _ = self.run('git', 'submodule', 'status', record=False)
return code == 0 and bool(out)

Expand All @@ -74,7 +87,22 @@ def checkout_revision(self, revision=None):
return [code, out, err]

def clone(self):
code, _, _ = self.run('git', 'clone', '--recursive', self.repo_url, '.')
"""
Clone the repository.

.. note::

Temporarily, we support skipping submodule recursive clone via a
feature flag. This will eventually be configureable with our YAML
config.
"""
# TODO remove with https://github.com/rtfd/readthedocs-build/issues/30
from readthedocs.projects.models import Feature
cmd = ['git', 'clone']
if not self.project.has_feature(Feature.SKIP_SUBMODULES):
cmd.append('--recursive')
cmd.extend([self.repo_url, '.'])
code, _, _ = self.run(*cmd)
if code != 0:
raise RepositoryError

Expand Down Expand Up @@ -199,8 +227,9 @@ def checkout(self, identifier=None):
# Clean any remains of previous checkouts
self.run('git', 'clean', '-d', '-f', '-f')

# Update submodules
if self.submodules_exists():
# Update submodules, temporarily allow for skipping submodule checkout
# step for projects need more submodule configuration.
if self.are_submodules_available():
self.run('git', 'submodule', 'sync')
self.run(
'git',
Expand Down
1 change: 1 addition & 0 deletions readthedocs/vcs_support/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BaseVCS(object):
# pylint: disable=unused-argument
def __init__(self, project, version_slug, environment=None, **kwargs):
self.default_branch = project.default_branch
self.project = project
self.name = project.name
self.repo_url = project.clean_repo
self.working_dir = project.checkout_path(version_slug)
Expand Down