Skip to content

feat(bump): add --no-commit to tag the current HEAD without a bump commit - #2123

Open
VamikaSinghal wants to merge 1 commit into
commitizen-tools:masterfrom
VamikaSinghal:feat/bump-no-commit
Open

VamikaSinghal wants to merge 1 commit into
commitizen-tools:masterfrom
VamikaSinghal:feat/bump-no-commit

Conversation

@VamikaSinghal

Copy link
Copy Markdown
Contributor

Description

Adds cz bump --no-commit, the opt-out asked for in #753: the bump still updates the version_files and the changelog, runs the pre_bump_hooks/post_bump_hooks and creates the tag, but it does not stage or commit anything. The tag points to the current HEAD and the updated files stay in the working tree.

Why: projects that keep the version in Git tags only (version_provider = "scm") do not want a release commit, e.g. a CI job that tags the commit which triggered it. Today cz bump fails for them with 2nd git.commit error: "nothing to commit, working tree clean" (exit code 6), and the SCM tutorial documents a manual cz version + cz changelog + git tag sequence instead. #1969 skips the commit automatically when there is nothing to commit; this PR adds the explicit flag from the issue, which also covers the case where files were updated (changelog, version_files) but the user does not want them committed. The two changes touch the same block and rebase trivially on top of each other.

Changes:

  • commitizen/commands/bump.py: new no_commit argument; the existing add/commit/retry block moved unchanged into Bump._commit(), and Bump._report_skipped_commit() prints one line (to stderr when --changelog-to-stdout is used, so stdout stays the changelog). The tag step is unchanged.
  • commitizen/cli.py: the --no-commit option (CLI only, like --allow-no-commit).
  • docs/commands/bump.md: a --no-commit section, with a note on how it differs from --allow-no-commit and --version-files-only; docs/tutorials/release-scm.md: fixes the scp typo in the intro and adds a tip pointing to the flag before the manual git tag recipe.
  • tests/commands/test_bump_command.py: two tests (tag on the previous HEAD, git.commit never called, config file left modified and unstaged; --changelog-to-stdout keeps stdout clean and leaves CHANGELOG.md untracked). The cz bump --help regression snapshots for Python 3.10–3.14 were regenerated with --force-regen under each interpreter.

Closes #753

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (Claude Code)

Generated-by: Claude Code following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

cz bump --no-commit behaves like cz bump except that no commit is created: same version calculation, file updates, hooks and tag; the tag is placed on the current HEAD. Without the flag nothing changes.

Steps to Test This Pull Request

uv run pytest tests/commands/test_bump_command.py -k no_commit     # 2 new tests
uv run pytest -n auto --dist=loadfile                              # 1330 passed, 2 skipped, 2 xfailed
uv run ruff check && uv run mypy && uv run prek run --all-files    # all pass
uv run --group documentation mkdocs build --strict                 # builds, anchors resolve

The 4 *_signed* bump tests error on my machine because gpg is not installed; they are unrelated and error on master too.

Manual run in a throwaway repo with version_provider = "scm", where cz bump fails today:

$ cz bump --yes --no-commit
bump: version 0.1.0 → 0.2.0
tag to create: v0.2.0
increment detected: MINOR

--no-commit: skipping the bump commit, tagging the current HEAD (updated files stay uncommitted)
Done!
$ git log --oneline --decorate
dbf9240 (HEAD -> main, tag: v0.2.1) fix: a bug
b6b126e (tag: v0.2.0) feat: first feature
1c9ba3a (tag: v0.1.0) chore: init
$ cz bump --yes            # same repo, without the flag (current behaviour)
...
2nd git.commit error: "On branch main
nothing to commit, working tree clean
"

With the version in pyproject.toml and update_changelog_on_bump = true, the files are updated but left uncommitted:

$ cz bump --yes --no-commit
...
$ git log --oneline --decorate
1873c92 (HEAD -> main, tag: 0.2.0) feat: add feature
1e6d245 chore: init
$ git status --short
 M pyproject.toml
?? CHANGELOG.md

cz bump --yes --no-commit --changelog-to-stdout > body.md writes only the changelog to body.md; the --no-commit line goes to stderr.

Additional Context

Related: #1969 (skip the commit automatically when there are no file changes), #753 discussion where woile and Lee-W preferred "just create a tag" for the SCM case. The option is CLI-only for now; a no_commit setting could be added later if wanted.

🤖 Generated with Claude Code

…mmit

`cz bump --no-commit` updates the version files and the changelog, runs the
hooks and creates the tag as usual, but does not stage or commit anything:
the tag points to the current HEAD and the updated files stay in the working
tree. This is the explicit opt-out asked for in commitizen-tools#753, for projects that keep
the version in Git tags only (for example `version_provider = "scm"`) and do
not want a release commit, such as a CI job tagging the commit that
triggered it.

Closes commitizen-tools#753

Assisted By: AI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (e153e14) to head (e1a8a65).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2123   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          61       61           
  Lines        2866     2875    +9     
=======================================
+ Hits         2817     2826    +9     
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag to avoid creating a new commit for the bump

1 participant