MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _run_hooks

Function _run_hooks

pre_commit/commands/run.py:282–322  ·  view source on GitHub ↗

Actually run the hooks.

(
        config: dict[str, Any],
        hooks: Sequence[Hook],
        skips: set[str],
        args: argparse.Namespace,
)

Source from the content-addressed store, hash-verified

280
281
282def _run_hooks(
283 config: dict[str, Any],
284 hooks: Sequence[Hook],
285 skips: set[str],
286 args: argparse.Namespace,
287) -> int:
288 """Actually run the hooks."""
289 cols = _compute_cols(hooks)
290 classifier = Classifier.from_config(
291 _all_filenames(args), config['files'], config['exclude'],
292 )
293 retval = 0
294 prior_diff = _get_diff()
295 for hook in hooks:
296 current_retval, prior_diff = _run_single_hook(
297 classifier, hook, skips, cols, prior_diff,
298 verbose=args.verbose, use_color=args.color,
299 )
300 retval |= current_retval
301 fail_fast = (config['fail_fast'] or hook.fail_fast or args.fail_fast)
302 if current_retval and fail_fast:
303 break
304 if retval and args.show_diff_on_failure and prior_diff:
305 if args.all_files:
306 output.write_line(
307 'pre-commit hook(s) made changes.\n'
308 'If you are seeing this message in CI, '
309 'reproduce locally with: `pre-commit run --all-files`.\n'
310 'To run `pre-commit` as part of git workflow, use '
311 '`pre-commit install`.',
312 )
313 output.write_line('All changes made by hooks:')
314 # args.color is a boolean.
315 # See user_color function in color.py
316 git_color_opt = 'always' if args.color else 'never'
317 subprocess.call((
318 'git', '--no-pager', 'diff', '--no-ext-diff',
319 f'--color={git_color_opt}',
320 ))
321
322 return retval
323
324
325def _has_unmerged_paths() -> bool:

Callers 1

runFunction · 0.85

Calls 5

_compute_colsFunction · 0.85
_all_filenamesFunction · 0.85
_get_diffFunction · 0.85
_run_single_hookFunction · 0.85
from_configMethod · 0.45

Tested by

no test coverage detected