From 2cbabf90cc2b7544706f741610908b6a2920199c Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Fri, 18 Feb 2022 23:51:58 -0800 Subject: [PATCH] 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. --- pre_commit_hooks/check_executables_have_shebangs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py index 6b5402ac..d8e4f490 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