Skip to content

Commit

Permalink
feat: Checkout master before publishing
Browse files Browse the repository at this point in the history
Related to #39
  • Loading branch information
relekang committed Dec 22, 2015
1 parent 020efaa commit dc4077a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions semantic_release/cli.py
Expand Up @@ -10,8 +10,8 @@
from .hvcs import check_build_status, check_token, post_changelog
from .pypi import upload_to_pypi
from .settings import config
from .vcs_helpers import (commit_new_version, get_current_head_hash, get_repository_owner_and_name,
push_new_version, tag_new_version)
from .vcs_helpers import (checkout, commit_new_version, get_current_head_hash,
get_repository_owner_and_name, push_new_version, tag_new_version)


@click.command()
Expand Down Expand Up @@ -111,6 +111,7 @@ def publish(**kwargs):
owner, name = get_repository_owner_and_name()

ci_checks.check('master')
checkout('master')

if version(**kwargs):
push_new_version(
Expand Down
9 changes: 9 additions & 0 deletions semantic_release/vcs_helpers.py
Expand Up @@ -82,3 +82,12 @@ def push_new_version(gh_token=None, owner=None, name=None):
if gh_token:
message = message.replace(gh_token, '[GH_TOKEN]')
raise GitError(message)


def checkout(branch):
"""
Checkout the given branch in the local repository.
:param branch: The branch to checkout.
"""
return repo.git.checkout(branch)
2 changes: 2 additions & 0 deletions tests/test_cli.py
Expand Up @@ -165,6 +165,7 @@ def test_publish_should_do_nothing_when_version_fails(mocker, runner):

def test_publish_should_call_functions(mocker, runner):
mock_push = mocker.patch('semantic_release.cli.push_new_version')
mock_checkout = mocker.patch('semantic_release.cli.checkout')
mock_version = mocker.patch('semantic_release.cli.version', return_value=True)
mock_log = mocker.patch('semantic_release.cli.post_changelog')
mock_ci_check = mocker.patch('semantic_release.ci_checks.check')
Expand All @@ -179,6 +180,7 @@ def test_publish_should_call_functions(mocker, runner):
assert mock_pypi.called
mock_version.assert_called_once_with(noop=False, post=False, force_level=None)
mock_log.assert_called_once_with('relekang', 'python-semantic-release', '2.0.0', 'CHANGES')
mock_checkout.assert_called_once_with('master')


def test_changelog_should_call_functions(mocker, runner):
Expand Down
11 changes: 8 additions & 3 deletions tests/test_vcs_helpers.py
Expand Up @@ -2,9 +2,9 @@
from git import GitCommandError

from semantic_release.errors import GitError
from semantic_release.vcs_helpers import (commit_new_version, get_commit_log, get_current_head_hash,
get_repository_owner_and_name, push_new_version,
tag_new_version)
from semantic_release.vcs_helpers import (checkout, commit_new_version, get_commit_log,
get_current_head_hash, get_repository_owner_and_name,
push_new_version, tag_new_version)

from . import mock

Expand Down Expand Up @@ -54,3 +54,8 @@ def test_push_should_not_print_gh_token(mock_git):
with pytest.raises(GitError) as excinfo:
push_new_version(gh_token='gh--token')
assert 'gh--token' not in str(excinfo)


def test_checkout_should_checkout_correct_branch(mock_git):
checkout('a-branch')
mock_git.checkout.assert_called_once_with('a-branch')

0 comments on commit dc4077a

Please sign in to comment.