fix(bump): evaluate increment regexes against the commit subject only - #1605
Open
YuriNachos wants to merge 2 commits into
Open
fix(bump): evaluate increment regexes against the commit subject only#1605YuriNachos wants to merge 2 commits into
YuriNachos wants to merge 2 commits into
Conversation
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
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
conventional_commitsis disabled,calculate_next_version_with_configforwarded each commit's full raw message (subject + body) tonext_version::VersionUpdater::increment. Thenext_versioncrate appliescustom_major_increment_regex,custom_minor_increment_regexandno_increment_regexagainst 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 = falseandcustom_major_increment_regex = "breaking", a commitfix: real bug\n\nnotes: breaking change discussedbumps to a major release (the body word "breaking" matches) instead of a patch release.This PR threads the
conventional_commitsflag 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 whenconventional_commits = true, soBREAKING CHANGE:footer detection and!-flag handling behave exactly as before.The change reuses the existing
calculate_next_version_with_configentry point (now a thin delegate that passesconventional_commits = true, preserving every existing caller/test) and moves the real work intocalculate_next_version_from_commits(config, conventional_commits), whichChangelog::bump_versioncalls withself.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 onmain(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?
release::test::custom_increment_regex_matches_subject_only_when_non_conventional: a commit whose subject matches no regex but whose body contains bothbreakingandfeat. 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.mainbehavior (assert 1.0.1 == 2.0.0) and passes on this branch.cargo +nightly fmt --all -- --checkcargo clippy --tests -- -D warningscargo test -p git-cliff-core --lib(allrelease::tests pass)--with-commitof the exact multiline messages from the issue: body-onlybreaking/featno longer bump the version;BREAKING CHANGE:footer detection in the default (conventional) path still produces a major bump.Types of Changes