mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
fix: resolve the --changed base in one place
This commit is contained in:
1 parent
30113783c9
commit
d3d82dd296
5 files changed
+75
-25
No files matched your search
+2
-1
@@ -10,6 +10,7 @@ from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import ArtifactDirectoryMissing, ArtifactLockBusy
|
||||
from core.gitclone import MainLineUnreachable
|
||||
from core.paths import BIOS_DIR, DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
|
||||
|
||||
@@ -130,7 +131,7 @@ def run_cli(main: Callable[[], int | None]) -> None:
|
||||
code = main()
|
||||
sys.stdout.flush()
|
||||
except (InputMissing, SourceUnreadable, ArtifactLockBusy,
|
||||
ArtifactDirectoryMissing) as exc:
|
||||
ArtifactDirectoryMissing, MainLineUnreachable) as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except BrokenPipeError:
|
||||
|
||||
@@ -10,6 +10,10 @@ class GitRefused(RuntimeError):
|
||||
"""A git command that exited non-zero, with what it said."""
|
||||
|
||||
|
||||
class MainLineUnreachable(RuntimeError):
|
||||
"""The clone does not hold the project's main and cannot fetch it."""
|
||||
|
||||
|
||||
def _run(args: tuple[str, ...]) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(["git", *args], capture_output=True, text=True, check=False)
|
||||
|
||||
@@ -83,8 +87,23 @@ def project_main_line() -> str | None:
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
if fetched.returncode != 0:
|
||||
raise RuntimeError(
|
||||
raise MainLineUnreachable(
|
||||
f"this clone does not hold the main of {PROJECT_URLS[0]}, and "
|
||||
f"fetching its main from {source} failed: {fetched.stderr.strip()}"
|
||||
)
|
||||
return "FETCH_HEAD"
|
||||
|
||||
|
||||
def compare_base() -> str | None:
|
||||
"""The line --changed compares with: the project's main line, else the
|
||||
first upstream/ or origin/ line the clone holds, None when it holds none
|
||||
and only its uncommitted files can be read. profile_sync and validate_pr
|
||||
both read it, so the two compare against the same base."""
|
||||
line = project_main_line()
|
||||
if line:
|
||||
return line
|
||||
for candidates in fallback_lines():
|
||||
for candidate in candidates:
|
||||
if git_lines("rev-parse", "--verify", "--quiet", candidate):
|
||||
return candidate
|
||||
return None
|
||||
@@ -285,16 +285,9 @@ 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 fallback_lines, git_lines, project_main_line
|
||||
from core.gitclone import compare_base
|
||||
|
||||
line = project_main_line()
|
||||
if line:
|
||||
return line
|
||||
for candidates in fallback_lines():
|
||||
for candidate in candidates:
|
||||
if git_lines("rev-parse", "--verify", "--quiet", candidate):
|
||||
return candidate
|
||||
return "HEAD"
|
||||
return compare_base() or "HEAD"
|
||||
|
||||
|
||||
def select_profiles(profiles: dict, args: argparse.Namespace) -> dict:
|
||||
|
||||
+5
-14
@@ -34,7 +34,7 @@ try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
yaml = None
|
||||
from core.gitclone import fallback_lines, git_lines, project_main_line
|
||||
from core.gitclone import compare_base, git_lines
|
||||
from resolve.review import (
|
||||
ValidationResult,
|
||||
load_platform_hashes,
|
||||
@@ -54,19 +54,10 @@ def get_changed_files() -> list[str]:
|
||||
A git that fails outright is an error, never "nothing changed".
|
||||
"""
|
||||
changed: list[str] = []
|
||||
compared = False
|
||||
project_base = project_main_line()
|
||||
remotes = [[project_base]] if project_base else fallback_lines()
|
||||
for candidates in remotes:
|
||||
for line in candidates:
|
||||
committed = git_lines("diff", "--name-only", f"{line}...HEAD")
|
||||
if committed is None:
|
||||
continue
|
||||
compared = True
|
||||
changed.extend(committed)
|
||||
break
|
||||
if compared and changed:
|
||||
break
|
||||
base = compare_base()
|
||||
committed = git_lines("diff", "--name-only", f"{base}...HEAD") if base else None
|
||||
compared = committed is not None
|
||||
changed.extend(committed or [])
|
||||
staged = git_lines("diff", "--cached", "--name-only")
|
||||
local = git_lines("diff", "--name-only")
|
||||
untracked = git_lines("ls-files", "--others", "--exclude-standard", "--", "bios")
|
||||
|
||||
Reference in new issue
Block a user