Show More
@@ -1,56 +1,56 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # Copyright 2014 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2014 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # A tool/hook to run basic sanity checks on commits/patches for |
|
5 | # A tool/hook to run basic sanity checks on commits/patches for | |
6 | # submission to Mercurial. Install by adding the following to your |
|
6 | # submission to Mercurial. Install by adding the following to your | |
7 | # .hg/hgrc: |
|
7 | # .hg/hgrc: | |
8 | # |
|
8 | # | |
9 | # [hooks] |
|
9 | # [hooks] | |
10 | # pretxncommit = contrib/check-commit |
|
10 | # pretxncommit = contrib/check-commit | |
11 | # |
|
11 | # | |
12 | # The hook can be temporarily bypassed with: |
|
12 | # The hook can be temporarily bypassed with: | |
13 | # |
|
13 | # | |
14 | # $ BYPASS= hg commit |
|
14 | # $ BYPASS= hg commit | |
15 | # |
|
15 | # | |
16 | # See also: http://mercurial.selenic.com/wiki/ContributingChanges |
|
16 | # See also: http://mercurial.selenic.com/wiki/ContributingChanges | |
17 |
|
17 | |||
18 | import re, sys, os |
|
18 | import re, sys, os | |
19 |
|
19 | |||
20 | errors = [ |
|
20 | errors = [ | |
21 | (r"[(]bc[)]", "(BC) needs to be uppercase"), |
|
21 | (r"[(]bc[)]", "(BC) needs to be uppercase"), | |
22 | (r"[(]issue \d\d\d", "no space allowed between issue and number"), |
|
22 | (r"[(]issue \d\d\d", "no space allowed between issue and number"), | |
23 | (r"[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), |
|
23 | (r"[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), | |
24 | (r"^# User [^@\n]+$", "username is not an email address"), |
|
24 | (r"^# User [^@\n]+$", "username is not an email address"), | |
25 | (r"^# .*\n(?!merge with )[^#]\S+[^:] ", |
|
25 | (r"^# .*\n(?!merge with )[^#]\S+[^:] ", | |
26 | "summary line doesn't start with 'topic: '"), |
|
26 | "summary line doesn't start with 'topic: '"), | |
27 | (r"^# .*\n[A-Z][a-z]\S+", "don't capitalize summary lines"), |
|
27 | (r"^# .*\n[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
28 | (r"^# .*\n[^\n]*: *[A-Z][a-z]\S+", "don't capitalize summary lines"), |
|
28 | (r"^# .*\n[^\n]*: *[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
29 | (r"^# .*\n.*\.\s+$", "don't add trailing period on summary line"), |
|
29 | (r"^# .*\n.*\.\s+$", "don't add trailing period on summary line"), | |
30 | (r"^# .*\n.{78,}", "summary line too long"), |
|
30 | (r"^# .*\n.{78,}", "summary line too long (limit is 78)"), | |
31 | (r"^\+\n \n", "adds double empty line"), |
|
31 | (r"^\+\n \n", "adds double empty line"), | |
32 | (r"\+\s+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), |
|
32 | (r"\+\s+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), | |
33 | ] |
|
33 | ] | |
34 |
|
34 | |||
35 | node = os.environ.get("HG_NODE") |
|
35 | node = os.environ.get("HG_NODE") | |
36 |
|
36 | |||
37 | if node: |
|
37 | if node: | |
38 | commit = os.popen("hg export %s" % node).read() |
|
38 | commit = os.popen("hg export %s" % node).read() | |
39 | else: |
|
39 | else: | |
40 | commit = sys.stdin.read() |
|
40 | commit = sys.stdin.read() | |
41 |
|
41 | |||
42 | exitcode = 0 |
|
42 | exitcode = 0 | |
43 | for exp, msg in errors: |
|
43 | for exp, msg in errors: | |
44 | m = re.search(exp, commit, re.MULTILINE) |
|
44 | m = re.search(exp, commit, re.MULTILINE) | |
45 | if m: |
|
45 | if m: | |
46 | pos = 0 |
|
46 | pos = 0 | |
47 | for n, l in enumerate(commit.splitlines(True)): |
|
47 | for n, l in enumerate(commit.splitlines(True)): | |
48 | pos += len(l) |
|
48 | pos += len(l) | |
49 | if pos >= m.end(): |
|
49 | if pos >= m.end(): | |
50 | print "%d: %s" % (n, msg) |
|
50 | print "%d: %s" % (n, msg) | |
51 | print " %s" % l[:-1] |
|
51 | print " %s" % l[:-1] | |
52 | if "BYPASS" not in os.environ: |
|
52 | if "BYPASS" not in os.environ: | |
53 | exitcode = 1 |
|
53 | exitcode = 1 | |
54 | break |
|
54 | break | |
55 |
|
55 | |||
56 | sys.exit(exitcode) |
|
56 | sys.exit(exitcode) |
General Comments 0
You need to be logged in to leave comments.
Login now