c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 133 forks source link

--new-version with search/replace modifies file incorrectly when current_version == new_version #260

Open christokur opened 1 year ago

christokur commented 1 year ago

bump2version --new-version 0.3.1 patch

.bumpversion.cfg:

[bumpversion]
current_version = 0.3.1

[bumpversion:file:pyproject.toml]
parse = ^version\s+=\s+['"]*(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)['"]*
search = version = "{current_version}"
replace = version = "{new_version}"

pyproject.toml BEFORE:

[tool.poetry]
name = "project"
version = "0.3.1"
...

pyproject.toml AFTER:

[tool.poetry]
name = "project"
version = "version = "0.3.1""
...

The bug is here: https://github.com/c4urself/bump2version/blob/bc95374d0dff73e610bed520846f88859815e532/bumpversion/utils.py#L121

The fix is something like this:

            file_content_after = file_content_before.replace(
                self._versionconfig.search.format(**{**context, "current_version": current_version.original}), replace_with
            )