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