refactor: one git runner and main line fallback

core.gitclone gains required_git_lines, which raises GitRefused with
git's error, and fallback_lines, the remote lines tried when no remote
names the project. profile_sync and validate_pr use both.

profile_sync --changed without --base now also finds a clone whose main
line is upstream/master, upstream/v2, origin/master or origin/v2, as
validate_pr already did, before falling back to HEAD.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent 97af05db9a
commit 2f8f78b6b5
3 files changed
+46 -20

No files matched your search

+11 -11
View File
@@ -240,13 +240,12 @@ def build_parser() -> argparse.ArgumentParser:
def _git_lines(args: list[str]) -> list[str]:
result = subprocess.run(
["git", *args], capture_output=True, text=True, check=False
)
if result.returncode:
detail = result.stderr.strip() or f"exit {result.returncode}"
raise SystemExit(f"ERROR: git {' '.join(args)}: {detail}")
return [line for line in result.stdout.splitlines() if line]
from core.gitclone import GitRefused, required_git_lines
try:
return required_git_lines(*args)
except GitRefused as exc:
raise SystemExit(f"ERROR: {exc}") from exc
def branch_profiles(emulators_dir: str, base: str, added_only: bool) -> list[str]:
@@ -286,14 +285,15 @@ def project_base() -> str:
is HEAD, and --changed --strict found nothing and passed while the PR's
CI then failed. validate_pr.py resolves the same line the same way.
"""
from core.gitclone import git_lines as git_lines, project_main_line
from core.gitclone import fallback_lines, git_lines, project_main_line
line = project_main_line()
if line:
return line
for remote in ("upstream", "origin"):
if git_lines("rev-parse", "--verify", "--quiet", f"{remote}/main"):
return f"{remote}/main"
for candidates in fallback_lines():
for candidate in candidates:
if git_lines("rev-parse", "--verify", "--quiet", candidate):
return candidate
return "HEAD"