Skip to content

Commit 70fee48

Browse files
authored
Merge pull request #4811 from stsewd/delete-untracked-tags-on-fetch
Delete untracked tags on fetch
2 parents adde923 + 07ad2a5 commit 70fee48

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ cache:
2323
- ~/.cache/pip
2424
- ~/.nvm/nvm.sh
2525
- ~/.npm
26+
before_install:
27+
- sudo apt-get install -y git
2628
install:
2729
- ./scripts/travis/install_elasticsearch.sh
2830
- pip install tox-travis

docs/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ since it will help you to avoid clutter in your system-wide libraries.
1313

1414
Additionally Read the Docs depends on:
1515

16-
* `Git`_ (version >=2)
16+
* `Git`_ (version >=2.17.0)
1717
* `Mercurial`_ (only if you need to work with mercurial repositories)
1818
* `Pip`_ (version >1.5)
1919
* `Redis`_

readthedocs/rtd_tests/tests/test_backend.py

+60-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
# -*- coding: utf-8 -*-
22

33
from __future__ import (
4-
absolute_import, division, print_function, unicode_literals)
4+
absolute_import,
5+
division,
6+
print_function,
7+
unicode_literals,
8+
)
59

10+
import os
611
from os.path import exists
12+
from tempfile import mkdtemp
713

814
import django_dynamic_fixture as fixture
915
import pytest
1016
from django.contrib.auth.models import User
11-
from mock import Mock
17+
from mock import Mock, patch
1218

1319
from readthedocs.config import ALL
1420
from readthedocs.projects.exceptions import RepositoryError
1521
from readthedocs.projects.models import Feature, Project
1622
from readthedocs.rtd_tests.base import RTDTestCase
1723
from readthedocs.rtd_tests.utils import (
18-
create_git_tag, make_test_git, make_test_hg)
24+
create_git_branch,
25+
create_git_tag,
26+
delete_git_branch,
27+
delete_git_tag,
28+
make_test_git,
29+
make_test_hg,
30+
)
1931

2032

2133
class TestGitBackend(RTDTestCase):
@@ -118,6 +130,51 @@ def test_check_invalid_submodule_urls(self):
118130
repo.checkout('invalidsubmodule')
119131
self.assertEqual(e.msg, RepositoryError.INVALID_SUBMODULES)
120132

133+
@patch('readthedocs.projects.models.Project.checkout_path')
134+
def test_fetch_clean_tags_and_branches(self, checkout_path):
135+
upstream_repo = self.project.repo
136+
create_git_tag(upstream_repo, 'v01')
137+
create_git_tag(upstream_repo, 'v02')
138+
create_git_branch(upstream_repo, 'newbranch')
139+
140+
local_repo = os.path.join(mkdtemp(), 'local')
141+
os.mkdir(local_repo)
142+
checkout_path.return_value = local_repo
143+
144+
repo = self.project.vcs_repo()
145+
repo.clone()
146+
147+
delete_git_tag(upstream_repo, 'v02')
148+
delete_git_branch(upstream_repo, 'newbranch')
149+
150+
# We still have all branches and tags in the local repo
151+
self.assertEqual(
152+
set(['v01', 'v02']),
153+
set(vcs.verbose_name for vcs in repo.tags)
154+
)
155+
self.assertEqual(
156+
set([
157+
'relativesubmodule', 'invalidsubmodule',
158+
'master', 'submodule', 'newbranch',
159+
]),
160+
set(vcs.verbose_name for vcs in repo.branches)
161+
)
162+
163+
repo.checkout()
164+
165+
# We don't have the eliminated branches and tags in the local repo
166+
self.assertEqual(
167+
set(['v01']),
168+
set(vcs.verbose_name for vcs in repo.tags)
169+
)
170+
self.assertEqual(
171+
set([
172+
'relativesubmodule', 'invalidsubmodule',
173+
'master', 'submodule'
174+
]),
175+
set(vcs.verbose_name for vcs in repo.branches)
176+
)
177+
121178

122179
class TestHgBackend(RTDTestCase):
123180
def setUp(self):

readthedocs/vcs_support/backends/git.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def validate_submodules(self, config):
122122
return True, submodules.keys()
123123

124124
def fetch(self):
125-
code, _, _ = self.run('git', 'fetch', '--tags', '--prune')
125+
code, _, _ = self.run(
126+
'git', 'fetch', '--tags', '--prune', '--prune-tags',
127+
)
126128
if code != 0:
127129
raise RepositoryError
128130

0 commit comments

Comments
 (0)