From 89ab609732ab5dfdcdc1ed7a374cf5c45126e523 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 25 Nov 2020 18:21:37 -0800 Subject: [PATCH] fix the default value for types_or --- pre_commit/clientlib.py | 2 +- pre_commit/commands/run.py | 6 +++++- tests/commands/run_test.py | 21 +++++++++++++++++++++ tests/repository_test.py | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index d619ea52..20d44925 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -61,7 +61,7 @@ MANIFEST_HOOK_DICT = cfgv.Map( cfgv.Optional('files', check_string_regex, ''), cfgv.Optional('exclude', check_string_regex, '^$'), cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']), - cfgv.Optional('types_or', cfgv.check_array(check_type_tag), ['file']), + cfgv.Optional('types_or', cfgv.check_array(check_type_tag), []), cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []), cfgv.Optional( diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 508b61a3..1e8fad23 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -92,7 +92,11 @@ class Classifier: ret = [] for filename in names: tags = self._types_for_file(filename) - if tags >= types and tags & types_or and not tags & exclude_types: + if ( + tags >= types and + (not types_or or tags & types_or) and + not tags & exclude_types + ): ret.append(filename) return ret diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 34f3a375..b4491d01 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -964,6 +964,27 @@ def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir): assert classifier.filenames == [r'a/b\c'] +def test_classifier_empty_types_or(tmpdir): + tmpdir.join('bar').ensure() + tmpdir.join('foo').mksymlinkto('bar') + with tmpdir.as_cwd(): + classifier = Classifier(('foo', 'bar')) + for_symlink = classifier.by_types( + classifier.filenames, + types=['symlink'], + types_or=[], + exclude_types=[], + ) + for_file = classifier.by_types( + classifier.filenames, + types=['file'], + types_or=[], + exclude_types=[], + ) + assert for_symlink == ['foo'] + assert for_file == ['bar'] + + @pytest.fixture def some_filenames(): return ( diff --git a/tests/repository_test.py b/tests/repository_test.py index 8d771458..d513cb71 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -901,7 +901,7 @@ def test_manifest_hooks(tempdir_factory, store): 'post-commit', 'manual', 'post-checkout', 'push', ), types=['file'], - types_or=['file'], + types_or=[], verbose=False, )