From 693e804a9eb0017740a1a1112d4e03bdba96c519 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 21 Aug 2022 19:55:14 -0700 Subject: [PATCH 1/2] fix(bump): Support regexes containing colons The version_files feature uses a colon to delimit filenames from a regex to use to find the version. Make version_files slightly more robust by splitting on the first colon rather than all colons, thereby permitting the regex to contain a colon. Maintain the pre-existing assumption that the filename doesn't contain a colon, as this is rare and would likely cause many other problems. --- commitizen/bump.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index 701b7d662..2314b8d0e 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -141,8 +141,7 @@ def update_version_in_files( """ # TODO: separate check step and write step for location in files: - filepath, *regexes = location.split(":") - regex = regexes[0] if regexes else None + filepath, _, regex = location.partition(":") with open(filepath, "r") as f: version_file = f.read() From f093717e93d090cfd1b0085541f9770fd46a1f6b Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Sun, 21 Aug 2022 20:09:43 -0700 Subject: [PATCH 2/2] ci(pre-commit): Include : in version_files regex Commitizen runs bump on itself to, among other things, manage the version it uses of its own pre-commit hooks. When searching .pre-commit-config.yaml for the version number of Commitizen, look for "rev:" rather than "rev" to reduce the likelihood of a false positive now that colons are permitted in version_files regexes. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 78f9cb170..68e79b072 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ tag_format = "v$version" version_files = [ "pyproject.toml:version", "commitizen/__version__.py", - ".pre-commit-config.yaml:rev.\\s+(?=[^\\n]+Commitizen)" + ".pre-commit-config.yaml:rev:.\\s+(?=[^\\n]+Commitizen)" ] [tool.black]