test git diff
Some checks failed
AI Reviewer / review (pull_request) Failing after 24s

This commit is contained in:
2026-02-02 20:20:33 +00:00
parent 1354e09831
commit fa494cfaae
2 changed files with 20 additions and 3 deletions

View File

@@ -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] = []