Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(Init): raise InitFailedError on keyboard interrupt on pre-commit ... #1604

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

Open
bearomorphism wants to merge 1 commit into commitizen-tools:v4-9-2
base: v4-9-2
Choose a base branch
Loading
from bearomorphism:fix-hook-types

Conversation

Copy link
Contributor

@bearomorphism bearomorphism commented Sep 15, 2025
edited
Loading

...hook question, remove unreachable code path

Description

Checklist

Code Changes

  • Add test cases to all the changes you introduce
  • Run poetry 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 poetry doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external) in the documentation

When running poetry doc, any broken internal documentation links will be reported in the console output like this:

INFO - Doc file 'config.md' contains a link 'commands/bump.md#-post_bump_hooks', but the doc 'commands/bump.md' does not contain an anchor '#-post_bump_hooks'.

Expected Behavior

Steps to Test This Pull Request

Additional Context

Copy link

codecov bot commented Sep 15, 2025
edited
Loading

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v4-9-2@1bb40c7). Learn more about missing BASE report.

Files with missing lines Patch % Lines
commitizen/commands/init.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@
## v4-9-2 #1604 +/- ##
=========================================
 Coverage ? 98.32% 
=========================================
 Files ? 58 
 Lines ? 2684 
 Branches ? 0 
=========================================
 Hits ? 2639 
 Misses ? 45 
 Partials ? 0 
Flag Coverage Δ
unittests 98.32% <91.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines -382 to -383
if hook_types is None:
hook_types = ["commit-msg", "pre-push"]
Copy link
Contributor Author

@bearomorphism bearomorphism Sep 15, 2025

Choose a reason for hiding this comment

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

This branch is redundant. hook_types is never None as we already checked it at callsite.

Copy link
Contributor Author

Just adding a note that I have confirmed the issue with @Lee-W offline


def _gen_pre_commit_cmd(self, hook_types: list[str]) -> str:
"""Generate pre-commit command according to given hook types"""
if not hook_types:
Copy link
Contributor Author

@bearomorphism bearomorphism Sep 15, 2025

Choose a reason for hiding this comment

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

This not hook_types is again redundant.

c = cmd.run(cmd_str)
if c.return_code != 0:
raise InitFailedError(
"Failed to install pre-commit hook.\n"
Copy link
Contributor Author

@bearomorphism bearomorphism Sep 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

Just added this line to keep the original behavior.

if not self.project_info.is_pre_commit_installed:
raise InitFailedError(
"Failed to install pre-commit hook.\n"
"pre-commit is not installed in current environment."
Copy link
Contributor Author

@bearomorphism bearomorphism Sep 15, 2025

Choose a reason for hiding this comment

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

This line is also added to keep the original behavior.

Copy link
Contributor Author

Added some more changes related to hook_types to reduce complexity. Thanks.

@Lee-W Lee-W added this to the 4.9.2 milestone Sep 15, 2025
@Lee-W Lee-W changed the base branch from master to v4-9-2 September 15, 2025 15:31
...hook question, simplify logic, remove unreachable code path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@woile woile woile approved these changes

@Lee-W Lee-W Awaiting requested review from Lee-W Lee-W is a code owner

@noirbizarre noirbizarre Awaiting requested review from noirbizarre noirbizarre is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
4.9.2
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /