# Path: pre_commit_hooks/check_executables_have_shebangs.py
# EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
#     outs = cmd_output('git', 'ls-files', '-z', '--stage', '--', *paths)
#     for out in zsplit(outs):
#         metadata, filename = out.split('\t')
#         mode, _, _ = metadata.split()
#         yield GitLsFile(mode, filename)
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def has_shebang(path: str) -> int:
#     with open(path, 'rb') as f:
#         first_bytes = f.read(2)
# 
#     return first_bytes == b'#!'


import argparse
import shlex
import sys
from typing import Sequence
from pre_commit_hooks.check_executables_have_shebangs import EXECUTABLE_VALUES
from pre_commit_hooks.check_executables_have_shebangs import git_ls_files
from pre_commit_hooks.check_executables_have_shebangs import has_shebang
"""Check that text files with a shebang are executable."""
from __future__ import annotations




def check_shebangs(paths: list[str]) -> int:
    # Cannot optimize on non-executability here if we intend this check to
    # work on win32 -- and that's where problems caused by non-executability
    # (elsewhere) are most likely to arise from.
    return _check_git_filemode(paths)


def _check_git_filemode(paths: Sequence[str]) -> int:
    seen: set[str] = set()
    for ls_file in git_ls_files(paths):

# Path: pre_commit_hooks/check_executables_have_shebangs.py
# EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
#     outs = cmd_output('git', 'ls-files', '-z', '--stage', '--', *paths)
#     for out in zsplit(outs):
#         metadata, filename = out.split('\t')
#         mode, _, _ = metadata.split()
#         yield GitLsFile(mode, filename)
# 
# Path: pre_commit_hooks/check_executables_have_shebangs.py
# def has_shebang(path: str) -> int:
#     with open(path, 'rb') as f:
#         first_bytes = f.read(2)
# 
#     return first_bytes == b'#!'


# Path: pre_commit_hooks/check_shebang_scripts_are_executable.py
import argparse
import shlex
import sys
from typing import Sequence
from pre_commit_hooks.check_executables_have_shebangs import EXECUTABLE_VALUES
from pre_commit_hooks.check_executables_have_shebangs import git_ls_files
from pre_commit_hooks.check_executables_have_shebangs import has_shebang

"""Check that text files with a shebang are executable."""
from __future__ import annotations




def check_shebangs(paths: list[str]) -> int:
    # Cannot optimize on non-executability here if we intend this check to
    # work on win32 -- and that's where problems caused by non-executability
    # (elsewhere) are most likely to arise from.
    return _check_git_filemode(paths)


def _check_git_filemode(paths: Sequence[str]) -> int:
    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:])