Fail a hook if it makes modifications. Resolves #285

This commit is contained in:
Anthony Sottile 2015-11-12 15:16:55 -08:00
parent 67f6f812c4
commit a3f78bc165
5 changed files with 47 additions and 0 deletions

View file

@ -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