fix: synthesize diff header when provider omits it
This commit is contained in:
parent
01ead5754f
commit
25c04859e6
|
|
@ -506,10 +506,22 @@ def sanitize_unified_patch(patch: str) -> str:
|
||||||
# Look for the 'diff --git' header
|
# Look for the 'diff --git' header
|
||||||
diff_start = text.find("diff --git")
|
diff_start = text.find("diff --git")
|
||||||
if diff_start == -1:
|
if diff_start == -1:
|
||||||
|
# Some providers omit diff header; synthesize one if we have +++ line.
|
||||||
|
plus_line = next((line for line in cleaned if line.startswith("+++ ")), None)
|
||||||
|
minus_line = next((line for line in cleaned if line.startswith("--- ")), None)
|
||||||
|
if plus_line:
|
||||||
|
plus_path = plus_line[4:].strip()
|
||||||
|
minus_path = minus_line[4:].strip() if minus_line else plus_path
|
||||||
|
if minus_path == "/dev/null":
|
||||||
|
minus_path = plus_path
|
||||||
|
text = f"diff --git {minus_path} {plus_path}\n{text}"
|
||||||
|
else:
|
||||||
# No diff header means AI chose not to generate a patch
|
# No diff header means AI chose not to generate a patch
|
||||||
# This is normal for gated outputs or when AI determines no changes needed
|
# This is normal for gated outputs or when AI determines no changes needed
|
||||||
return ""
|
return ""
|
||||||
return text[diff_start:] + "\n"
|
else:
|
||||||
|
text = text[diff_start:]
|
||||||
|
return text + "\n"
|
||||||
|
|
||||||
|
|
||||||
def rewrite_patch_for_p0(patch: str) -> str:
|
def rewrite_patch_for_p0(patch: str) -> str:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue