Actually run the hooks.
(
config: dict[str, Any],
hooks: Sequence[Hook],
skips: set[str],
args: argparse.Namespace,
)
| 280 | |
| 281 | |
| 282 | def _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 | |
| 325 | def _has_unmerged_paths() -> bool: |
no test coverage detected