mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
Target files by type as well as path regex
This commit is contained in:
parent
a4e9394cc7
commit
81b66cda74
3 changed files with 118 additions and 24 deletions
|
|
@ -58,18 +58,18 @@ def test_cherry_pick_conflict(in_merge_conflict):
|
|||
def get_files_matching_func():
|
||||
def get_filenames():
|
||||
return (
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
'im_a_file_that_doesnt_exist.py',
|
||||
'testing/test_symlink',
|
||||
'hooks.yaml',
|
||||
('pre_commit/main.py', git.GIT_MODE_FILE),
|
||||
('pre_commit/git.py', git.GIT_MODE_FILE),
|
||||
('im_a_file_that_doesnt_exist.py', git.GIT_MODE_FILE),
|
||||
('testing/test_symlink', git.GIT_MODE_SYMLINK),
|
||||
('hooks.yaml', git.GIT_MODE_FILE),
|
||||
)
|
||||
|
||||
return git.get_files_matching(get_filenames)
|
||||
|
||||
|
||||
def test_get_files_matching_base(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '^$')
|
||||
ret = get_files_matching_func('', '^$', frozenset(['file', 'symlink']))
|
||||
assert ret == set([
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
|
|
@ -79,7 +79,7 @@ def test_get_files_matching_base(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$', '^$', frozenset(['file']))
|
||||
assert ret == set([
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
|
|
@ -87,17 +87,17 @@ def test_get_files_matching_total_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$', '^$', frozenset(['file']))
|
||||
assert ret == set(['hooks.yaml'])
|
||||
|
||||
|
||||
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||
ret = get_files_matching_func('exist.py', '^$')
|
||||
def test_does_not_include_deleted_files(get_files_matching_func):
|
||||
ret = get_files_matching_func('exist.py', '^$', frozenset(['file']))
|
||||
assert ret == set()
|
||||
|
||||
|
||||
def test_exclude_removes_files(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '\\.py$')
|
||||
ret = get_files_matching_func('', '\\.py$', frozenset(['file', 'symlink']))
|
||||
assert ret == set(['hooks.yaml', 'testing/test_symlink'])
|
||||
|
||||
|
||||
|
|
@ -114,12 +114,17 @@ def test_get_conflicted_files(in_merge_conflict):
|
|||
cmd_output('git', 'add', 'other_file')
|
||||
|
||||
ret = set(git.get_conflicted_files())
|
||||
assert ret == set(('conflict_file', 'other_file'))
|
||||
assert ret == set([
|
||||
('conflict_file', git.GIT_MODE_FILE),
|
||||
('other_file', git.GIT_MODE_FILE),
|
||||
])
|
||||
|
||||
|
||||
def test_get_conflicted_files_in_submodule(in_conflicting_submodule):
|
||||
resolve_conflict()
|
||||
assert set(git.get_conflicted_files()) == set(('conflict_file',))
|
||||
assert set(git.get_conflicted_files()) == set([
|
||||
('conflict_file', git.GIT_MODE_FILE)],
|
||||
)
|
||||
|
||||
|
||||
def test_get_conflicted_files_unstaged_files(in_merge_conflict):
|
||||
|
|
@ -132,7 +137,9 @@ def test_get_conflicted_files_unstaged_files(in_merge_conflict):
|
|||
bar_only_file.write('new contents!\n')
|
||||
|
||||
ret = set(git.get_conflicted_files())
|
||||
assert ret == set(('conflict_file',))
|
||||
assert ret == set([
|
||||
('conflict_file', git.GIT_MODE_FILE),
|
||||
])
|
||||
|
||||
|
||||
MERGE_MSG = "Merge branch 'foo' into bar\n\nConflicts:\n\tconflict_file\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue