From fb15fa65f20e7c618032293ece1bda238672ab43 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 10 May 2019 20:27:52 -0700 Subject: [PATCH] Fix handling of SIGINT in hook script --- pre_commit/resources/hook-tmpl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index 19d0e726..a145c8ee 100755 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -170,16 +170,25 @@ def _opts(stdin): return ('--config', CONFIG, '--hook-stage', stage) + fns[HOOK_TYPE](stdin) +if sys.version_info < (3, 7): # https://bugs.python.org/issue25942 + def _subprocess_call(cmd): # this is the python 2.7 implementation + return subprocess.Popen(cmd).wait() +else: + _subprocess_call = subprocess.call + + def main(): retv, stdin = _run_legacy() try: _validate_config() - return retv | subprocess.call(_exe() + _opts(stdin)) + return retv | _subprocess_call(_exe() + _opts(stdin)) except EarlyExit: return retv except FatalError as e: print(e.args[0]) return 1 + except KeyboardInterrupt: + return 1 if __name__ == '__main__':