diff --git a/pre_commit/git.py b/pre_commit/git.py index 17b7af13..796a0b8a 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -89,7 +89,7 @@ def get_files_matching(all_file_list_strategy): if ( include_regex.search(filename) and not exclude_regex.search(filename) and - os.path.exists(filename) + os.path.lexists(filename) ) ) return wrapper diff --git a/testing/test_symlink b/testing/test_symlink new file mode 120000 index 00000000..ee1f6cb7 --- /dev/null +++ b/testing/test_symlink @@ -0,0 +1 @@ +does_not_exist \ No newline at end of file diff --git a/tests/git_test.py b/tests/git_test.py index 084c15b2..c4e01450 100644 --- a/tests/git_test.py +++ b/tests/git_test.py @@ -61,6 +61,7 @@ def get_files_matching_func(): 'pre_commit/main.py', 'pre_commit/git.py', 'im_a_file_that_doesnt_exist.py', + 'testing/test_symlink', 'hooks.yaml', ) @@ -73,6 +74,7 @@ def test_get_files_matching_base(get_files_matching_func): 'pre_commit/main.py', 'pre_commit/git.py', 'hooks.yaml', + 'testing/test_symlink' ]) @@ -96,7 +98,7 @@ def test_does_not_include_deleted_fileS(get_files_matching_func): def test_exclude_removes_files(get_files_matching_func): ret = get_files_matching_func('', '\\.py$') - assert ret == set(['hooks.yaml']) + assert ret == set(['hooks.yaml', 'testing/test_symlink']) def resolve_conflict():