Add a --show-diff-on-failure option

This commit is contained in:
Anthony Sottile 2017-02-25 10:14:17 -08:00
parent 0ece39c484
commit 05c88738b0
3 changed files with 32 additions and 1 deletions

View file

@ -3,6 +3,7 @@ from __future__ import unicode_literals
import logging
import os
import subprocess
import sys
from pre_commit import color
@ -152,6 +153,13 @@ def _run_hooks(repo_hooks, args, environ):
retval = 0
for repo, hook in repo_hooks:
retval |= _run_single_hook(hook, repo, args, skips, cols)
if (
retval and
args.show_diff_on_failure and
subprocess.call(('git', 'diff', '--quiet')) != 0
):
print('All changes made by hooks:')
subprocess.call(('git', 'diff'))
return retval

View file

@ -149,6 +149,10 @@ def main(argv=None):
'--hook-stage', choices=('commit', 'push'), default='commit',
help='The stage during which the hook is fired e.g. commit or push.',
)
run_parser.add_argument(
'--show-diff-on-failure', action='store_true',
help='When hooks fail, run `git diff` directly afterward.',
)
run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
run_mutex_group.add_argument(
'--all-files', '-a', action='store_true', default=False,