Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tools/verifygitlog.py: Show invalid commit subjects in quotes. #16465

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
merged 1 commit into from
Dec 23, 2024

Conversation

agatti
Copy link
Contributor

@agatti agatti commented Dec 20, 2024

Summary

If a commit subject line has any trailing whitespace it won't match the repository validation rules, and the line will show up as part of the relevant error message. However, since there's no quotation marks around the offending text, the trailing whitespace may go unnoticed, and given that the commit message is then discarded when the commit operation is retried this can get fairly annoying.

This commit simply modifies the error output for invalid subject lines to add quotation marks around the offending text, so trailing whitespace is much easier to see.

Testing

I accidentally triggered the trailing whitespace issue when attempting to commit some code (the subject line has a trailing space character past the period):

[...]
MicroPython git commit message format checker............................Failed
- hook id: verifygitlog
- duration: 0.15s
- exit code: 1

error: Subject line: py/emitnative: Use RV32 Zba opcodes for shorter sequences if enabled. 
error: * must end with "."
error: * must match: '^[^!]+: [A-Z]+.+ .+\\.$'
error: * Example: "py/runtime: Add support for foo to bar."
[...]

But after this change it looks like this:

[...]
MicroPython git commit message format checker............................Failed
- hook id: verifygitlog
- duration: 0.15s
- exit code: 1

error: Subject line: "py/emitnative: Use RV32 Zba opcodes for shorter sequences if enabled. "
error: * must end with "."
error: * must match: '^[^!]+: [A-Z]+.+ .+\\.$'
error: * Example: "py/runtime: Add support for foo to bar."
[...]

With the trailing space slightly more visible.

Trade-offs and Alternatives

I could have used the backtick (`) character instead of normal quotation mark character but then that may yield "interesting" side-effects if the output is accidentally copied and pasted in an Unix-like shell.

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (7ca6e5e) to head (4729a89).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16465   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21349    21349           
=======================================
  Hits        21045    21045           
  Misses        304      304           

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

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Dec 21, 2024
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

This change looks very reasonable.

If a commit subject line has any trailing whitespace it won't match the
repository validation rules, and the line will show up as part of the
relevant error message.  However, since there's no quotation marks
around the offending text, the trailing whitespace may go unnoticed, and
given that the commit message is then discarded when the commit
operation is retried this can get fairly annoying.

This commit simply modifies the error output for invalid subject lines
to add quotation marks around the offending text, so trailing whitespace
is much easier to see.

Signed-off-by: Alessandro Gatti <[email protected]>
@dpgeorge dpgeorge force-pushed the precommit-quote-commit-subject branch from 31695e4 to 4729a89 Compare December 23, 2024 01:55
@dpgeorge dpgeorge merged commit 4729a89 into micropython:master Dec 23, 2024
63 checks passed
@agatti agatti deleted the precommit-quote-commit-subject branch December 23, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants