-
-
Notifications
You must be signed in to change notification settings - Fork 316
Description
Description
The update_version_in_files function in commitizen/bump.py replaces all occurrences of the version string in lines that match the pattern, not just the project version. This incorrectly updates dependency version constraints that happen to contain the same version string.
When version_files = ["pyproject.toml"] is used without a custom pattern, the default pattern matches any line containing the version string. The function then uses line.replace() which replaces all occurrences, causing dependency versions like "langgraph-checkpoint-postgres>=3.0.1" to be incorrectly changed to ">=4.0.0".
Steps to reproduce
[project]
version = "3.0.1"
dependencies = [
"langgraph-checkpoint-postgres>=3.0.1",
]
[tool.commitizen]
version_files = ["pyproject.toml"]
version = "3.0.1"
Run cz bump to bump the version (e.g., from 3.0.1 to 4.0.0)
Observe that both the project version AND the dependency version constraint are updated
Current behavior
When bumping from 3.0.1 to 4.0.0, the function incorrectly updates:
version = "3.0.1" → version = "4.0.0" (correct)
"langgraph-checkpoint-postgres>=3.0.1" → "langgraph-checkpoint-postgres>=4.0.0" (incorrect)
This happens because:
The default pattern re.escape(version) matches any line containing the version string
line.replace(current_version, new_version) replaces ALL occurrences in matching lines
Dependency constraints containing the same version string get incorrectly updated
Desired behavior
nly the project version should be updated. Dependency version constraints should remain unchanged, even if they contain the same version string.
Expected result after bumping from 3.0.1 to 4.0.0:
version = "3.0.1" → version = "4.0.0"
"langgraph-checkpoint-postgres>=3.0.1" → "langgraph-checkpoint-postgres>=3.0.1" (unchanged)
The fix should use regex substitution to only replace the version in the context where it should be updated (e.g., in version assignment statements), not all occurrences in matching lines.
Screenshots
No response
Environment
Commitizen Version: 4.10.0
Python Version: 3.12.12 (main, Oct 14 2025, 21:38:21) [Clang 20.1.4 ]
Operating System: Darwin