diff --git a/src/ai_reviewer/__pycache__/diff.cpython-311.pyc b/src/ai_reviewer/__pycache__/diff.cpython-311.pyc index 18b212e..d4c7db8 100644 Binary files a/src/ai_reviewer/__pycache__/diff.cpython-311.pyc and b/src/ai_reviewer/__pycache__/diff.cpython-311.pyc differ diff --git a/src/ai_reviewer/diff.py b/src/ai_reviewer/diff.py index a6afbaf..1eceeb3 100644 --- a/src/ai_reviewer/diff.py +++ b/src/ai_reviewer/diff.py @@ -53,9 +53,26 @@ 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") - return result.stdout + 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]: