diff --git a/commitizen/bump.py b/commitizen/bump.py index cb572d361..54b54b083 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -23,7 +23,11 @@ def find_increment( - commits: list[GitCommit], regex: str, increments_map: dict | OrderedDict + commits: list[GitCommit], + regex: str, + increments_map: dict | OrderedDict, + ignore_bump_rev_list: list[str] | None = None, + ignore_bump_author_list: list[str] | None = None, ) -> Increment | None: if isinstance(increments_map, dict): increments_map = OrderedDict(increments_map) @@ -34,6 +38,18 @@ def find_increment( increment: str | None = None for commit in commits: + if ignore_bump_rev_list and commit.rev in ignore_bump_rev_list: + logger.debug( + f"Skipping commit {commit.rev} as it's in ignore_bump_rev_list" + ) + continue + + if ignore_bump_author_list and commit.author in ignore_bump_author_list: + logger.debug( + f"Skipping commit {commit.rev} as its author '{commit.author}' is in ignore_bump_author_list" + ) + continue + for message in commit.message.split("\n"): result = select_pattern.search(message) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 6084c8c15..c35b1be4a 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -104,6 +104,10 @@ def __init__(self, config: BaseConfig, arguments: BumpArgs) -> None: self.retry = arguments["retry"] self.pre_bump_hooks = self.config.settings["pre_bump_hooks"] self.post_bump_hooks = self.config.settings["post_bump_hooks"] + self.ignore_bump_rev_list = self.config.settings.get("ignore_bump_rev_list") + self.ignore_bump_author_list = self.config.settings.get( + "ignore_bump_author_list" + ) deprecated_version_type = arguments.get("version_type") if deprecated_version_type: warnings.warn( @@ -158,7 +162,13 @@ def _find_increment(self, commits: list[git.GitCommit]) -> Increment | None: raise NoPatternMapError( f"'{self.config.settings['name']}' rule does not support bump" ) - return bump.find_increment(commits, regex=bump_pattern, increments_map=bump_map) + return bump.find_increment( + commits, + regex=bump_pattern, + increments_map=bump_map, + ignore_bump_rev_list=self.ignore_bump_rev_list, + ignore_bump_author_list=self.ignore_bump_author_list, + ) def _validate_arguments(self, current_version: VersionProtocol) -> None: errors: list[str] = [] @@ -363,7 +373,9 @@ def __call__(self) -> None: new_tag_version=new_tag_version, message=message, increment=increment, - changelog_file_name=changelog_file_name, + changelog_file_name=( + changelog_cmd.file_name if self.changelog_flag else None + ), ) if self.arguments.get("files_only"): @@ -426,7 +438,9 @@ def __call__(self) -> None: current_tag_version=new_tag_version, message=message, increment=increment, - changelog_file_name=changelog_file_name, + changelog_file_name=( + changelog_cmd.file_name if self.changelog_flag else None + ), ) # TODO: For v3 output this only as diagnostic and remove this if diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 4865ccc18..703fbd9ff 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -65,6 +65,8 @@ class Settings(TypedDict, total=False): version_type: str | None version: str | None breaking_change_exclamation_in_title: bool + ignore_bump_rev_list: list[str] | None + ignore_bump_author_list: list[str] | None CONFIG_FILES: tuple[str, ...] = ( diff --git a/docs/config/bump.md b/docs/config/bump.md index 10ca5bcf8..403e232a1 100644 --- a/docs/config/bump.md +++ b/docs/config/bump.md @@ -215,3 +215,57 @@ version_files = [ ## `version_scheme` See [`--version-scheme`](../commands/bump.md#-version-scheme). + +Here’s a clearer, more consistent rewrite with tightened wording, corrected descriptions, and parallel structure between the two options. + +## `ignore_bump_rev_list` + +- Type: `list` +- Default: `[]` + +A list of git commit revisions (SHAs) that should be excluded from version bump calculation. + +For example, given the following commit: + +```text +commit e302cb4f2c626099b4a9c8cf881b0bb5906b7356 +Author: example_user +Date: Sat Feb 1 21:00:00 2026 +0800 + + feat: add a new test file, this should not be bumped +``` + +Configure `pyproject.toml` as follows: + +```toml title="pyproject.toml" +[tool.commitizen] +ignore_bump_rev_list = ["e302cb4f2c626099b4a9c8cf881b0bb5906b7356"] +``` + +As a result, this commit will be ignored when determining whether a version bump is required. + +## `ignore_bump_author_list` + +- Type: `list` +- Default: `[]` + +A list of commit authors whose commits should be excluded from version bump calculation. + +For example, given the following commit: + +```text +commit e302cb4f2c626099b4a9c8cf881b0bb5906b7356 +Author: example_user +Date: Sat Feb 1 21:00:00 2026 +0800 + + feat: add a new test file, this should not be bumped +``` + +Configure `pyproject.toml` as follows: + +```toml title="pyproject.toml" +[tool.commitizen] +ignore_bump_author_list = ["example_user"] +``` + +As a result, any commit authored by `example_user` will be ignored when determining whether a version bump is required. diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 8209278ed..811fb433a 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -108,6 +108,42 @@ def test_find_increment(messages, expected_type): assert increment_type == expected_type +def test_find_increment_with_ignored_rev(): + messages = [ + "docs(README): motivation", + "feat: this should not be bumped because of the ignore_bump_rev_list", + ] + commits = [ + GitCommit(rev="test1", title=messages[0]), + GitCommit(rev="test2", title=messages[1]), + ] + increment_type = bump.find_increment( + commits, + regex=ConventionalCommitsCz.bump_pattern, + increments_map=ConventionalCommitsCz.bump_map, + ignore_bump_rev_list=["test2"], + ) + assert increment_type is None + + +def test_find_increment_with_ignored_author(): + messages = [ + "feat: this should not be bumped because of the ignore_bump_author_list", + "docs(README): motivation", + ] + commits = [ + GitCommit(rev="test1", title=messages[0], author="alice"), + GitCommit(rev="test2", title=messages[1], author="bob"), + ] + increment_type = bump.find_increment( + commits, + regex=ConventionalCommitsCz.bump_pattern, + increments_map=ConventionalCommitsCz.bump_map, + ignore_bump_author_list=["alice"], + ) + assert increment_type is None + + @pytest.mark.parametrize( ("messages", "expected_type"), [