bump2version icon indicating copy to clipboard operation
bump2version copied to clipboard

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

Open christokur opened this issue 3 years ago • 0 comments

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
            )

christokur avatar Oct 21 '22 16:10 christokur