Show More
@@ -17,39 +17,56 b'' | |||
|
17 | 17 | |
|
18 | 18 | import re, sys, os |
|
19 | 19 | |
|
20 | commitheader = r"^(?:# [^\n]*\n)*" | |
|
21 | afterheader = commitheader + r"(?!#)" | |
|
22 | beforepatch = afterheader + r"(?!\n(?!@@))" | |
|
23 | ||
|
20 | 24 | errors = [ |
|
21 | (r"[(]bc[)]", "(BC) needs to be uppercase"), | |
|
22 | (r"[(]issue \d\d\d", "no space allowed between issue and number"), | |
|
23 | (r"[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), | |
|
24 |
(r" |
|
|
25 |
(r" |
|
|
25 | (beforepatch + r".*[(]bc[)]", "(BC) needs to be uppercase"), | |
|
26 | (beforepatch + r".*[(]issue \d\d\d", "no space allowed between issue and number"), | |
|
27 | (beforepatch + r".*[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), | |
|
28 | (commitheader + r"# User [^@\n]+\n", "username is not an email address"), | |
|
29 | (commitheader + r"(?!merge with )[^#]\S+[^:] ", | |
|
26 | 30 | "summary line doesn't start with 'topic: '"), |
|
27 |
( |
|
|
28 |
( |
|
|
29 |
(r" |
|
|
31 | (afterheader + r"[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
|
32 | (afterheader + r"[^\n]*: *[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
|
33 | (afterheader + r"\S*[^A-Za-z0-9-]\S*: ", | |
|
30 | 34 | "summary keyword should be most user-relevant one-word command or topic"), |
|
31 |
( |
|
|
32 |
( |
|
|
33 |
(r" |
|
|
34 |
(r" |
|
|
35 |
(r" |
|
|
35 | (afterheader + r".*\.\s*\n", "don't add trailing period on summary line"), | |
|
36 | (afterheader + r".{79,}", "summary line too long (limit is 78)"), | |
|
37 | (r"\n\+\n \n", "adds double empty line"), | |
|
38 | (r"\n \n\+\n", "adds double empty line"), | |
|
39 | (r"\n\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), | |
|
36 | 40 | ] |
|
37 | 41 | |
|
42 | word = re.compile('\S') | |
|
43 | def nonempty(first, second): | |
|
44 | if word.search(first): | |
|
45 | return first | |
|
46 | return second | |
|
47 | ||
|
38 | 48 | def checkcommit(commit, node = None): |
|
39 | 49 | exitcode = 0 |
|
40 | 50 | printed = node is None |
|
41 | 51 | for exp, msg in errors: |
|
42 |
m = re.search(exp, commit |
|
|
52 | m = re.search(exp, commit) | |
|
43 | 53 | if m: |
|
44 | 54 | pos = 0 |
|
55 | end = m.end() | |
|
56 | trailing = re.search(r'(\\n)+$', exp) | |
|
57 | if trailing: | |
|
58 | end -= len(trailing.group()) / 2 | |
|
59 | last = '' | |
|
45 | 60 | for n, l in enumerate(commit.splitlines(True)): |
|
46 | 61 | pos += len(l) |
|
47 |
if pos |
|
|
62 | if pos < end: | |
|
63 | last = nonempty(l, last) | |
|
64 | else: | |
|
48 | 65 | if not printed: |
|
49 | 66 | printed = True |
|
50 | 67 | print "node: %s" % node |
|
51 | 68 | print "%d: %s" % (n, msg) |
|
52 | print " %s" % l[:-1] | |
|
69 | print " %s" % nonempty(l, last)[:-1] | |
|
53 | 70 | if "BYPASS" not in os.environ: |
|
54 | 71 | exitcode = 1 |
|
55 | 72 | break |
General Comments 0
You need to be logged in to leave comments.
Login now