diff --git a/.travis.yml b/.travis.yml index 7eff80a97e4..6f4bdf452ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,8 @@ cache: - ~/.cache/pip - ~/.nvm/nvm.sh - ~/.npm +before_install: + - sudo apt-get install -y git install: - ./scripts/travis/install_elasticsearch.sh - pip install tox-travis diff --git a/docs/install.rst b/docs/install.rst index 4d6f85d625b..d7234bf9283 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -13,7 +13,7 @@ since it will help you to avoid clutter in your system-wide libraries. Additionally Read the Docs depends on: -* `Git`_ (version >=2) +* `Git`_ (version >=2.17.0) * `Mercurial`_ (only if you need to work with mercurial repositories) * `Pip`_ (version >1.5) * `Redis`_ diff --git a/readthedocs/rtd_tests/tests/test_backend.py b/readthedocs/rtd_tests/tests/test_backend.py index 3acae2d2036..239c2dc8f57 100644 --- a/readthedocs/rtd_tests/tests/test_backend.py +++ b/readthedocs/rtd_tests/tests/test_backend.py @@ -1,21 +1,33 @@ # -*- coding: utf-8 -*- from __future__ import ( - absolute_import, division, print_function, unicode_literals) + absolute_import, + division, + print_function, + unicode_literals, +) +import os from os.path import exists +from tempfile import mkdtemp import django_dynamic_fixture as fixture import pytest from django.contrib.auth.models import User -from mock import Mock +from mock import Mock, patch from readthedocs.config import ALL from readthedocs.projects.exceptions import RepositoryError from readthedocs.projects.models import Feature, Project from readthedocs.rtd_tests.base import RTDTestCase from readthedocs.rtd_tests.utils import ( - create_git_tag, make_test_git, make_test_hg) + create_git_branch, + create_git_tag, + delete_git_branch, + delete_git_tag, + make_test_git, + make_test_hg, +) class TestGitBackend(RTDTestCase): @@ -118,6 +130,51 @@ def test_check_invalid_submodule_urls(self): repo.checkout('invalidsubmodule') self.assertEqual(e.msg, RepositoryError.INVALID_SUBMODULES) + @patch('readthedocs.projects.models.Project.checkout_path') + def test_fetch_clean_tags_and_branches(self, checkout_path): + upstream_repo = self.project.repo + create_git_tag(upstream_repo, 'v01') + create_git_tag(upstream_repo, 'v02') + create_git_branch(upstream_repo, 'newbranch') + + local_repo = os.path.join(mkdtemp(), 'local') + os.mkdir(local_repo) + checkout_path.return_value = local_repo + + repo = self.project.vcs_repo() + repo.clone() + + delete_git_tag(upstream_repo, 'v02') + delete_git_branch(upstream_repo, 'newbranch') + + # We still have all branches and tags in the local repo + self.assertEqual( + set(['v01', 'v02']), + set(vcs.verbose_name for vcs in repo.tags) + ) + self.assertEqual( + set([ + 'relativesubmodule', 'invalidsubmodule', + 'master', 'submodule', 'newbranch', + ]), + set(vcs.verbose_name for vcs in repo.branches) + ) + + repo.checkout() + + # We don't have the eliminated branches and tags in the local repo + self.assertEqual( + set(['v01']), + set(vcs.verbose_name for vcs in repo.tags) + ) + self.assertEqual( + set([ + 'relativesubmodule', 'invalidsubmodule', + 'master', 'submodule' + ]), + set(vcs.verbose_name for vcs in repo.branches) + ) + class TestHgBackend(RTDTestCase): def setUp(self): diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index 9b117799fb3..2959add5493 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -122,7 +122,9 @@ def validate_submodules(self, config): return True, submodules.keys() def fetch(self): - code, _, _ = self.run('git', 'fetch', '--tags', '--prune') + code, _, _ = self.run( + 'git', 'fetch', '--tags', '--prune', '--prune-tags', + ) if code != 0: raise RepositoryError