utils/app_errors/app_errors/tests/checkout.py
Krzysztof kuhy Rudnicki f05845e2f7 Read GitHub repo from checkout origin
feedback_inbox and app_errors guessed kuhyx/<folder> for a task's repo,
which filed cleanup-plate under kuhyx/cleanup-plate (real:
Sepci0/cleanup-plate) and showed phantom repos on the board. Both now
read the GitHub owner/name from ~/src/<folder>'s origin remote (https or
ssh forms) and fall back to the guess only when there is no checkout or
its origin is not on GitHub. app-errors 0.1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZfgt44aEKxvGBJkwP
2026-11-19 18:08:26 +01:00

21 lines
690 B
Python

"""A real git checkout in a temp dir, built without kuhy's git config."""
from __future__ import annotations
import os
from pathlib import Path
import shutil
import subprocess
GIT = shutil.which("git") or "git"
def make_checkout(path: Path, origin: str | None) -> Path:
"""Init a repo at ``path`` with remote ``origin`` (none when None)."""
env = {"PATH": os.environ["PATH"], "HOME": str(path.parent), "GIT_CONFIG_NOSYSTEM": "1"}
path.mkdir(parents=True)
subprocess.run([GIT, "init", "-q", str(path)], check=True, env=env)
if origin is not None:
subprocess.run([GIT, "-C", str(path), "remote", "add", "origin", origin], check=True, env=env)
return path