Answer architecture round 1: 0 🔴, 3 🟡; type Effects.git, list the guards one per line, say how code_of guesses the worktree
This commit is contained in:
+15
-3
@@ -5,8 +5,18 @@ import subprocess
|
||||
|
||||
from failure import Failure
|
||||
|
||||
# A -c given here outranks the checkout's own config, which may allow one transport by name; GIT_NO_LAZY_FETCH needs git 2.44.
|
||||
GUARDS = [option for setting in ["core.fsmonitor=false", "log.showSignature=false", "protocol.allow=never", *(f"protocol.{name}.allow=never" for name in ("ext", "file", "git", "http", "https", "ssh"))] for option in ("-c", setting)]
|
||||
# The settings a guarded call gives git as -c options. A -c outranks the checkout's own config, which may allow one transport by name.
|
||||
GUARD_SETTINGS = [
|
||||
"core.fsmonitor=false",
|
||||
"log.showSignature=false",
|
||||
"protocol.allow=never",
|
||||
"protocol.ext.allow=never",
|
||||
"protocol.file.allow=never",
|
||||
"protocol.git.allow=never",
|
||||
"protocol.http.allow=never",
|
||||
"protocol.https.allow=never",
|
||||
"protocol.ssh.allow=never",
|
||||
]
|
||||
|
||||
|
||||
def git(*args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False) -> str | Failure:
|
||||
@@ -16,7 +26,9 @@ def git(*args: str, cwd: str | None = None, timeout: float | None = None, guarde
|
||||
guarded is for a checkout whose config may name a program, such as one rule-hook has not yet allowed a call to touch: no fsmonitor, no signature check, and no transport, so no fetch of a partial clone's missing objects either.
|
||||
"""
|
||||
command = " ".join(args)
|
||||
guards, env = (GUARDS, {**os.environ, "GIT_NO_LAZY_FETCH": "1"}) if guarded else ([], None)
|
||||
guards = [option for setting in GUARD_SETTINGS for option in ("-c", setting)] if guarded else []
|
||||
# GIT_NO_LAZY_FETCH needs git 2.44.
|
||||
env = {**os.environ, "GIT_NO_LAZY_FETCH": "1"} if guarded else None
|
||||
try:
|
||||
ran = subprocess.run(["git", *guards, *args], capture_output=True, cwd=cwd, encoding="utf-8", env=env, timeout=timeout)
|
||||
except UnicodeDecodeError as failure:
|
||||
|
||||
Reference in New Issue
Block a user