2017-07-01 04:29:42 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import os
|
2018-03-29 23:39:29 +03:00
|
|
|
import signal
|
2017-07-01 04:29:42 +03:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2017-07-24 19:25:53 +03:00
|
|
|
from distutils.spawn import find_executable
|
2017-07-01 04:29:42 +03:00
|
|
|
|
|
|
|
here = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
topsrcdir = os.path.join(here, os.pardir, os.pardir)
|
|
|
|
|
|
|
|
|
2018-03-29 23:39:29 +03:00
|
|
|
def run_process(cmd):
|
|
|
|
proc = subprocess.Popen(cmd)
|
|
|
|
|
|
|
|
# ignore SIGINT, the mozlint subprocess should exit quickly and gracefully
|
|
|
|
orig_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
|
|
proc.wait()
|
|
|
|
signal.signal(signal.SIGINT, orig_handler)
|
|
|
|
return proc.returncode
|
|
|
|
|
|
|
|
|
2017-07-01 04:29:42 +03:00
|
|
|
def run_mozlint(hooktype, args):
|
2017-07-12 00:02:46 +03:00
|
|
|
# --quiet prevents warnings on eslint, it will be ignored by other linters
|
2017-07-24 19:25:53 +03:00
|
|
|
python = find_executable('python2.7') or find_executable('python')
|
|
|
|
cmd = [python, os.path.join(topsrcdir, 'mach'), 'lint', '--quiet']
|
2017-07-01 04:29:42 +03:00
|
|
|
|
|
|
|
if 'commit' in hooktype:
|
|
|
|
# don't prevent commits, just display the lint results
|
2018-03-29 23:39:29 +03:00
|
|
|
run_process(cmd + ['--workdir=staged'])
|
2017-07-01 04:29:42 +03:00
|
|
|
return False
|
|
|
|
elif 'push' in hooktype:
|
2018-03-29 23:39:29 +03:00
|
|
|
return run_process(cmd + ['--outgoing'] + args)
|
2017-07-01 04:29:42 +03:00
|
|
|
|
|
|
|
print("warning: '{}' is not a valid mozlint hooktype".format(hooktype))
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def hg(ui, repo, **kwargs):
|
|
|
|
hooktype = kwargs['hooktype']
|
|
|
|
return run_mozlint(hooktype, kwargs.get('pats', []))
|
|
|
|
|
|
|
|
|
2017-11-02 00:07:18 +03:00
|
|
|
def git():
|
2017-07-01 04:29:42 +03:00
|
|
|
hooktype = os.path.basename(__file__)
|
2017-11-21 14:10:09 +03:00
|
|
|
if hooktype == 'hooks.py':
|
|
|
|
hooktype = 'pre-push'
|
2017-11-02 00:07:18 +03:00
|
|
|
return run_mozlint(hooktype, [])
|
2017-07-01 04:29:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(git())
|