From c245b14c834818b0a434aac6e45fc298cbb93222 Mon Sep 17 00:00:00 2001 From: Chad Dombrova Date: Mon, 5 Feb 2024 14:29:32 -0800 Subject: [PATCH] fix(bump): only get and validate commits if increment is not provided This avoids calls to git and additional validations that are not necessary when using --increment --- commitizen/commands/bump.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 435c0039f9..f30f1c0e94 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -209,21 +209,10 @@ def __call__(self) -> None: # noqa: C901 scheme=self.scheme, ) - is_initial = self.is_initial_tag(current_tag_version, is_yes) - if is_initial: - commits = git.get_commits() - else: - commits = git.get_commits(current_tag_version) - # If user specified changelog_to_stdout, they probably want the # changelog to be generated as well, this is the most intuitive solution self.changelog = self.changelog or bool(self.changelog_to_stdout) - # No commits, there is no need to create an empty tag. - # Unless we previously had a prerelease. - if not commits and not current_version.is_prerelease: - raise NoCommitsFoundError("[NO_COMMITS_FOUND]\n" "No new commits found.") - if manual_version: try: new_version = self.scheme(manual_version) @@ -234,6 +223,19 @@ def __call__(self) -> None: # noqa: C901 ) from exc else: if increment is None: + is_initial = self.is_initial_tag(current_tag_version, is_yes) + if is_initial: + commits = git.get_commits() + else: + commits = git.get_commits(current_tag_version) + + # No commits, there is no need to create an empty tag. + # Unless we previously had a prerelease. + if not commits and not current_version.is_prerelease: + raise NoCommitsFoundError( + "[NO_COMMITS_FOUND]\n" "No new commits found." + ) + increment = self.find_increment(commits) # It may happen that there are commits, but they are not eligible