mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-21 08:20:14 -06:00
Implement fail_fast.
This commit is contained in:
@@ -130,6 +130,7 @@ CONFIG_SCHEMA = schema.Map(
|
||||
'Config', None,
|
||||
|
||||
schema.RequiredRecurse('repos', schema.Array(CONFIG_REPO_DICT)),
|
||||
schema.Optional('fail_fast', schema.check_bool, False),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -169,13 +169,15 @@ def _compute_cols(hooks, verbose):
|
||||
return max(cols, 80)
|
||||
|
||||
|
||||
def _run_hooks(repo_hooks, args, environ):
|
||||
def _run_hooks(config, repo_hooks, args, environ):
|
||||
"""Actually run the hooks."""
|
||||
skips = _get_skips(environ)
|
||||
cols = _compute_cols([hook for _, hook in repo_hooks], args.verbose)
|
||||
retval = 0
|
||||
for repo, hook in repo_hooks:
|
||||
retval |= _run_single_hook(hook, repo, args, skips, cols)
|
||||
if retval and config['fail_fast']:
|
||||
break
|
||||
if (
|
||||
retval and
|
||||
args.show_diff_on_failure and
|
||||
@@ -251,4 +253,4 @@ def run(runner, args, environ=os.environ):
|
||||
if not hook['stages'] or args.hook_stage in hook['stages']
|
||||
]
|
||||
|
||||
return _run_hooks(repo_hooks, args, environ)
|
||||
return _run_hooks(runner.config, repo_hooks, args, environ)
|
||||
|
||||
@@ -37,10 +37,14 @@ class Runner(object):
|
||||
def config_file_path(self):
|
||||
return os.path.join(self.git_root, self.config_file)
|
||||
|
||||
@cached_property
|
||||
def config(self):
|
||||
return load_config(self.config_file_path)
|
||||
|
||||
@cached_property
|
||||
def repositories(self):
|
||||
"""Returns a tuple of the configured repositories."""
|
||||
repos = load_config(self.config_file_path)['repos']
|
||||
repos = self.config['repos']
|
||||
repos = tuple(Repository.create(x, self.store) for x in repos)
|
||||
for repo in repos:
|
||||
repo.require_installed()
|
||||
|
||||
Reference in New Issue
Block a user