summaryrefslogtreecommitdiffstats
path: root/pre_commit_hooks/check_executables_have_shebangs.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit_hooks/check_executables_have_shebangs.py')
-rw-r--r--pre_commit_hooks/check_executables_have_shebangs.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py
index 34af5ca..d8e4f49 100644
--- a/pre_commit_hooks/check_executables_have_shebangs.py
+++ b/pre_commit_hooks/check_executables_have_shebangs.py
@@ -1,13 +1,12 @@
"""Check that executable text files have a shebang."""
+from __future__ import annotations
+
import argparse
import shlex
import sys
from typing import Generator
-from typing import List
from typing import NamedTuple
-from typing import Optional
from typing import Sequence
-from typing import Set
from pre_commit_hooks.util import cmd_output
from pre_commit_hooks.util import zsplit
@@ -15,8 +14,11 @@ from pre_commit_hooks.util import zsplit
EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))
-def check_executables(paths: List[str]) -> int:
- if sys.platform == 'win32': # pragma: win32 cover
+def check_executables(paths: list[str]) -> int:
+ 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
@@ -42,7 +44,7 @@ def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
def _check_git_filemode(paths: Sequence[str]) -> int:
- seen: Set[str] = set()
+ seen: set[str] = set()
for ls_file in git_ls_files(paths):
is_executable = any(b in EXECUTABLE_VALUES for b in ls_file.mode[-3:])
if is_executable and not has_shebang(ls_file.filename):
@@ -71,7 +73,7 @@ def _message(path: str) -> None:
)
-def main(argv: Optional[Sequence[str]] = None) -> int:
+def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)