Skip to content

Commit b8982ec

Browse files
jimmodpgeorge
authored andcommitted
tools/verifygitlog.py: Add additional help for subject line issues.
This check used to just show the regular expression that failed to match, but the rules are pretty subtle and hard to interpret from the regular expression alone. Add some basic checks for the main things that go wrong: - Missing capitalisation. - Missing full-stop. - Missing path. - Single-word subject. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent f6d06b3 commit b8982ec

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tools/verifygitlog.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ def git_log(pretty_format, *args):
4646
yield line.decode().rstrip("\r\n")
4747

4848

49+
def diagnose_subject_line(subject_line, subject_line_format, err):
50+
err.error("Subject line: " + subject_line)
51+
if not subject_line.endswith("."):
52+
err.error('* should end with "."')
53+
if not re.match(r"^[^!]+: ", subject_line):
54+
err.error('* should start with "path: "')
55+
if re.match(r"^[^!]+: *$", subject_line):
56+
err.error("* should contain a subject after the path.")
57+
m = re.match(r"^[^!]+: ([a-z][^ ]*)", subject_line)
58+
if m:
59+
err.error('* first word of subject ("{}") should be capitalised.'.format(m.group(1)))
60+
if re.match(r"^[^!]+: [^ ]+$", subject_line):
61+
err.error("* subject should contain more than one word.")
62+
err.error("* should match: " + repr(subject_line_format))
63+
err.error('* Example: "py/runtime: Add support for foo to bar."')
64+
65+
4966
def verify(sha, err):
5067
verbose("verify", sha)
5168
err.prefix = "commit " + sha + ": "
@@ -75,9 +92,9 @@ def verify_message_body(raw_body, err):
7592
very_verbose("subject_line", subject_line)
7693
subject_line_format = r"^[^!]+: [A-Z]+.+ .+\.$"
7794
if not re.match(subject_line_format, subject_line):
78-
err.error("Subject line should match " + repr(subject_line_format) + ": " + subject_line)
95+
diagnose_subject_line(subject_line, subject_line_format, err)
7996
if len(subject_line) >= 73:
80-
err.error("Subject line should be 72 or less characters: " + subject_line)
97+
err.error("Subject line should be 72 or fewer characters: " + subject_line)
8198

8299
# Second one divides subject and body.
83100
if len(raw_body) > 1 and raw_body[1]:
@@ -90,7 +107,7 @@ def verify_message_body(raw_body, err):
90107
err.error("Message lines should be 75 or less characters: " + line)
91108

92109
if not raw_body[-1].startswith("Signed-off-by: ") or "@" not in raw_body[-1]:
93-
err.warning("Message should be signed-off")
110+
err.warning('Message should be signed-off. Use "git commit -s".')
94111

95112

96113
def run(args):

0 commit comments

Comments
 (0)