File tree Expand file tree Collapse file tree 2 files changed +15
-12
lines changed
Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 11import functools
22import os
3+ import os .path
34import pkg_resources
45import re
56from plumbum import local
@@ -57,14 +58,13 @@ def get_files_matching(all_file_list_strategy):
5758 @memoize_by_cwd
5859 def wrapper (expr ):
5960 regex = re .compile (expr )
60- return set (
61+ return set (filter ( os . path . exists , (
6162 filename
6263 for filename in all_file_list_strategy ()
6364 if regex .search (filename )
64- )
65+ )))
6566 return wrapper
6667
6768
68-
6969get_staged_files_matching = get_files_matching (get_staged_files )
7070get_all_files_matching = get_files_matching (get_all_files )
Original file line number Diff line number Diff line change @@ -42,9 +42,9 @@ def test_remove_pre_commit(empty_git_dir):
4242def get_files_matching_func ():
4343 def get_filenames ():
4444 return (
45- 'foo .py' ,
46- 'bar/baz .py' ,
47- 'tests/baz_test .py' ,
45+ 'pre_commit/run .py' ,
46+ 'pre_commit/git .py' ,
47+ 'im_a_file_that_doesnt_exist .py' ,
4848 'manifest.yaml' ,
4949 )
5050
@@ -54,22 +54,25 @@ def get_filenames():
5454def test_get_files_matching_base (get_files_matching_func ):
5555 ret = get_files_matching_func ('' )
5656 assert ret == set ([
57- 'foo.py' ,
58- 'bar/baz.py' ,
59- 'tests/baz_test.py' ,
57+ 'pre_commit/run.py' ,
58+ 'pre_commit/git.py' ,
6059 'manifest.yaml' ,
6160 ])
6261
6362
6463def test_get_files_matching_total_match (get_files_matching_func ):
6564 ret = get_files_matching_func ('^.*\.py$' )
6665 assert ret == set ([
67- 'foo.py' ,
68- 'bar/baz.py' ,
69- 'tests/baz_test.py' ,
66+ 'pre_commit/run.py' ,
67+ 'pre_commit/git.py' ,
7068 ])
7169
7270
7371def test_does_search_instead_of_match (get_files_matching_func ):
7472 ret = get_files_matching_func ('\.yaml$' )
7573 assert ret == set (['manifest.yaml' ])
74+
75+
76+ def test_does_not_include_deleted_fileS (get_files_matching_func ):
77+ ret = get_files_matching_func ('exist.py' )
78+ assert ret == set ()
You can’t perform that action at this time.
0 commit comments