MCPcopy Index your code
hub / github.com/openai/plugins / git_command

Function git_command

plugins/codex-security/scripts/workbench_target.py:41–71  ·  view source on GitHub ↗
(
    target: Path,
    *args: str,
    text: bool,
    git_dir: Path | None = None,
    work_tree: Path | None = None,
)

Source from the content-addressed store, hash-verified

39
40
41def git_command(
42 target: Path,
43 *args: str,
44 text: bool,
45 git_dir: Path | None = None,
46 work_tree: Path | None = None,
47) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
48 if (git_dir is None) != (work_tree is None):
49 raise ValueError("git_dir and work_tree must be provided together")
50 environment = os.environ.copy()
51 for name in GIT_REPOSITORY_ENVIRONMENT:
52 environment.pop(name, None)
53 environment["GIT_LITERAL_PATHSPECS"] = "1"
54 # Repository-local config is untrusted; fsmonitor may name an executable hook.
55 command = ["git", "-c", "core.fsmonitor=false", "-C", str(target)]
56 if git_dir is not None and work_tree is not None:
57 command.extend(["--git-dir", str(git_dir), "--work-tree", str(work_tree)])
58 full_command = [*command, *args]
59 try:
60 return subprocess.run(
61 full_command,
62 check=False,
63 capture_output=True,
64 env=environment,
65 text=text,
66 )
67 except FileNotFoundError:
68 # Git is optional for Codebase scans. Treat an unavailable executable like
69 # any other failed Git probe so the target falls back to a directory snapshot.
70 empty_output = "" if text else b""
71 return subprocess.CompletedProcess(full_command, 127, empty_output, empty_output)
72
73
74def update_digest_field(digest: Any, label: bytes, value: bytes) -> None:

Callers 3

git_outputFunction · 0.85
git_bytesFunction · 0.85

Calls 2

extendMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected