mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Don't pass deleted files to pre-commit scripts.
This commit is contained in:
parent
6649e180bb
commit
bef4a01af9
2 changed files with 15 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import re
|
import re
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
|
|
@ -57,14 +58,13 @@ def get_files_matching(all_file_list_strategy):
|
||||||
@memoize_by_cwd
|
@memoize_by_cwd
|
||||||
def wrapper(expr):
|
def wrapper(expr):
|
||||||
regex = re.compile(expr)
|
regex = re.compile(expr)
|
||||||
return set(
|
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 regex.search(filename)
|
||||||
)
|
)))
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_staged_files_matching = get_files_matching(get_staged_files)
|
get_staged_files_matching = get_files_matching(get_staged_files)
|
||||||
get_all_files_matching = get_files_matching(get_all_files)
|
get_all_files_matching = get_files_matching(get_all_files)
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ def test_remove_pre_commit(empty_git_dir):
|
||||||
def get_files_matching_func():
|
def get_files_matching_func():
|
||||||
def get_filenames():
|
def get_filenames():
|
||||||
return (
|
return (
|
||||||
'foo.py',
|
'pre_commit/run.py',
|
||||||
'bar/baz.py',
|
'pre_commit/git.py',
|
||||||
'tests/baz_test.py',
|
'im_a_file_that_doesnt_exist.py',
|
||||||
'manifest.yaml',
|
'manifest.yaml',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -54,9 +54,8 @@ 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([
|
||||||
'foo.py',
|
'pre_commit/run.py',
|
||||||
'bar/baz.py',
|
'pre_commit/git.py',
|
||||||
'tests/baz_test.py',
|
|
||||||
'manifest.yaml',
|
'manifest.yaml',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
@ -64,12 +63,16 @@ 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([
|
||||||
'foo.py',
|
'pre_commit/run.py',
|
||||||
'bar/baz.py',
|
'pre_commit/git.py',
|
||||||
'tests/baz_test.py',
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
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(['manifest.yaml'])
|
assert ret == set(['manifest.yaml'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||||
|
ret = get_files_matching_func('exist.py')
|
||||||
|
assert ret == set()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue