mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 09:34:42 +04:00
Merge pull request #1027 from pre-commit/keyboard_interrupt_fix
Fix handling of SIGINT in hook script
This commit is contained in:
commit
bd212393ae
1 changed files with 10 additions and 1 deletions
|
|
@ -170,16 +170,25 @@ def _opts(stdin):
|
||||||
return ('--config', CONFIG, '--hook-stage', stage) + fns[HOOK_TYPE](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():
|
def main():
|
||||||
retv, stdin = _run_legacy()
|
retv, stdin = _run_legacy()
|
||||||
try:
|
try:
|
||||||
_validate_config()
|
_validate_config()
|
||||||
return retv | subprocess.call(_exe() + _opts(stdin))
|
return retv | _subprocess_call(_exe() + _opts(stdin))
|
||||||
except EarlyExit:
|
except EarlyExit:
|
||||||
return retv
|
return retv
|
||||||
except FatalError as e:
|
except FatalError as e:
|
||||||
print(e.args[0])
|
print(e.args[0])
|
||||||
return 1
|
return 1
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue