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

Use gitpython for tags #4052

Merged
merged 14 commits into from
May 29, 2018
15 changes: 14 additions & 1 deletion readthedocs/rtd_tests/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from readthedocs.projects.models import Project, Feature
from readthedocs.rtd_tests.base import RTDTestCase

from readthedocs.rtd_tests.utils import make_test_git, make_test_hg
from readthedocs.rtd_tests.utils import create_tag, make_test_git, make_test_hg


class TestGitBackend(RTDTestCase):
Expand Down Expand Up @@ -57,6 +57,19 @@ def test_git_checkout(self):
repo.checkout()
self.assertTrue(exists(repo.working_dir))

def test_git_tags(self):
repo_path = self.project.repo
create_tag(repo_path, 'v01')
create_tag(repo_path, 'v02', annotated=True)
create_tag(repo_path, 'release-ünîø∂é')
repo = self.project.vcs_repo()
# Hack the repo path
repo.working_dir = repo_path
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to do this here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we don't make the clone part, so the vcs object will try to search the repo in /project/checkouts/.... Sorry for the late reply, I was focused in fixin the unicode problem 😁

self.assertEqual(
set(['v01', 'v02', 'release-ünîø∂é']),
set(vcs.verbose_name for vcs in repo.tags)
)

def test_check_for_submodules(self):
repo = self.project.vcs_repo()

Expand Down
16 changes: 14 additions & 2 deletions readthedocs/rtd_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,24 @@ def make_test_git():

# Checkout to master branch again
check_output(['git', 'checkout', 'master'], env=env)

# Create some tags
chdir(path)
return directory


def create_tag(directory, tag, annotated=False):
Copy link
Member

Choose a reason for hiding this comment

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

create_git_tag maybe?

and I think that directory can be renamed to path also, to keep the same wording.

Copy link
Member Author

Choose a reason for hiding this comment

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

Directory makes reference to the tmp directory, and path is used for the cwd,

env = environ.copy()
env['GIT_DIR'] = pjoin(directory, '.git')
path = getcwd()
chdir(directory)

command = ['git', 'tag']
if annotated:
command.extend(['-a', '-m', 'Some tag'])
command.append(tag)
check_output(command, env=env)
chdir(path)


def make_test_hg():
directory = mkdtemp()
path = getcwd()
Expand Down