sapling/hgext/checkmessagehook.py
Kostia Balytskyi e75b9fc1b1 fb-hgext: move most of hgext3rd and related tests to core
Summary:
This commit moves most of the stuff in hgext3rd and related tests to
hg-crew/hgext and hg-crew/test respectively.

The things that are not moved are the ones which require some more complex
imports.


Depends on D6675309

Test Plan: - tests are failing at this commit, fixes are in the following commits

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.intern.facebook.com/D6675329
2018-01-09 03:03:59 -08:00

34 lines
979 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)
badlines = []
for lnum, line in enumerate(hg_commit_message.splitlines()):
for c in line:
if ord(c) < 128 and c not in printable:
badlines.append((lnum + 1, line))
break
if badlines:
ui.warn(_('non-printable characters in commit message\n'))
for num, l in badlines:
ui.warn(_('Line {}: {!r}\n'.format(num, l)))
# False means success
return bool(badlines)