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 disabling shallow cloning (#5031) #5036

Merged
merged 1 commit into from
Dec 26, 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
5 changes: 4 additions & 1 deletion readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ def add_features(sender, **kwargs):
DONT_OVERWRITE_SPHINX_CONTEXT = 'dont_overwrite_sphinx_context'
ALLOW_V2_CONFIG_FILE = 'allow_v2_config_file'
MKDOCS_THEME_RTD = 'mkdocs_theme_rtd'
DONT_SHALLOW_CLONE = 'dont_shallow_clone'

FEATURES = (
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
Expand All @@ -1021,10 +1022,12 @@ def add_features(sender, **kwargs):
(PIP_ALWAYS_UPGRADE, _('Always run pip install --upgrade')),
(SKIP_SUBMODULES, _('Skip git submodule checkout')),
(DONT_OVERWRITE_SPHINX_CONTEXT, _(
'Do not overwrite context vars in conf.py with Read the Docs context',)),
'Do not overwrite context vars in conf.py with Read the Docs context')),
(ALLOW_V2_CONFIG_FILE, _(
'Allow to use the v2 of the configuration file')),
(MKDOCS_THEME_RTD, _('Use Read the Docs theme for MkDocs as default theme')),
(DONT_SHALLOW_CLONE, _(
'Do not shallow clone when cloning git repos')),
)

projects = models.ManyToManyField(
Expand Down
15 changes: 14 additions & 1 deletion readthedocs/rtd_tests/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,27 @@ def test_skip_submodule_checkout(self):
repo.update()
repo.checkout('submodule')
self.assertTrue(repo.are_submodules_available(self.dummy_conf))
feature = fixture.get(
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(self.dummy_conf))

def test_use_shallow_clone(self):
repo = self.project.vcs_repo()
repo.update()
repo.checkout('submodule')
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good to call .clone (mocked) here and check what were the arguments used to call it. That way, we are sure that we are using use_shallow_clone and it does have an effect in the flow.

self.assertTrue(repo.use_shallow_clone())
fixture.get(
Feature,
projects=[self.project],
feature_id=Feature.DONT_SHALLOW_CLONE,
)
self.assertTrue(self.project.has_feature(Feature.DONT_SHALLOW_CLONE))
self.assertFalse(repo.use_shallow_clone())

def test_check_submodule_urls(self):
repo = self.project.vcs_repo()
repo.update()
Expand Down
35 changes: 27 additions & 8 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,26 @@ def validate_submodules(self, config):
return False, []
return True, submodules.keys()

def use_shallow_clone(self):
"""
Test whether shallow clone should be performed.

.. note::

Temporarily, we support skipping this option as builds that rely on
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can remove this note if we go for using a feature flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was to include this for now so we can unblock the broken builds then decide at a later date whether we wanted to expose this to users. If we don't, we remove the note. If we do, we remove all of this code.

git history can fail if using shallow clones. This should
eventually be configurable via the web UI.
"""
from readthedocs.projects.models import Feature
return not self.project.has_feature(Feature.DONT_SHALLOW_CLONE)

def fetch(self):
code, stdout, stderr = self.run(
'git', 'fetch', '--depth', str(self.repo_depth),
'--tags', '--prune', '--prune-tags',
)
cmd = ['git', 'fetch', '--tags', '--prune', '--prune-tags']

if self.use_shallow_clone():
cmd.extend(['--depth', str(self.repo_depth)])

code, stdout, stderr = self.run(*cmd)
if code != 0:
raise RepositoryError
return code, stdout, stderr
Expand All @@ -152,10 +167,14 @@ def checkout_revision(self, revision=None):

def clone(self):
"""Clones the repository."""
code, stdout, stderr = self.run(
'git', 'clone', '--depth', str(self.repo_depth),
'--no-single-branch', self.repo_url, '.'
)
cmd = ['git', 'clone', '--no-single-branch']

if self.use_shallow_clone():
cmd.extend(['--depth', str(self.repo_depth)])

cmd.extend([self.repo_url, '.'])

code, stdout, stderr = self.run(*cmd)
if code != 0:
raise RepositoryError
return code, stdout, stderr
Expand Down