# Path: pre_commit/git.py
# NO_FS_MONITOR = ('-c', 'core.useBuiltinFSMonitor=false')
# def zsplit(s: str) -> list[str]:
# def no_git_env(
#         _env: MutableMapping[str, str] | None = None,
# ) -> dict[str, str]:
# def get_root() -> str:
# def get_git_dir(git_root: str = '.') -> str:
# def get_remote_url(git_root: str) -> str:
# def is_in_merge_conflict() -> bool:
# def parse_merge_msg_for_conflicts(merge_msg: bytes) -> list[str]:
# def get_conflicted_files() -> set[str]:
# def get_staged_files(cwd: str | None = None) -> list[str]:
# def intent_to_add_files() -> list[str]:
# def get_all_files() -> list[str]:
# def get_changed_files(old: str, new: str) -> list[str]:
# def head_rev(remote: str) -> str:
# def has_diff(*args: str, repo: str = '.') -> bool:
# def has_core_hookpaths_set() -> bool:
# def init_repo(path: str, remote: str) -> None:
# def commit(repo: str = '.') -> None:
# def git_path(name: str, repo: str = '.') -> str:
# def check_for_cygwin_mismatch() -> None:
# 
# Path: pre_commit/staged_files_only.py
# @contextlib.contextmanager
# def staged_files_only(patch_dir: str) -> Generator[None, None, None]:
#     """Clear any unstaged changes from the git working directory inside this
#     context.
#     """
#     with _intent_to_add_cleared(), _unstaged_changes_cleared(patch_dir):
#         yield
# 
# Path: pre_commit/util.py
# def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
#     returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
#     stdout = stdout_b.decode() if stdout_b is not None else None
#     stderr = stderr_b.decode() if stderr_b is not None else None
#     return returncode, stdout, stderr
# 
# Path: testing/auto_namedtuple.py
# def auto_namedtuple(classname='auto_namedtuple', **kwargs):
#     """Returns an automatic namedtuple object.
# 
#     Args:
#         classname - The class name for the returned object.
#         **kwargs - Properties to give the returned object.
#     """
#     return (collections.namedtuple(classname, kwargs.keys())(**kwargs))
# 
# Path: testing/fixtures.py
# def git_dir(tempdir_factory):
#     path = tempdir_factory.get()
#     cmd_output('git', 'init', path)
#     return path
# 
# Path: testing/util.py
# @contextlib.contextmanager
# def cwd(path):
#     original_cwd = os.getcwd()
#     os.chdir(path)
#     try:
#         yield
#     finally:
#         os.chdir(original_cwd)
# 
# Path: testing/util.py
# def get_resource_path(path):
#     return os.path.join(TESTING_DIR, 'resources', path)
# 
# Path: testing/util.py
# def git_commit(*args, fn=cmd_output, msg='commit!', all_files=True, **kwargs):
#     kwargs.setdefault('stderr', subprocess.STDOUT)
# 
#     cmd = ('git', 'commit', '--allow-empty', '--no-gpg-sign', *args)
#     if all_files:  # allow skipping `-a` with `all_files=False`
#         cmd += ('-a',)
#     if msg is not None:  # allow skipping `-m` with `msg=None`
#         cmd += ('-m', msg)
#     ret, out, _ = fn(*cmd, **kwargs)
#     return ret, out.replace('\r\n', '\n')


import itertools
import os.path
import shutil
import pytest
from pre_commit import git
from pre_commit.staged_files_only import staged_files_only
from pre_commit.util import cmd_output
from testing.auto_namedtuple import auto_namedtuple
from testing.fixtures import git_dir
from testing.util import cwd
from testing.util import get_resource_path
from testing.util import git_commit
    line_parts = [line.split() for line in git_status.splitlines()]
    return {v: k for k, v in line_parts}


@pytest.fixture
def foo_staged(in_git_dir):
    foo = in_git_dir.join('foo')
    foo.write(FOO_CONTENTS)
    cmd_output('git', 'add', 'foo')
    yield auto_namedtuple(path=in_git_dir.strpath, foo_filename=foo.strpath)


def _test_foo_state(
        path,
        foo_contents=FOO_CONTENTS,
        status='A',
        encoding='UTF-8',
):
    assert os.path.exists(path.foo_filename)
    with open(path.foo_filename, encoding=encoding) as f:
        assert f.read() == foo_contents
    actual_status = get_short_git_status()['foo']
    assert status == actual_status


def test_foo_staged(foo_staged):
    _test_foo_state(foo_staged)


def test_foo_nothing_unstaged(foo_staged, patch_dir):

# Path: pre_commit/git.py
# NO_FS_MONITOR = ('-c', 'core.useBuiltinFSMonitor=false')
# def zsplit(s: str) -> list[str]:
# def no_git_env(
#         _env: MutableMapping[str, str] | None = None,
# ) -> dict[str, str]:
# def get_root() -> str:
# def get_git_dir(git_root: str = '.') -> str:
# def get_remote_url(git_root: str) -> str:
# def is_in_merge_conflict() -> bool:
# def parse_merge_msg_for_conflicts(merge_msg: bytes) -> list[str]:
# def get_conflicted_files() -> set[str]:
# def get_staged_files(cwd: str | None = None) -> list[str]:
# def intent_to_add_files() -> list[str]:
# def get_all_files() -> list[str]:
# def get_changed_files(old: str, new: str) -> list[str]:
# def head_rev(remote: str) -> str:
# def has_diff(*args: str, repo: str = '.') -> bool:
# def has_core_hookpaths_set() -> bool:
# def init_repo(path: str, remote: str) -> None:
# def commit(repo: str = '.') -> None:
# def git_path(name: str, repo: str = '.') -> str:
# def check_for_cygwin_mismatch() -> None:
# 
# Path: pre_commit/staged_files_only.py
# @contextlib.contextmanager
# def staged_files_only(patch_dir: str) -> Generator[None, None, None]:
#     """Clear any unstaged changes from the git working directory inside this
#     context.
#     """
#     with _intent_to_add_cleared(), _unstaged_changes_cleared(patch_dir):
#         yield
# 
# Path: pre_commit/util.py
# def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
#     returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
#     stdout = stdout_b.decode() if stdout_b is not None else None
#     stderr = stderr_b.decode() if stderr_b is not None else None
#     return returncode, stdout, stderr
# 
# Path: testing/auto_namedtuple.py
# def auto_namedtuple(classname='auto_namedtuple', **kwargs):
#     """Returns an automatic namedtuple object.
# 
#     Args:
#         classname - The class name for the returned object.
#         **kwargs - Properties to give the returned object.
#     """
#     return (collections.namedtuple(classname, kwargs.keys())(**kwargs))
# 
# Path: testing/fixtures.py
# def git_dir(tempdir_factory):
#     path = tempdir_factory.get()
#     cmd_output('git', 'init', path)
#     return path
# 
# Path: testing/util.py
# @contextlib.contextmanager
# def cwd(path):
#     original_cwd = os.getcwd()
#     os.chdir(path)
#     try:
#         yield
#     finally:
#         os.chdir(original_cwd)
# 
# Path: testing/util.py
# def get_resource_path(path):
#     return os.path.join(TESTING_DIR, 'resources', path)
# 
# Path: testing/util.py
# def git_commit(*args, fn=cmd_output, msg='commit!', all_files=True, **kwargs):
#     kwargs.setdefault('stderr', subprocess.STDOUT)
# 
#     cmd = ('git', 'commit', '--allow-empty', '--no-gpg-sign', *args)
#     if all_files:  # allow skipping `-a` with `all_files=False`
#         cmd += ('-a',)
#     if msg is not None:  # allow skipping `-m` with `msg=None`
#         cmd += ('-m', msg)
#     ret, out, _ = fn(*cmd, **kwargs)
#     return ret, out.replace('\r\n', '\n')


# Path: tests/staged_files_only_test.py
import itertools
import os.path
import shutil
import pytest
from pre_commit import git
from pre_commit.staged_files_only import staged_files_only
from pre_commit.util import cmd_output
from testing.auto_namedtuple import auto_namedtuple
from testing.fixtures import git_dir
from testing.util import cwd
from testing.util import get_resource_path
from testing.util import git_commit

    line_parts = [line.split() for line in git_status.splitlines()]
    return {v: k for k, v in line_parts}


@pytest.fixture
def foo_staged(in_git_dir):
    foo = in_git_dir.join('foo')
    foo.write(FOO_CONTENTS)
    cmd_output('git', 'add', 'foo')
    yield auto_namedtuple(path=in_git_dir.strpath, foo_filename=foo.strpath)


def _test_foo_state(
        path,
        foo_contents=FOO_CONTENTS,
        status='A',
        encoding='UTF-8',
):
    assert os.path.exists(path.foo_filename)
    with open(path.foo_filename, encoding=encoding) as f:
        assert f.read() == foo_contents
    actual_status = get_short_git_status()['foo']
    assert status == actual_status


def test_foo_staged(foo_staged):
    _test_foo_state(foo_staged)


def test_foo_nothing_unstaged(foo_staged, patch_dir):

    with staged_files_only(patch_dir):