Skip to content

Commit 2bbbd74

Browse files
committed
Fixed regression in config update.
Fixes #108
1 parent daa5268 commit 2bbbd74

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

bumpversion/config/files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def update_config_file(
136136
search=config.search,
137137
replace=config.replace,
138138
regex=config.regex,
139-
ignore_missing_version=config.ignore_missing_version,
139+
ignore_missing_version=True,
140140
serialize=config.serialize,
141141
parse=config.parse,
142142
)

tests/test_bump.py

+68
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the bump module."""
22
from pathlib import Path
3+
from textwrap import dedent
34
from unittest.mock import MagicMock, patch
45

56
import pytest
@@ -186,3 +187,70 @@ def test_commit_and_tag_with_config_file(mock_context):
186187
config.scm_info.tool.commit_to_scm.assert_called_once()
187188
config.scm_info.tool.tag_in_scm.assert_called_once()
188189
assert set(config.scm_info.tool.commit_to_scm.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}
190+
191+
192+
def test_key_path_required_for_toml_change(tmp_path: Path, caplog):
193+
"""If the key_path is not provided, the toml file should use standard search and replace."""
194+
from bumpversion import config
195+
from bumpversion.version_part import VersionConfig
196+
197+
# Arrange
198+
config_path = tmp_path / "pyproject.toml"
199+
config_path.write_text(
200+
dedent(
201+
"""
202+
[project]
203+
version = "0.1.26"
204+
205+
[tool.bumpversion]
206+
current_version = "0.1.26"
207+
allow_dirty = true
208+
commit = true
209+
210+
[[tool.bumpversion.files]]
211+
filename = "pyproject.toml"
212+
search = "version = \\"{current_version}\\""
213+
replace = "version = \\"{new_version}\\""
214+
"""
215+
)
216+
)
217+
218+
conf = config.get_configuration(config_file=config_path)
219+
220+
# Act
221+
from click.testing import CliRunner, Result
222+
from bumpversion import cli
223+
224+
runner: CliRunner = CliRunner()
225+
with inside_dir(tmp_path):
226+
result: Result = runner.invoke(
227+
cli.cli,
228+
["bump", "-vv", "minor"],
229+
)
230+
231+
if result.exit_code != 0:
232+
print(caplog.text)
233+
print("Here is the output:")
234+
print(result.output)
235+
import traceback
236+
237+
print(traceback.print_exception(result.exc_info[1]))
238+
239+
# Assert
240+
assert result.exit_code == 0
241+
assert config_path.read_text() == dedent(
242+
"""
243+
[project]
244+
version = "0.2.0"
245+
246+
[tool.bumpversion]
247+
current_version = "0.2.0"
248+
allow_dirty = true
249+
commit = true
250+
251+
[[tool.bumpversion.files]]
252+
filename = "pyproject.toml"
253+
search = "version = \\"{current_version}\\""
254+
replace = "version = \\"{new_version}\\""
255+
"""
256+
)

0 commit comments

Comments
 (0)