Skip to content

Commit

Permalink
Merge pull request readthedocs#4811 from stsewd/delete-untracked-tags…
Browse files Browse the repository at this point in the history
…-on-fetch

Delete untracked tags on fetch
  • Loading branch information
ericholscher authored Nov 1, 2018
2 parents adde923 + 07ad2a5 commit 70fee48
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
Expand Down
63 changes: 60 additions & 3 deletions readthedocs/rtd_tests/tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 70fee48

Please sign in to comment.