|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 | 3 | from __future__ import (
|
4 |
| - absolute_import, division, print_function, unicode_literals) |
| 4 | + absolute_import, |
| 5 | + division, |
| 6 | + print_function, |
| 7 | + unicode_literals, |
| 8 | +) |
5 | 9 |
|
| 10 | +import os |
6 | 11 | from os.path import exists
|
| 12 | +from tempfile import mkdtemp |
7 | 13 |
|
8 | 14 | import django_dynamic_fixture as fixture
|
9 | 15 | import pytest
|
10 | 16 | from django.contrib.auth.models import User
|
11 |
| -from mock import Mock |
| 17 | +from mock import Mock, patch |
12 | 18 |
|
13 | 19 | from readthedocs.config import ALL
|
14 | 20 | from readthedocs.projects.exceptions import RepositoryError
|
15 | 21 | from readthedocs.projects.models import Feature, Project
|
16 | 22 | from readthedocs.rtd_tests.base import RTDTestCase
|
17 | 23 | 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 | +) |
19 | 31 |
|
20 | 32 |
|
21 | 33 | class TestGitBackend(RTDTestCase):
|
@@ -118,6 +130,51 @@ def test_check_invalid_submodule_urls(self):
|
118 | 130 | repo.checkout('invalidsubmodule')
|
119 | 131 | self.assertEqual(e.msg, RepositoryError.INVALID_SUBMODULES)
|
120 | 132 |
|
| 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 | + |
121 | 178 |
|
122 | 179 | class TestHgBackend(RTDTestCase):
|
123 | 180 | def setUp(self):
|
|
0 commit comments