Skip to content

fix(bump): evaluate increment regexes against the commit subject only - #1605

Open
YuriNachos wants to merge 2 commits into
orhun:mainfrom
YuriNachos:fix/bump-custom-regex-subject
Open

fix(bump): evaluate increment regexes against the commit subject only#1605
YuriNachos wants to merge 2 commits into
orhun:mainfrom
YuriNachos:fix/bump-custom-regex-subject

Conversation

@YuriNachos

Copy link
Copy Markdown

Description

When conventional_commits is disabled, calculate_next_version_with_config forwarded each commit's full raw message (subject + body) to next_version::VersionUpdater::increment. The next_version crate applies custom_major_increment_regex, custom_minor_increment_regex and no_increment_regex against the whole string for any commit that does not parse as conventional, so a commit whose body happens to contain the configured token drove a wrong version bump.

Concrete case from #1476: with conventional_commits = false and custom_major_increment_regex = "breaking", a commit fix: real bug\n\nnotes: breaking change discussed bumps to a major release (the body word "breaking" matches) instead of a patch release.

This PR threads the conventional_commits flag into the bump calculation. When conventional commits are disabled, only the commit subject (first line) is handed to the version calculator, so body text can no longer trigger an increment. The conventional path is untouched — the full message is still passed when conventional_commits = true, so BREAKING CHANGE: footer detection and !-flag handling behave exactly as before.

The change reuses the existing calculate_next_version_with_config entry point (now a thin delegate that passes conventional_commits = true, preserving every existing caller/test) and moves the real work into calculate_next_version_from_commits(config, conventional_commits), which Changelog::bump_version calls with self.config.git.conventional_commits.

Motivation and Context

A body-driven major/minor bump is a silent, severe defect in a release tool: the resulting version is plausible enough to ship before anyone notices. This fixes the root cause described in #1476.

Note: the ^-anchored reproducer from the original report no longer reproduces on main (it resolves through conventional-commit type matching), but the unanchored — and far more common — form of the bug remains, and this addresses the same root cause for both.

Closes #1476

How Has This Been Tested?

  • New unit test release::test::custom_increment_regex_matches_subject_only_when_non_conventional: a commit whose subject matches no regex but whose body contains both breaking and feat. With the fix it yields a patch bump (1.0.1); without the fix it yields a major bump (2.0.0). The test also asserts that a matching subject still drives major/minor bumps.
  • Verified red → green: the new test fails on main behavior (assert 1.0.1 == 2.0.0) and passes on this branch.
  • cargo +nightly fmt --all -- --check
  • cargo clippy --tests -- -D warnings
  • cargo test -p git-cliff-core --lib (all release:: tests pass)
  • Manual CLI reproduction with --with-commit of the exact multiline messages from the issue: body-only breaking/feat no longer bump the version; BREAKING CHANGE: footer detection in the default (conventional) path still produces a major bump.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)

When `conventional_commits` is disabled, git-cliff passed each commit's
full raw message (including the body) to `next_version`, so the custom
`custom_major_increment_regex`, `custom_minor_increment_regex` and
`no_increment_regex` matched against body text and could trigger an
unintended version bump.

For example, with `custom_major_increment_regex = "breaking"`, a commit
whose subject is `fix: real bug` but whose body contains the word
"breaking" was bumped to a major version instead of a patch.

Mirror the conventional-commits path: when `conventional_commits` is
disabled, feed only the commit subject (the first line) to the version
calculator. The conventional path is unchanged, so `BREAKING CHANGE:`
footer detection still relies on the full message.

Added a regression test that fails (major bump from body text) before
the change and passes (patch bump) after it.

Closes orhun#1476
@YuriNachos
YuriNachos requested a review from orhun as a code owner August 12, 2026 08:29
… mode

Extends the non-conventional subject-only coverage to no_increment_regex,
which the fix's doc-comment lists alongside the custom_major/minor regexes.
A commit whose body (but not subject) matches no_increment_regex must still
bump, because only the subject is evaluated when conventional commits are
disabled.

Ref: orhun#1476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

custom_major/minor_increment_regex ignored for multiline commits when conventional_commits = false

1 participant