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(pre-commit): Correct pre-commit Hook Definition #514

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

Merged
Lee-W merged 4 commits into commitizen-tools:master from Kurt-von-Laven:allow-abort
May 22, 2022

Conversation

Copy link
Contributor

@Kurt-von-Laven Kurt-von-Laven commented May 16, 2022

Description

Use new --allow-abort option. Prevent pre-commit hook from complaining when a commit is aborted by default, but allow users to override this option in their pre-commit config by specifying it in args, not entry. Move --commit-msg-file option from entry to args since it has to be the last option.

Confine hook to commit-msg stage. The Commitizen pre-commit hook runs cz check, which only makes sense to do on a commit message, not at other Git hook stages. By default the hook is currently run on staged files pre-commit, which is nonsensical unless the files in the repository themselves contain Git commit messages. The hook is an implausible candidate even for the prepare-commit-msg stage since this stage is intended for hooks that modify the commit message rather than check it. Specifying the hook stage centrally makes it less error-prone to use and saves one line of configuration for users of the pre-commit hook.

Change minimum pre-commit version from 0.15.4 to 1.4.3. pre-commit 1.4.3, released 2018年01月02日, is the minimum pre-commit version at which language_version: python3 is translated to the correct py launcher call on Windows.

Don't require serial execution. require_serial is not pertinent to commit-msg hooks or hooks that themselves execute serially. The option is intended to prevent fork-bombing that can occur when pre-commit runs a hook that itself spawns many processes many times in parallel.

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

The commit hook continues to work as before but without requiring that the commit-msg stage be specified in your .pre-commit-config.yaml or giving a misleading error message when the commit is aborted by saving an empty commit message in your editor.

Steps to Test This Pull Request

  1. Replace your Commitizen hook config in your .pre-commit-config.yaml with the following:

    repos:
     - repo: https://github.com/Kurt-von-Laven/commitizen
     rev: allow-abort
     hooks:
     - id: commitizen
  2. Ensure that you have pre-commit 1.4.3 or higher installed.

  3. Install commit-msg hooks if you haven't already via: pre-commit install --hook-type commit-msg.

  4. Commit some changes to your repository.

  5. If the commit message was invalid, the hook will fail, and otherwise it will succeed. Empty commit messages now fall in the latter category, and the commit aborts cleanly without a misleading error.

Additional context

Follows on #512, which added the --allow-abort option to cz check. Reverts #135, which removed stages: [commit-msg].

Kurt-von-Laven and others added 4 commits May 15, 2022 23:49
require_serial is not pertinent to commit-msg hooks or hooks that
themselves execute serially. The option is intended to prevent
fork-bombing that can occur when pre-commit runs a hook that itself
spawns many processes many times in parallel.
pre-commit 1.4.3, released 2018年01月02日, is the minimum pre-commit version
at which language_version: python3 is translated to the correct py
launcher call on Windows.
The Commitizen pre-commit hook runs cz check, which only makes sense to
do on a commit message, not at other Git hook stages. By default the
hook is currently run on staged files pre-commit, which is nonsensical
unless the files in the repository themselves contain Git commit
messages. The hook is an implausible candidate even for the
prepare-commit-msg stage since this stage is intended for hooks that
modify the commit message rather than check it. Specifying the hook
stage centrally makes it less error-prone to use and saves one line of
configuration for users of the pre-commit hook.
Prevent pre-commit hook from complaining when a commit is aborted by
default, but allow users to override this option in their pre-commit
config by specifying it in args, not entry. Move --commit-msg-file
option from entry to args since it has to be the last option.
Copy link

codecov bot commented May 16, 2022
edited
Loading

Codecov Report

Merging #514 (522509e) into master (7b69599) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

@@ Coverage Diff @@
## master #514 +/- ##
==========================================
- Coverage 97.92% 97.86% -0.07% 
==========================================
 Files 39 39 
 Lines 1540 1543 +3 
==========================================
+ Hits 1508 1510 +2 
- Misses 32 33 +1 
Flag Coverage Δ
unittests 97.86% <100.00%> (-0.07%) ⬇️

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

Impacted Files Coverage Δ
commitizen/cli.py 93.93% <ø> (ø)
commitizen/commands/init.py 91.66% <ø> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/commands/check.py 100.00% <100.00%> (ø)
commitizen/cz/__init__.py 100.00% <100.00%> (ø)
commitizen/defaults.py 100.00% <100.00%> (ø)
commitizen/changelog.py 96.72% <0.00%> (-0.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85d9939...522509e. Read the comment docs.

Copy link
Contributor Author

Please let me know what action I should take regarding the Codecov report. My instinct is to consider it a false positive and ignore it since I believe it is a consequence of increasing the length of the pre-commit hook definition length by one net line. Although, maybe the ideal thing would be to configure Codecov not to scan .pre-commit-hooks.yaml?

Copy link
Member

Lee-W commented May 17, 2022

I just browse through the code. Everything looks good, but I might a bit more time to test it out. I think we'll be able to merge it this week. Thank you so much for your active contributions 🙏

Please let me know what action I should take regarding the Codecov report. My instinct is to consider it a false positive and ignore it since I believe it is a consequence of increasing the length of the pre-commit hook definition length by one net line. Although, maybe the ideal thing would be to configure Codecov not to scan .pre-commit-hooks.yaml?

I'm good with ignore the warning here.
@woile I don't think I have the permission to do the check. Could you please check it when you have time? Thanks!

Kurt-von-Laven reacted with thumbs up emoji

@Lee-W Lee-W merged commit d55acad into commitizen-tools:master May 22, 2022
Copy link
Member

Lee-W commented May 22, 2022

just tested. let's merge it 🎉

Kurt-von-Laven reacted with hooray emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

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