From 3ecbe83dc63aeb688c3f052df68f5f63918e9f7e Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Fri, 6 Jun 2025 01:50:14 +0800 Subject: [PATCH] refactor(git): retype get_commits parameter to make it more friendly to call sites --- commitizen/commands/bump.py | 5 +---- commitizen/commands/check.py | 2 +- commitizen/git.py | 7 +++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index a4024eee3..c9e5dfc3e 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -253,10 +253,7 @@ def __call__(self) -> None: ) from exc else: if increment is None: - if current_tag: - commits = git.get_commits(current_tag.name) - else: - commits = git.get_commits() + commits = git.get_commits(current_tag.name if current_tag else None) # No commits, there is no need to create an empty tag. # Unless we previously had a prerelease. diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 8a7d0dd01..ba003cf3c 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -110,7 +110,7 @@ def _get_commits(self) -> list[git.GitCommit]: return [git.GitCommit(rev="", title="", body=self._filter_comments(msg))] # Get commit messages from git log (--rev-range) - return git.get_commits(end=self.rev_range or "HEAD") + return git.get_commits(end=self.rev_range) @staticmethod def _filter_comments(msg: str) -> str: diff --git a/commitizen/git.py b/commitizen/git.py index fb59750ea..4b855297b 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -203,15 +203,18 @@ def _create_commit_cmd_string(args: str, committer_date: str | None, name: str) def get_commits( start: str | None = None, - end: str = "HEAD", + end: str | None = None, *, args: str = "", ) -> list[GitCommit]: """Get the commits between start and end.""" + if end is None: + end = "HEAD" git_log_entries = _get_log_as_str_list(start, end, args) return [ GitCommit.from_rev_and_commit(rev_and_commit) - for rev_and_commit in filter(None, git_log_entries) + for rev_and_commit in git_log_entries + if rev_and_commit ]