Check Git core.fileMode rather than infer from OS.
There was already a guard preventing the check-executables-have-shebangs
hook from raising false positives on win32 by looking up the Git file
mode rather than relying on the file mode in the file system. Git already
automatically probes the file system for executable bit support. Leverage
Git's core.fileMode config variable to prevent false positives on all
file systems that don't track executable bits.
diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py
index 6b5402a..d8e4f49 100644
--- a/pre_commit_hooks/check_executables_have_shebangs.py
+++ b/pre_commit_hooks/check_executables_have_shebangs.py
@@ -15,7 +15,10 @@
def check_executables(paths: list[str]) -> int:
- if sys.platform == 'win32': # pragma: win32 cover
+ fs_tracks_executable_bit = cmd_output(
+ 'git', 'config', 'core.fileMode', retcode=None,
+ ).strip()
+ if fs_tracks_executable_bit == 'false': # pragma: win32 cover
return _check_git_filemode(paths)
else: # pragma: win32 no cover
retv = 0