1
0
Fork 0

Merging upstream version 2.8.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:22:33 +01:00
parent 6ea1883b99
commit da7a7a571b
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
65 changed files with 1119 additions and 189 deletions

View file

@ -3,12 +3,14 @@ import os.path
import sys
from typing import Dict
from typing import List
from typing import MutableMapping
from typing import Optional
from typing import Set
from pre_commit.errors import FatalError
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
from pre_commit.util import EnvironT
logger = logging.getLogger(__name__)
@ -22,7 +24,9 @@ def zsplit(s: str) -> List[str]:
return []
def no_git_env(_env: Optional[EnvironT] = None) -> Dict[str, str]:
def no_git_env(
_env: Optional[MutableMapping[str, str]] = None,
) -> Dict[str, str]:
# Too many bugs dealing with environment variables and GIT:
# https://github.com/pre-commit/pre-commit/issues/300
# In git 2.6.3 (maybe others), git exports GIT_WORK_TREE while running
@ -43,7 +47,21 @@ def no_git_env(_env: Optional[EnvironT] = None) -> Dict[str, str]:
def get_root() -> str:
return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
try:
root = cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
except CalledProcessError:
raise FatalError(
'git failed. Is it installed, and are you in a Git repository '
'directory?',
)
else:
if root == '': # pragma: no cover (old git)
raise FatalError(
'git toplevel unexpectedly empty! make sure you are not '
'inside the `.git` directory of your repository.',
)
else:
return root
def get_git_dir(git_root: str = '.') -> str:
@ -181,7 +199,7 @@ def check_for_cygwin_mismatch() -> None:
"""See https://github.com/pre-commit/pre-commit/issues/354"""
if sys.platform in ('cygwin', 'win32'): # pragma: no cover (windows)
is_cygwin_python = sys.platform == 'cygwin'
toplevel = cmd_output('git', 'rev-parse', '--show-toplevel')[1]
toplevel = get_root()
is_cygwin_git = toplevel.startswith('/')
if is_cygwin_python ^ is_cygwin_git: