mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
0e16b9b84d
Summary: It makes it easier to set up a hook - just enabling the extension will enable the hook. Test Plan: Run perl script system("echo 1 >> 1"); system("hg add 1"); system("hg ci -m"."\x80"); system("hg ci -m"."\x01"); system("hg ci -m ok"); make sure only one commit was created Reviewers: #sourcecontrol, mjpieters Reviewed By: mjpieters Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4604980 Tasks: 16212973 Signature: t1:4604980:1487944300:8e4e7f340c746237b47773fc81759025e97b919e
27 lines
741 B
Python
27 lines
741 B
Python
import string
|
|
|
|
from mercurial.i18n import _
|
|
|
|
def reposetup(ui, repo):
|
|
ui.setconfig('hooks', 'pretxncommit.checkmessage', checkcommitmessage)
|
|
|
|
def checkcommitmessage(ui, repo, **kwargs):
|
|
"""
|
|
Checks a single commit message for adherence to commit message rules.
|
|
"""
|
|
hg_commit_message = repo['tip'].description()
|
|
try:
|
|
hg_commit_message.decode('utf8')
|
|
except UnicodeDecodeError:
|
|
ui.warn(_('commit message is not utf-8\n'))
|
|
return True
|
|
|
|
printable = set(string.printable)
|
|
for c in hg_commit_message:
|
|
if ord(c) < 128 and c not in printable:
|
|
ui.warn(_('non-printable characters in commit message\n'))
|
|
return True
|
|
|
|
# False means success
|
|
return False
|