# Path: pre_commit_hooks/util.py
# def added_files() -> set[str]:
#     cmd = ('git', 'diff', '--staged', '--name-only', '--diff-filter=A')
#     return set(cmd_output(*cmd).splitlines())
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout


import argparse
from typing import Iterable
from typing import Iterator
from typing import Sequence
from pre_commit_hooks.util import added_files
from pre_commit_hooks.util import cmd_output
from __future__ import annotations




def lower_set(iterable: Iterable[str]) -> set[str]:
    return {x.lower() for x in iterable}


def parents(file: str) -> Iterator[str]:
    path_parts = file.split('/')
    path_parts.pop()
    while path_parts:
        yield '/'.join(path_parts)
        path_parts.pop()


def directories_for(files: set[str]) -> set[str]:
    return {parent for file in files for parent in parents(file)}


def find_conflicting_filenames(filenames: Sequence[str]) -> int:
    repo_files = set(cmd_output('git', 'ls-files').splitlines())
    repo_files |= directories_for(repo_files)

# Path: pre_commit_hooks/util.py
# def added_files() -> set[str]:
#     cmd = ('git', 'diff', '--staged', '--name-only', '--diff-filter=A')
#     return set(cmd_output(*cmd).splitlines())
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout


# Path: pre_commit_hooks/check_case_conflict.py
import argparse
from typing import Iterable
from typing import Iterator
from typing import Sequence
from pre_commit_hooks.util import added_files
from pre_commit_hooks.util import cmd_output

from __future__ import annotations




def lower_set(iterable: Iterable[str]) -> set[str]:
    return {x.lower() for x in iterable}


def parents(file: str) -> Iterator[str]:
    path_parts = file.split('/')
    path_parts.pop()
    while path_parts:
        yield '/'.join(path_parts)
        path_parts.pop()


def directories_for(files: set[str]) -> set[str]:
    return {parent for file in files for parent in parents(file)}


def find_conflicting_filenames(filenames: Sequence[str]) -> int:
    repo_files = set(cmd_output('git', 'ls-files').splitlines())
    repo_files |= directories_for(repo_files)

    relevant_files = set(filenames) | added_files()