diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index 7fb49d78..c04cf333 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -130,6 +130,7 @@ CONFIG_SCHEMA = schema.Map( 'Config', None, schema.RequiredRecurse('repos', schema.Array(CONFIG_REPO_DICT)), + schema.Optional('exclude', schema.check_regex, '^$'), schema.Optional('fail_fast', schema.check_bool, False), ) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index e260b662..6f695487 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -183,6 +183,7 @@ def _run_hooks(config, repo_hooks, args, environ): skips = _get_skips(environ) cols = _compute_cols([hook for _, hook in repo_hooks], args.verbose) filenames = _all_filenames(args) + filenames = _filter_by_include_exclude(filenames, '', config['exclude']) retval = 0 for repo, hook in repo_hooks: retval |= _run_single_hook(filenames, hook, repo, args, skips, cols) diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 46d2a7e1..51e4eac9 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -183,6 +183,21 @@ def test_exclude_types_hook_repository( assert b'exe' not in printed +def test_global_exclude(cap_out, tempdir_factory, mock_out_store_directory): + git_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') + with cwd(git_path): + with modify_config() as config: + config['exclude'] = '^foo.py$' + open('foo.py', 'a').close() + open('bar.py', 'a').close() + cmd_output('git', 'add', '.') + ret, printed = _do_run(cap_out, git_path, _get_opts(verbose=True)) + assert ret == 0 + # Does not contain foo.py since it was excluded + expected = b'hookid: bash_hook\n\nbar.py\nHello World\n\n' + assert printed.endswith(expected) + + def test_show_diff_on_failure( capfd, cap_out, tempdir_factory, mock_out_store_directory, ):