Skip to content

fix: commit changelog even when preReleaseCommand returns false#781

Merged
BYK merged 2 commits intomasterfrom
byk/fix/changelog-commit-without-prerelease
Mar 25, 2026
Merged

fix: commit changelog even when preReleaseCommand returns false#781
BYK merged 2 commits intomasterfrom
byk/fix/changelog-commit-without-prerelease

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 25, 2026

Problem

The commit decision in craft prepare was gated on runPreReleaseCommand()'s return value. When it returned false — because preReleaseCommand was empty or auto-bumping found no bumpable targets — changelog changes from prepareChangelog() were silently left uncommitted.

This affected projects like sentry-go that use changelog: { policy: auto } with only github/registry targets (neither supports bumpVersion).

Fix

  1. Explicit changelog staging — After prepareChangelog() writes the file, we now git add the changelog path explicitly so it's staged regardless of the pre-release outcome.

  2. Conditional --all — Replaced commitNewVersion() with commitChanges() that uses --all only when preReleaseCommandRan is true (version bumps can touch arbitrary files). Otherwise, plain git commit commits only staged files (the changelog), preventing accidental inclusion of stray working-tree artifacts.

Scenario Before After
Changelog + version bump ✅ Commit (--all) ✅ Commit (--all)
Changelog + no version bump ❌ Skipped ✅ Commit (changelog only)
No changelog + version bump ✅ Commit (--all) ✅ Commit (--all)
No changelog + no bump + preRelease ran ✅ reportError ✅ reportError
No changelog + no bump + no preRelease ❌ Misleading log ✅ Debug log (no-op)

The commit decision was gated on runPreReleaseCommand()'s return value,
which returns false when:
- preReleaseCommand is explicitly empty string
- auto-bumping finds no bumpable targets (e.g. github + registry only)

This caused changelog entries to be silently lost in projects like
sentry-go that have changelog: { policy: auto } but no targets with
bumpVersion support.

The fix:
1. Explicitly `git add` the changelog file after prepareChangelog()
   writes it, so it is staged regardless of preReleaseCommand outcome.
2. Replace commitNewVersion() with commitChanges() that uses `--all`
   only when preReleaseCommandRan is true (version bump files could be
   anywhere), and plain `git commit` otherwise (only staged files —
   i.e. the changelog — get committed).

This prevents both the original bug (changelog not committed) and avoids
accidentally sweeping untracked files into the release commit.
@BYK BYK marked this pull request as ready for review March 25, 2026 21:11
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

The guard that checks whether the pre-release command produced changes
only looked at created/modified (working tree). Since the changelog is
now explicitly staged via git add before the pre-release command runs,
it may appear in staged rather than modified. Include repoStatus.staged
in the check to avoid a false reportError.
@BYK BYK merged commit 1d8a5f5 into master Mar 25, 2026
18 checks passed
@BYK BYK deleted the byk/fix/changelog-commit-without-prerelease branch March 25, 2026 21:40
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.

1 participant