Skip to content
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

feat(check): Add --allow-abort option #512

Merged
merged 3 commits into from
May 14, 2022

Conversation

Kurt-von-Laven
Copy link
Contributor

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

Description

Empty commit messages indicate to Git that the commit should be aborted. Displaying an error message when the commit is already being aborted typically only creates confusion. Add an --allow-abort argument to the check command and allow_abort config variable, both defaulting to false for backwards compatibility. When the commit message is empty, determine the outcome based on the allow_abort setting alone, ignoring the pattern.

Closes #424.

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

No error message is displayed when aborting a commit locally, unless the commit .

Steps to Test This Pull Request

  1. Run cz commit.
  2. Save and close the commit message file that appears with an empty commit message.
  3. No error occurs if you add allow_abort = true to your config, but an error occurs otherwise.

Additional context

Would it make sense for --allow-abort to also be added as an arg to the commit command? How do folks feel about the argument/setting name and overall approach? See also #247 for a related feature proposal. Since the time of that discussion, I realized that naming a Commitizen argument --allow-empty-message could prove extremely confusing, because passing it to Commitizen would not, by itself, cause commits with empty messages to be committed like the Git argument of the same name. It would also interact poorly with the proposal to allow ferrying arbitrary arguments to git commit in #451, because it would be easy to accidentally pass the argument to Git, resulting in commits with empty messages no longer being aborted.

@Kurt-von-Laven Kurt-von-Laven force-pushed the reject-abort branch 4 times, most recently from 8199666 to cd8c895 Compare May 5, 2022 07:32
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #512 (aa25391) into master (7b69599) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #512   +/-   ##
=======================================
  Coverage   97.92%   97.92%           
=======================================
  Files          39       39           
  Lines        1540     1543    +3     
=======================================
+ Hits         1508     1511    +3     
  Misses         32       32           
Flag Coverage Δ
unittests 97.92% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
commitizen/cli.py 93.93% <ø> (ø)
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%> (ø)

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 713ce19...aa25391. Read the comment docs.

@woile woile requested a review from Lee-W May 10, 2022 11:55
@woile
Copy link
Member

woile commented May 10, 2022

LGTM but cz check is not my speciality, can u take a look @Lee-W ?

Explicitly mark some loop variables unused as recommended by
flake8-bugbear.
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Hi @Kurt-von-Laven , sorry for late reviewing. Your work is fantastic! Just left a few questions. But I think we're almost ready to mrege

commitizen/cli.py Show resolved Hide resolved
docs/check.md Outdated Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
@Kurt-von-Laven Kurt-von-Laven changed the title feat(check): Don't error on empty commit messages feat(check): Add --allow-abort option May 11, 2022
Copy link
Contributor Author

@Kurt-von-Laven Kurt-von-Laven left a comment

Choose a reason for hiding this comment

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

Would it make sense for --allow-abort to also be added as an arg to the commit command?

EDIT: I think I answered this question for myself: no.

commitizen/cli.py Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
docs/check.md Outdated Show resolved Hide resolved
@Kurt-von-Laven
Copy link
Contributor Author

I am not able to reproduce the failure on Python 3.10 locally on Python 3.10.4. It appears to be unrelated to this pull request, so I think the build may simply need to be re-run. Please let me know if anyone sees a connection I am missing.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Except for the minor comment update, this PR looks good to me. @woile I'm planning on merging it this weekend if no other new comments added

commitizen/cli.py Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
commitizen/commands/check.py Show resolved Hide resolved
@Lee-W
Copy link
Member

Lee-W commented May 13, 2022

hmmm. we might need to take a deeper look at the 3.10 case

Empty commit messages indicate to Git that the commit should be aborted.
Displaying an error message when the commit is already being aborted
typically only creates confusion. Add an --allow-abort argument to the
check command and allow_abort config variable, both defaulting to false
for backwards compatibility. When the commit message is empty, determine
the outcome based on the allow_abort setting alone, ignoring the
pattern.
Copy link
Contributor Author

@Kurt-von-Laven Kurt-von-Laven left a comment

Choose a reason for hiding this comment

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

I am still unable to reproduce the build failure locally on Python 3.10.4.

commitizen/commands/check.py Show resolved Hide resolved
@Kurt-von-Laven
Copy link
Contributor Author

Looks like the Python 3.10 build indeed simply needed to be re-run since all I changed was the two comments.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

LGTM. Let's merge it now!

@Lee-W Lee-W merged commit e0f9fe5 into commitizen-tools:master May 14, 2022
@Kurt-von-Laven Kurt-von-Laven deleted the reject-abort branch May 14, 2022 17:53
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.

Aborted Commit Considered to Fail Validation When Run As commit-msg Hook
3 participants