Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f4767c

Browse files
committed
Pass color option to git diff (on failure)
Fixes #1007
1 parent 0b6a397 commit 4f4767c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

pre_commit/commands/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,14 @@ def _run_hooks(config, hooks, args, environ):
224224
'`pre-commit install`.',
225225
)
226226
output.write_line('All changes made by hooks:')
227-
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
227+
if args.color:
228+
subprocess.call((
229+
'git', '--no-pager', 'diff', '--no-ext-diff',
230+
'--color={}'.format(args.color),
231+
))
232+
else:
233+
subprocess.call(('git', '--no-pager', 'diff', '--no-ext-diff'))
234+
228235
return retval
229236

230237

tests/commands/run_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ def test_global_exclude(cap_out, store, tempdir_factory):
187187
},
188188
b'All changes made by hooks:',
189189
),
190+
(
191+
{
192+
'show_diff_on_failure': True,
193+
'color': 'auto',
194+
},
195+
b'All changes made by hooks:',
196+
),
190197
(
191198
{
192199
'show_diff_on_failure': True,

0 commit comments

Comments
 (0)