summaryrefslogtreecommitdiffstats
path: root/pre_commit/git.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:22:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:22:18 +0000
commit58a809aa43ae21566be4613eb42ac56faf54f901 (patch)
tree371b9cc8a265cbabea4b12e5508b8bde6edf0b89 /pre_commit/git.py
parentAdding upstream version 2.20.0. (diff)
downloadpre-commit-58a809aa43ae21566be4613eb42ac56faf54f901.tar.xz
pre-commit-58a809aa43ae21566be4613eb42ac56faf54f901.zip
Adding upstream version 2.21.0.upstream/2.21.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/git.py')
-rw-r--r--pre_commit/git.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/pre_commit/git.py b/pre_commit/git.py
index 35392b3..a76118f 100644
--- a/pre_commit/git.py
+++ b/pre_commit/git.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import logging
import os.path
import sys
-from typing import MutableMapping
+from typing import Mapping
from pre_commit.errors import FatalError
from pre_commit.util import CalledProcessError
@@ -24,9 +24,7 @@ def zsplit(s: str) -> list[str]:
return []
-def no_git_env(
- _env: MutableMapping[str, str] | None = None,
-) -> dict[str, str]:
+def no_git_env(_env: Mapping[str, str] | None = 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
@@ -44,6 +42,8 @@ def no_git_env(
'GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND', 'GIT_SSL_CAINFO',
'GIT_SSL_NO_VERIFY', 'GIT_CONFIG_COUNT',
'GIT_HTTP_PROXY_AUTHMETHOD',
+ 'GIT_ALLOW_PROTOCOL',
+ 'GIT_ASKPASS',
}
}
@@ -150,18 +150,10 @@ def get_staged_files(cwd: str | None = None) -> list[str]:
def intent_to_add_files() -> list[str]:
_, stdout, _ = cmd_output(
- 'git', 'status', '--ignore-submodules', '--porcelain', '-z',
+ 'git', 'diff', '--no-ext-diff', '--ignore-submodules',
+ '--diff-filter=A', '--name-only', '-z',
)
- parts = list(reversed(zsplit(stdout)))
- intent_to_add = []
- while parts:
- line = parts.pop()
- status, filename = line[:3], line[3:]
- if status[0] in {'C', 'R'}: # renames / moves have an additional arg
- parts.pop()
- if status[1] == 'A':
- intent_to_add.append(filename)
- return intent_to_add
+ return zsplit(stdout)
def get_all_files() -> list[str]:
@@ -187,11 +179,11 @@ def head_rev(remote: str) -> str:
def has_diff(*args: str, repo: str = '.') -> bool:
cmd = ('git', 'diff', '--quiet', '--no-ext-diff', *args)
- return cmd_output_b(*cmd, cwd=repo, retcode=None)[0] == 1
+ return cmd_output_b(*cmd, cwd=repo, check=False)[0] == 1
def has_core_hookpaths_set() -> bool:
- _, out, _ = cmd_output_b('git', 'config', 'core.hooksPath', retcode=None)
+ _, out, _ = cmd_output_b('git', 'config', 'core.hooksPath', check=False)
return bool(out.strip())