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

Delete untracked tags on fetch #4811

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ need to install Python 2.7 with virtualenv in your system as well.

.. note::

Requires Git version >=2
Requires Git version >=2.17.0

.. note::

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,
Copy link
Member

Choose a reason for hiding this comment

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

If we are deprecating Python2 we should remove these imports and also configure .isort to not add them anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

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']),
Copy link
Member Author

Choose a reason for hiding this comment

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

I just realized that I wrote this code... I should have written {'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