mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-17 22:40:11 -06:00
show color in hook outputs when attached to a tty
This commit is contained in:
@@ -73,7 +73,7 @@ SKIPPED = 'Skipped'
|
||||
NO_FILES = '(no files to check)'
|
||||
|
||||
|
||||
def _run_single_hook(classifier, hook, args, skips, cols):
|
||||
def _run_single_hook(classifier, hook, args, skips, cols, use_color):
|
||||
filenames = classifier.filenames_for_hook(hook)
|
||||
|
||||
if hook.language == 'pcre':
|
||||
@@ -118,7 +118,8 @@ def _run_single_hook(classifier, hook, args, skips, cols):
|
||||
sys.stdout.flush()
|
||||
|
||||
diff_before = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
|
||||
retcode, out = hook.run(tuple(filenames) if hook.pass_filenames else ())
|
||||
filenames = tuple(filenames) if hook.pass_filenames else ()
|
||||
retcode, out = hook.run(filenames, use_color)
|
||||
diff_after = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
|
||||
|
||||
file_modifications = diff_before != diff_after
|
||||
@@ -203,7 +204,9 @@ def _run_hooks(config, hooks, args, environ):
|
||||
classifier = Classifier(filenames)
|
||||
retval = 0
|
||||
for hook in hooks:
|
||||
retval |= _run_single_hook(classifier, hook, args, skips, cols)
|
||||
retval |= _run_single_hook(
|
||||
classifier, hook, args, skips, cols, args.color,
|
||||
)
|
||||
if retval and config['fail_fast']:
|
||||
break
|
||||
if retval and args.show_diff_on_failure and git.has_diff():
|
||||
|
||||
Reference in New Issue
Block a user