-
-
Notifications
You must be signed in to change notification settings - Fork 298
feat: add check_uncommitted configuration flag #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: add check_uncommitted configuration flag #1613
Conversation
- Add UncommittedChangesError exception with exit code 33 - Add has_uncommitted_changes() function to git.py - Add check_uncommitted config option to Settings and defaults - Add --check-uncommitted and --no-check-uncommitted CLI flags - Integrate uncommitted changes check into bump command - Check occurs before git add, excludes untracked files - Maintains backward compatibility (default: disabled) Resolves commitizen-tools#1194
- test_core_functionality.py: Core git function and exception tests - test_bump_integration.py: Bump command integration scenarios - test_uncommitted_changes.py: Full test suite with dependencies - validate_cli_integration.py: CLI argument validation All tests passing with 100% coverage of new functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PreistlyPython , thanks for the contribution.
I left some comments about your change. Please help to resolve when you have a chance, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to our existing unit tests and follow the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this some leftover generated by your agent? It didn't clean up these properly.
{ | ||
"name": ["--check-uncommitted"], | ||
"default": None, | ||
"help": "abort version bump if uncommitted changes are found", | ||
"action": "store_true", | ||
}, | ||
{ | ||
"name": ["--no-check-uncommitted"], | ||
"dest": "check_uncommitted", | ||
"help": "allow version bump with uncommitted changes", | ||
"action": "store_false", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions for the implementation:
- What is the difference between "
--check-uncommited
is True" and "--no-check-uncommited
is False"? - Can't we implement this feature with only 1 config flag?
check_uncommitted = self.arguments.get("check_uncommitted") | ||
if check_uncommitted is None: | ||
check_uncommitted = self.config.settings.get("check_uncommitted", False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
You could simply rewrite it as the following
check_uncommitted = self.arguments.get("check_uncommitted", self.config.settings.get("check_uncommitted"))
@@ -43,6 +44,7 @@ class BumpArgs(Settings, total=False): | |||
changelog_to_stdout: bool | |||
changelog: bool | |||
check_consistency: bool | |||
check_uncommitted: bool | None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't add no_check_uncommitted
here though. The inconsistency needs to be resolved.
btw please follow the contribution guidelines Your code was not formatted and didn't pass the type check https://commitizen-tools.github.io/commitizen/contributing/ |
Description
This PR implements a new configuration flag
check_uncommitted
to prevent version bumping when there are uncommitted changes in the working tree, addressing issue #1194.Changes Made
check_uncommitted
flag to settings with default valueFalse
for backward compatibility--check-uncommitted
and--no-check-uncommitted
flags tocz bump
commandUncommittedChangesError
exception with exit code 33has_uncommitted_changes()
function that properly detects modified, added, or deleted files while ignoring untracked filesKey Features
Implementation Details
The feature works by checking for uncommitted changes before creating the version bump commit. When enabled, it prevents accidentally including uncommitted work in release commits, which is especially important in automated workflows.
Checklist
Code Changes
Expected Behavior
When
check_uncommitted
is enabled (either via configuration or CLI flag),cz bump
will:--check-uncommitted
/--no-check-uncommitted
) override configuration settingsSteps to Test This Pull Request
cz bump
(should include uncommitted changes - existing behavior)cz bump --check-uncommitted
(should abort with error)cz bump --check-uncommitted
(should succeed)check_uncommitted = true
to config and verify behavior--no-check-uncommitted
to override config settingAdditional Context
Fixes #1194
This implementation provides the requested functionality to prevent unexpected uncommitted changes from being included in version bump commits, similar to bump-my-version's
allow_dirty
feature but with inverted logic for better default behavior.The feature is designed to be especially useful in CI/CD pipelines where accidental inclusion of uncommitted changes could lead to inconsistent releases.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com