Skip to content

Commit

Permalink
fix: fix getting current version when version_source=tag_only (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafcio19 committed Apr 13, 2022
1 parent 7bffd66 commit b247936
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion semantic_release/history/__init__.py
Expand Up @@ -228,7 +228,7 @@ def get_current_version(prerelease_version: bool = False) -> str:
:return: A string with the current version number
"""
omit_pattern = None if prerelease_version else get_prerelease_pattern()
if config.get("version_source") == "tag":
if config.get("version_source") in ["tag", "tag_only"]:
return get_current_version_by_tag(omit_pattern)
current_version = get_current_version_by_config_file(omit_pattern)
if omit_pattern and omit_pattern in current_version:
Expand Down
18 changes: 18 additions & 0 deletions tests/history/test_version.py
Expand Up @@ -16,6 +16,7 @@
get_previous_version,
load_version_declarations,
set_new_version,
get_current_version_by_config_file,
)

from .. import wrapped_config_get
Expand Down Expand Up @@ -50,6 +51,23 @@ def test_current_version_should_return_default_version(mock_last_version):
assert "0.0.0" == get_current_version()


@mock.patch(
"semantic_release.history.config.get", wrapped_config_get(version_source="tag_only")
)
def test_current_version_should_run_with_tag_only(mocker):
mock_get_current_version_by_tag = mocker.patch(
"semantic_release.history.get_current_version_by_tag", return_value=None
)
mock_get_current_version_by_config_file = mocker.patch(
"semantic_release.history.get_current_version_by_config_file", return_value=None
)

get_current_version()

assert mock_get_current_version_by_tag.called
assert not mock_get_current_version_by_config_file.called


class TestGetPreviousVersion:
@mock.patch(
"semantic_release.history.get_commit_log",
Expand Down

0 comments on commit b247936

Please sign in to comment.