diff options
| author | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
| commit | 7aba3deae3ff17d032c37e07d2929d1426b34278 (patch) | |
| tree | 9c482f9acda1599bd2f9bed95a6a46b75e634e80 /plugins/claude-security/scripts/lib/git.py | |
| parent | 5472f5f56e0070feeeb464318b316714fe3e9105 (diff) | |
| parent | b8331dd69ab3e132bbf8cd6e89b5d8c1747e21b1 (diff) | |
Merge remote-tracking branch 'origin/main' into add-plugin/xcodeadd-plugin/xcode
Diffstat (limited to 'plugins/claude-security/scripts/lib/git.py')
| -rw-r--r-- | plugins/claude-security/scripts/lib/git.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/claude-security/scripts/lib/git.py b/plugins/claude-security/scripts/lib/git.py new file mode 100644 index 00000000..ded163d3 --- /dev/null +++ b/plugins/claude-security/scripts/lib/git.py @@ -0,0 +1,27 @@ +"""Read-only git calls for the scripts: one runner, prompts suppressed, output byte-faithful.""" + +from __future__ import annotations + +import os +import subprocess + +REDIRECTS = frozenset({"GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR"}) +ENV = {k: v for k, v in os.environ.items() if k not in REDIRECTS} | {"GIT_TERMINAL_PROMPT": "0"} + + +def run(cwd: str, *args: str) -> str | None: + """The stdout of `git -C <cwd> <args>` without trailing newlines; None on any failure.""" + try: + out = subprocess.run( + ["git", "-C", cwd, *args], + env=ENV, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + timeout=30, + check=False, + ) + except (OSError, subprocess.SubprocessError): + return None + if out.returncode != 0: + return None + return out.stdout.decode("utf-8", "surrogateescape").rstrip("\r\n") |
