Skip to content

Commit 35d3ed4

Browse files
committed
fix check-useless-excludes for exclude of broken symlink
1 parent a96bb23 commit 35d3ed4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pre_commit/meta_hooks/check_useless_excludes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def check_useless_excludes(config_file: str) -> int:
4343

4444
for repo in config['repos']:
4545
for hook in repo['hooks']:
46+
# the default of manifest hooks is `types: [file]` but we may
47+
# be configuring a symlink hook while there's a broken symlink
48+
hook.setdefault('types', [])
4649
# Not actually a manifest dict, but this more accurately reflects
4750
# the defaults applied during runtime
4851
hook = apply_defaults(hook, MANIFEST_HOOK_DICT)

tests/meta_hooks/check_useless_excludes_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from pre_commit import git
12
from pre_commit.meta_hooks import check_useless_excludes
3+
from pre_commit.util import cmd_output
24
from testing.fixtures import add_config_to_repo
5+
from testing.fixtures import make_config_from_repo
6+
from testing.fixtures import make_repo
7+
from testing.util import xfailif_windows
38

49

510
def test_useless_exclude_global(capsys, in_git_dir):
@@ -113,3 +118,20 @@ def test_valid_exclude(capsys, in_git_dir):
113118

114119
out, _ = capsys.readouterr()
115120
assert out == ''
121+
122+
123+
@xfailif_windows # pragma: win32 no cover
124+
def test_useless_excludes_broken_symlink(capsys, in_git_dir, tempdir_factory):
125+
path = make_repo(tempdir_factory, 'script_hooks_repo')
126+
config = make_config_from_repo(path)
127+
config['hooks'][0]['exclude'] = 'broken-symlink'
128+
add_config_to_repo(in_git_dir.strpath, config)
129+
130+
in_git_dir.join('broken-symlink').mksymlinkto('DNE')
131+
cmd_output('git', 'add', 'broken-symlink')
132+
git.commit()
133+
134+
assert check_useless_excludes.main(('.pre-commit-config.yaml',)) == 0
135+
136+
out, _ = capsys.readouterr()
137+
assert out == ''

0 commit comments

Comments
 (0)