mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #767 from pre-commit/consistent_ordering
Consistent ordering of filenames
This commit is contained in:
commit
31e751f4d3
2 changed files with 11 additions and 11 deletions
|
|
@ -38,14 +38,14 @@ def _hook_msg_start(hook, verbose):
|
||||||
|
|
||||||
def _filter_by_include_exclude(filenames, include, exclude):
|
def _filter_by_include_exclude(filenames, include, exclude):
|
||||||
include_re, exclude_re = re.compile(include), re.compile(exclude)
|
include_re, exclude_re = re.compile(include), re.compile(exclude)
|
||||||
return {
|
return [
|
||||||
filename for filename in filenames
|
filename for filename in filenames
|
||||||
if (
|
if (
|
||||||
include_re.search(filename) and
|
include_re.search(filename) and
|
||||||
not exclude_re.search(filename) and
|
not exclude_re.search(filename) and
|
||||||
os.path.lexists(filename)
|
os.path.lexists(filename)
|
||||||
)
|
)
|
||||||
}
|
]
|
||||||
|
|
||||||
|
|
||||||
def _filter_by_types(filenames, types, exclude_types):
|
def _filter_by_types(filenames, types, exclude_types):
|
||||||
|
|
|
||||||
|
|
@ -770,19 +770,19 @@ def test_fail_fast(
|
||||||
def some_filenames():
|
def some_filenames():
|
||||||
return (
|
return (
|
||||||
'.pre-commit-hooks.yaml',
|
'.pre-commit-hooks.yaml',
|
||||||
'pre_commit/main.py',
|
|
||||||
'pre_commit/git.py',
|
|
||||||
'im_a_file_that_doesnt_exist.py',
|
'im_a_file_that_doesnt_exist.py',
|
||||||
|
'pre_commit/git.py',
|
||||||
|
'pre_commit/main.py',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_include_exclude_base_case(some_filenames):
|
def test_include_exclude_base_case(some_filenames):
|
||||||
ret = _filter_by_include_exclude(some_filenames, '', '^$')
|
ret = _filter_by_include_exclude(some_filenames, '', '^$')
|
||||||
assert ret == {
|
assert ret == [
|
||||||
'.pre-commit-hooks.yaml',
|
'.pre-commit-hooks.yaml',
|
||||||
'pre_commit/main.py',
|
|
||||||
'pre_commit/git.py',
|
'pre_commit/git.py',
|
||||||
}
|
'pre_commit/main.py',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@xfailif_no_symlink
|
@xfailif_no_symlink
|
||||||
|
|
@ -790,19 +790,19 @@ def test_matches_broken_symlink(tmpdir): # pragma: no cover (non-windows)
|
||||||
with tmpdir.as_cwd():
|
with tmpdir.as_cwd():
|
||||||
os.symlink('does-not-exist', 'link')
|
os.symlink('does-not-exist', 'link')
|
||||||
ret = _filter_by_include_exclude({'link'}, '', '^$')
|
ret = _filter_by_include_exclude({'link'}, '', '^$')
|
||||||
assert ret == {'link'}
|
assert ret == ['link']
|
||||||
|
|
||||||
|
|
||||||
def test_include_exclude_total_match(some_filenames):
|
def test_include_exclude_total_match(some_filenames):
|
||||||
ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$')
|
ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$')
|
||||||
assert ret == {'pre_commit/main.py', 'pre_commit/git.py'}
|
assert ret == ['pre_commit/git.py', 'pre_commit/main.py']
|
||||||
|
|
||||||
|
|
||||||
def test_include_exclude_does_search_instead_of_match(some_filenames):
|
def test_include_exclude_does_search_instead_of_match(some_filenames):
|
||||||
ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$')
|
ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$')
|
||||||
assert ret == {'.pre-commit-hooks.yaml'}
|
assert ret == ['.pre-commit-hooks.yaml']
|
||||||
|
|
||||||
|
|
||||||
def test_include_exclude_exclude_removes_files(some_filenames):
|
def test_include_exclude_exclude_removes_files(some_filenames):
|
||||||
ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
|
ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
|
||||||
assert ret == {'.pre-commit-hooks.yaml'}
|
assert ret == ['.pre-commit-hooks.yaml']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue