mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Actually use the exclude pattern. Closes #47.
This commit is contained in:
parent
ac67af21ec
commit
535be5b33a
3 changed files with 17 additions and 8 deletions
|
|
@ -40,12 +40,16 @@ def get_all_files():
|
||||||
def get_files_matching(all_file_list_strategy):
|
def get_files_matching(all_file_list_strategy):
|
||||||
@functools.wraps(all_file_list_strategy)
|
@functools.wraps(all_file_list_strategy)
|
||||||
@memoize_by_cwd
|
@memoize_by_cwd
|
||||||
def wrapper(expr):
|
def wrapper(include_expr, exclude_expr):
|
||||||
regex = re.compile(expr)
|
include_regex = re.compile(include_expr)
|
||||||
|
exclude_regex = re.compile(exclude_expr)
|
||||||
return set(filter(os.path.exists, (
|
return set(filter(os.path.exists, (
|
||||||
filename
|
filename
|
||||||
for filename in all_file_list_strategy()
|
for filename in all_file_list_strategy()
|
||||||
if regex.search(filename)
|
if (
|
||||||
|
include_regex.search(filename) and
|
||||||
|
not exclude_regex.search(filename)
|
||||||
|
)
|
||||||
)))
|
)))
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def _run_single_hook(runner, repository, hook_id, all_files=False):
|
||||||
retcode, stdout, stderr = repository.run_hook(
|
retcode, stdout, stderr = repository.run_hook(
|
||||||
runner.cmd_runner,
|
runner.cmd_runner,
|
||||||
hook_id,
|
hook_id,
|
||||||
get_filenames(hook['files']),
|
get_filenames(hook['files'], hook['exclude']),
|
||||||
)
|
)
|
||||||
|
|
||||||
if retcode != repository.hooks[hook_id]['expected_return_value']:
|
if retcode != repository.hooks[hook_id]['expected_return_value']:
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ def get_files_matching_func():
|
||||||
|
|
||||||
|
|
||||||
def test_get_files_matching_base(get_files_matching_func):
|
def test_get_files_matching_base(get_files_matching_func):
|
||||||
ret = get_files_matching_func('')
|
ret = get_files_matching_func('', '^$')
|
||||||
assert ret == set([
|
assert ret == set([
|
||||||
'pre_commit/run.py',
|
'pre_commit/run.py',
|
||||||
'pre_commit/git.py',
|
'pre_commit/git.py',
|
||||||
|
|
@ -38,7 +38,7 @@ def test_get_files_matching_base(get_files_matching_func):
|
||||||
|
|
||||||
|
|
||||||
def test_get_files_matching_total_match(get_files_matching_func):
|
def test_get_files_matching_total_match(get_files_matching_func):
|
||||||
ret = get_files_matching_func('^.*\.py$')
|
ret = get_files_matching_func('^.*\.py$', '^$')
|
||||||
assert ret == set([
|
assert ret == set([
|
||||||
'pre_commit/run.py',
|
'pre_commit/run.py',
|
||||||
'pre_commit/git.py',
|
'pre_commit/git.py',
|
||||||
|
|
@ -46,10 +46,15 @@ def test_get_files_matching_total_match(get_files_matching_func):
|
||||||
|
|
||||||
|
|
||||||
def test_does_search_instead_of_match(get_files_matching_func):
|
def test_does_search_instead_of_match(get_files_matching_func):
|
||||||
ret = get_files_matching_func('\.yaml$')
|
ret = get_files_matching_func('\.yaml$', '^$')
|
||||||
assert ret == set(['hooks.yaml'])
|
assert ret == set(['hooks.yaml'])
|
||||||
|
|
||||||
|
|
||||||
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||||
ret = get_files_matching_func('exist.py')
|
ret = get_files_matching_func('exist.py', '^$')
|
||||||
assert ret == set()
|
assert ret == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_exclude_removes_files(get_files_matching_func):
|
||||||
|
ret = get_files_matching_func('', '\.py$')
|
||||||
|
assert ret == set(['hooks.yaml'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue