From 741d95128bc0700502e0598779121f320fb69af8 Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Fri, 23 Jul 2021 11:28:14 +0200 Subject: [PATCH] Fix false positives of check-executables-have-shebangs check-executables-have-shebangs needs to check the actual file mode known to Git and avoid relying only on the filesystem permissions, because some filesystems force the executable bit on every file (e.g. fat32 on Linux). --- .../check_executables_have_shebangs.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py index e271c66..08e13f4 100644 --- a/pre_commit_hooks/check_executables_have_shebangs.py +++ b/pre_commit_hooks/check_executables_have_shebangs.py @@ -16,16 +16,11 @@ EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7')) def check_executables(paths: List[str]) -> int: - if sys.platform == 'win32': # pragma: win32 cover - return _check_git_filemode(paths) - else: # pragma: win32 no cover - retv = 0 - for path in paths: - if not has_shebang(path): - _message(path) - retv = 1 - - return retv + # Even if this hook is configured to be called only on files flagged + # executable by identify, we must check the real filemode known to Git + # because some filesystems force the executable bit (e.g. fat32 under + # Linux). + return _check_git_filemode(paths) class GitLsFile(NamedTuple):