mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-17 22:40:11 -06:00
Add top-level files key for inclusion
This commit is contained in:
@@ -18,6 +18,8 @@ from pre_commit.util import parse_version
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
||||
check_string_regex = cfgv.check_and(cfgv.check_string, cfgv.check_regex)
|
||||
|
||||
|
||||
def check_type_tag(tag):
|
||||
if tag not in ALL_TAGS:
|
||||
@@ -53,12 +55,8 @@ MANIFEST_HOOK_DICT = cfgv.Map(
|
||||
cfgv.Required('language', cfgv.check_one_of(all_languages)),
|
||||
cfgv.Optional('alias', cfgv.check_string, ''),
|
||||
|
||||
cfgv.Optional(
|
||||
'files', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '',
|
||||
),
|
||||
cfgv.Optional(
|
||||
'exclude', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '^$',
|
||||
),
|
||||
cfgv.Optional('files', check_string_regex, ''),
|
||||
cfgv.Optional('exclude', check_string_regex, '^$'),
|
||||
cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),
|
||||
cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),
|
||||
|
||||
@@ -260,7 +258,8 @@ CONFIG_SCHEMA = cfgv.Map(
|
||||
cfgv.check_array(cfgv.check_one_of(C.STAGES)),
|
||||
C.STAGES,
|
||||
),
|
||||
cfgv.Optional('exclude', cfgv.check_regex, '^$'),
|
||||
cfgv.Optional('files', check_string_regex, ''),
|
||||
cfgv.Optional('exclude', check_string_regex, '^$'),
|
||||
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
||||
cfgv.Optional(
|
||||
'minimum_pre_commit_version',
|
||||
@@ -272,6 +271,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
||||
'repos',
|
||||
'default_language_version',
|
||||
'default_stages',
|
||||
'files',
|
||||
'exclude',
|
||||
'fail_fast',
|
||||
'minimum_pre_commit_version',
|
||||
|
||||
@@ -206,7 +206,9 @@ def _run_hooks(config, hooks, args, environ):
|
||||
skips = _get_skips(environ)
|
||||
cols = _compute_cols(hooks, args.verbose)
|
||||
filenames = _all_filenames(args)
|
||||
filenames = filter_by_include_exclude(filenames, '', config['exclude'])
|
||||
filenames = filter_by_include_exclude(
|
||||
filenames, config['files'], config['exclude'],
|
||||
)
|
||||
classifier = Classifier(filenames)
|
||||
retval = 0
|
||||
for hook in hooks:
|
||||
|
||||
@@ -180,6 +180,22 @@ def test_global_exclude(cap_out, store, tempdir_factory):
|
||||
assert printed.endswith(expected)
|
||||
|
||||
|
||||
def test_global_files(cap_out, store, tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(git_path):
|
||||
with modify_config() as config:
|
||||
config['files'] = '^bar.py$'
|
||||
open('foo.py', 'a').close()
|
||||
open('bar.py', 'a').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
opts = run_opts(verbose=True)
|
||||
ret, printed = _do_run(cap_out, store, git_path, opts)
|
||||
assert ret == 0
|
||||
# Does not contain foo.py since it was not included
|
||||
expected = b'hookid: bash_hook\n\nbar.py\nHello World\n\n'
|
||||
assert printed.endswith(expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('args', 'expected_out'),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user