From fa494cfaaeb5b5e703d396abe5712b978d270e81 Mon Sep 17 00:00:00 2001 From: Roberto Guagliardo Date: Mon, 2 Feb 2026 20:20:33 +0000 Subject: [PATCH] test git diff --- .../__pycache__/diff.cpython-311.pyc | Bin 7968 -> 8464 bytes src/ai_reviewer/diff.py | 23 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ai_reviewer/__pycache__/diff.cpython-311.pyc b/src/ai_reviewer/__pycache__/diff.cpython-311.pyc index 18b212e380ebf3b68563fdac8758403594042d70..d4c7db85bb2bd97a70d11592e4452af449e2766d 100644 GIT binary patch delta 997 zcmZXTO=uHA6o6+o*`Fl48)=iq*rrs|L(@_!Jy@i*VzKI>UBzm#{%vb#6SpRtGTF3M zqESyGIYie(z)L_-K@Vy!J*psh(v1WR3xXcKwz2%vmSsTVsZe9 zNXo&-Ajdog3H~N$z4e90Im9CY2`@cQN$!h3`4AYpqQDe)&I6zyU>5`nz;LgF4c7u# zha`VwgwOFS%uW>YuF$@))nzWzXKdL zu9?eM9WIUagl^pMCv>w9>G619d`VAgC?;68*qi4vCQ4^bhprmN4x2HtzUp|UHH(h0hS%FqxSFXe~%ezI4py_mNTe2MafCp{F4LqNQwkZwY^u2EIrG zRcWv$4cYnGD&{2?!*PpYS=wrYZl&YZA z1cfMMG{5-*4ZyI{UwjwDd+r9yuz9K3Y;JjhKU^?MbKB{%Qk9jOtlU0c=j9q7F3sC~ zl#IH+t8mK}B3m5rg^KHsZhZ|6eF+U!L&LSuupOFt)kR>B&s4p$HSetLp3QWSCwR>P)%*ato)QlSvX(m=?p`7(K-+~0WVqkz(W~Nlhhc4C9>di zR!?wDnxz&IpQV;1YcbdzJWtgN6e`6c#YL+a+|OPks#5t7)EKx}8QT4XftRh%dxp4H zi1Dy{kzFGZ4=P&seR#5UqK788s?8HE262)uT>H=zbs7{hMJp^#{gUHV)p*v-Vog;s z{lD-DYceuEO20FvU0_-WM<}`|=%x52Or+8%o75)p4YH-zI)f`OBKu&t7b>s;{^Jz1 Ie)Jyx4K0HMd;kCd delta 549 zcmbQ>w7`yUIWI340}#luHD>-5+{ib9n`s}zwYu@#r3q!tz3Vl6Hy$}9kL z^Gi!KS&M9dHWk@|2sL;(bfL?&nO332-Y`MN+{T*olE zmCw(70ow(3H6XgnCpE)tj_q}6y-U)17o`oZNE=*`cD-QYdXdlV3ZL5r4!0ZJf<3ku zSR{(XfZ8`72MM0C<#m#xWfJ{xE zB7cxb^ki>wY0(f6GZaKbf`}*(5jMG6+<-L=$h6(OK|Ga-F>14z)M6&ah{?NTwAsK) zGAF;5NnkAmDrwjpAlt=g4mOe#q#JBq0Fb50SdqJljD^6!WJ 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]: