Skip to content

Commit fb15fa6

Browse files
committed
Fix handling of SIGINT in hook script
1 parent e10b818 commit fb15fa6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pre_commit/resources/hook-tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,25 @@ def _opts(stdin):
170170
return ('--config', CONFIG, '--hook-stage', stage) + fns[HOOK_TYPE](stdin)
171171

172172

173+
if sys.version_info < (3, 7): # https://bugs.python.org/issue25942
174+
def _subprocess_call(cmd): # this is the python 2.7 implementation
175+
return subprocess.Popen(cmd).wait()
176+
else:
177+
_subprocess_call = subprocess.call
178+
179+
173180
def main():
174181
retv, stdin = _run_legacy()
175182
try:
176183
_validate_config()
177-
return retv | subprocess.call(_exe() + _opts(stdin))
184+
return retv | _subprocess_call(_exe() + _opts(stdin))
178185
except EarlyExit:
179186
return retv
180187
except FatalError as e:
181188
print(e.args[0])
182189
return 1
190+
except KeyboardInterrupt:
191+
return 1
183192

184193

185194
if __name__ == '__main__':

0 commit comments

Comments
 (0)