This commit is contained in:
Binary file not shown.
@@ -53,10 +53,27 @@ def run_git_diff(repo: str, base: str, head: str) -> str:
|
||||
"--no-color",
|
||||
]
|
||||
result = subprocess.run(cmd, check=False, capture_output=True, text=True)
|
||||
if result.returncode not in (0, 1):
|
||||
raise RuntimeError(result.stderr.strip() or "git diff failed")
|
||||
if result.returncode in (0, 1):
|
||||
return result.stdout
|
||||
|
||||
# If the diff failed because revisions are missing (common in CI when the
|
||||
# PR head/base aren't fetched), try fetching from origin and retry once.
|
||||
stderr = (result.stderr or "").strip()
|
||||
try:
|
||||
fetch_cmd = ["git", "-C", repo, "fetch", "origin", f"{base}", f"{head}"]
|
||||
subprocess.run(fetch_cmd, check=False, capture_output=True, text=True)
|
||||
except Exception:
|
||||
# Ignore fetch errors; we'll raise the original error below.
|
||||
pass
|
||||
|
||||
# Retry diff once
|
||||
result2 = subprocess.run(cmd, check=False, capture_output=True, text=True)
|
||||
if result2.returncode in (0, 1):
|
||||
return result2.stdout
|
||||
|
||||
# If still failing, raise a helpful error including stderr from git
|
||||
raise RuntimeError(result2.stderr.strip() or stderr or "git diff failed")
|
||||
|
||||
|
||||
def parse_diff(diff_text: str) -> list[FileDiff]:
|
||||
files: list[FileDiff] = []
|
||||
|
||||
Reference in New Issue
Block a user