Spaces:
Sleeping
Sleeping
File size: 809 Bytes
ced1295 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | from __future__ import annotations
FORBIDDEN_GIT_VERBS = {
"reset",
"restore",
"push",
"rebase",
"clean",
"cherry-pick",
}
ALLOWED_GIT_VERBS = {"status", "diff", "log", "branch", "checkout", "merge", "add", "commit"}
def is_command_safe(parts: list[str]) -> bool:
if not parts:
return False
cmd = parts[0]
if cmd in {"pytest", "ls", "pwd"}:
return True
if cmd in {"python", "python3"}:
return len(parts) >= 3 and parts[1] == "-m" and parts[2] == "pytest"
if cmd == "git":
if len(parts) < 2:
return False
verb = parts[1]
if verb in FORBIDDEN_GIT_VERBS:
return False
if verb not in ALLOWED_GIT_VERBS:
return False
return "--hard" not in parts
return False
|