mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +04:00
support 'diff-only' hooks by passing diff via stdin (#1279)
This commit is contained in:
parent
b2faf339ce
commit
4b7f832122
4 changed files with 20 additions and 5 deletions
|
|
@ -139,10 +139,14 @@ def _run_single_hook(
|
|||
|
||||
diff_cmd = ('git', 'diff', '--no-ext-diff')
|
||||
diff_before = cmd_output_b(*diff_cmd, retcode=None)
|
||||
if not hook.pass_filenames:
|
||||
filenames = ()
|
||||
if hook.pass_diff:
|
||||
inputs = (diff_before[1],)
|
||||
elif hook.pass_filenames:
|
||||
inputs = filenames
|
||||
else:
|
||||
inputs = ()
|
||||
time_before = time.time()
|
||||
retcode, out = hook.run(filenames, use_color)
|
||||
retcode, out = hook.run(inputs, use_color)
|
||||
duration = round(time.time() - time_before, 2) or 0
|
||||
diff_after = cmd_output_b(*diff_cmd, retcode=None)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue