mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Fail a hook if it makes modifications. Resolves #285
This commit is contained in:
parent
67f6f812c4
commit
a3f78bc165
5 changed files with 47 additions and 0 deletions
|
|
@ -85,7 +85,13 @@ def _run_single_hook(hook, repo, args, write, skips=frozenset()):
|
|||
write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))
|
||||
sys.stdout.flush()
|
||||
|
||||
diff_before = cmd_output('git', 'diff', retcode=None)
|
||||
retcode, stdout, stderr = repo.run_hook(hook, filenames)
|
||||
diff_after = cmd_output('git', 'diff', retcode=None)
|
||||
|
||||
# If the hook makes changes, fail the commit
|
||||
if diff_before != diff_after:
|
||||
retcode = 1
|
||||
|
||||
if retcode:
|
||||
retcode = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue