Skip to content

Commit 64b0de3

Browse files
committed
Fixes issue when new version equals current version
- Now it reports they are the same and exits.
1 parent c025650 commit 64b0de3

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ commits and tags:
4141
**Potential bugs to verify**
4242

4343
- https://github.com/c4urself/bump2version/issues/267 Ignore-missing error in files flag
44-
- https://github.com/c4urself/bump2version/issues/260 Incorrect behavior when new version == current version
44+
- Fixed: https://github.com/c4urself/bump2version/issues/260 Incorrect behavior when new version == current version
4545
- https://github.com/c4urself/bump2version/issues/248 Potential bug/test case
4646
- https://github.com/c4urself/bump2version/issues/246 Release inconsistency
4747
- https://github.com/c4urself/bump2version/issues/233 How are relative configured file paths resolved?

bumpversion/bump.py

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def do_bump(
7070
next_version_str = config.version_config.serialize(next_version, ctx)
7171
logger.info("New version will be '%s'", next_version_str)
7272

73+
if config.current_version == next_version_str:
74+
logger.info("Version is already '%s'", next_version_str)
75+
return
76+
7377
if dry_run:
7478
logger.info("Dry run active, won't touch any files.")
7579

tests/test_bump.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from bumpversion.exceptions import ConfigurationError
99
from bumpversion.files import ConfiguredFile
1010
from bumpversion.scm import Git, SCMInfo
11-
from tests.conftest import get_config_data
11+
from tests.conftest import get_config_data, inside_dir
1212

1313

1414
@pytest.fixture
@@ -116,15 +116,30 @@ def test_do_bump_with_new_version(mock_update_config_file, mock_modify_files):
116116
assert mock_update_config_file.call_args[0][3] is True
117117

118118

119+
@patch("bumpversion.files.modify_files")
120+
@patch("bumpversion.bump.update_config_file")
121+
def test_do_bump_when_new_equals_current(mock_update_config_file, mock_modify_files, tmp_path: Path):
122+
"""When the new version is the same as the current version, nothing should happen."""
123+
124+
# Arrange
125+
version_part = None
126+
new_version = "1.2.3"
127+
128+
with inside_dir(tmp_path):
129+
config, version_config, current_version = get_config_data({"current_version": "1.2.3"})
130+
# Act
131+
bump.do_bump(version_part, new_version, config)
132+
133+
# Assert
134+
mock_modify_files.assert_not_called()
135+
mock_update_config_file.assert_not_called()
136+
137+
119138
def test_do_bump_with_no_arguments():
120139
# Arrange
121140
version_part = None
122141
new_version = None
123-
config, version_config, current_version = get_config_data(
124-
{
125-
"current_version": "1.2.3",
126-
}
127-
)
142+
config, version_config, current_version = get_config_data({"current_version": "1.2.3"})
128143
config.scm_info = SCMInfo()
129144
dry_run = False
130145

0 commit comments

Comments
 (0)