Repository navigation
fix(diff): split a bare "diff --git" header at its separator - #1691
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
NanaseInori
left a comment
There was a problem hiding this comment.
The equal-path split fixes unquoted non-rename headers containing b/ inside the filename. Headers without that equal split retain the existing parser, and explicit rename headers still supply the final paths. The regression cases cover both behaviors. No blocking issue found in the code review.
|
Thanks for the review! |
|
@NanaseInori Thanks for the approval on this one — the change is unchanged since your review and CI is green. I believe it is ready to merge whenever you have a moment; happy to make any further adjustments if something else is needed. |
|
I followed up as a maintainer by fixing the copy-path parsing regression and adding 40 real-Git regression checks with Codex CLI assistance. |
No text conflicts and no silent breaks. Upstream added no new calls to the helpers the branch moved into internal/model and left the filter algorithms untouched. The internal/diff fixes reach the core commands through the shared code: `ocr core relocate` calls diff.ResolveComment, so it gains the blank-line-free new-side retry (alibaba#1777), and `ocr core diff` goes through GetDiff, so it keeps tracked gitignored files in workspace mode (alibaba#1837) and splits bare "diff --git" headers (alibaba#1691). New file types (.jsonc, HAML/Slim/ERB, EJS/Liquid/Nunjucks) and Scala rules are shared rule data. The branch delta against v1.13.5 is unchanged. Build, vet, make check and the full -race test suite pass; coverage is 91.2%.
Description
ParseDiffTexttakes its pathnames fromdiffHeaderRe(^diff --git a/(.+?) b/(.+)$). The first group is lazy, so it stops at the firstb/on the line, and for an unquoted header that is not necessarily the separator: git writesa/P b/Pand does not quote a space. A pathname under a directory whose name ends in " b" is therefore split inside the path, and the file is read from a path that does not exist.The one modified file was reported as a rename to
y.go b/x b/y.go, its content was never read, and a comment filed against it would name a file that does not exist.--commitmode failed the same way (cannot read file y.go b/x b/y.go at ref HEAD: exit status 128);--from/--toruns the same parser.Change
A header that is not a rename or a copy names the same path on both sides, so the split whose two sides agree is the one git wrote.
parseDiffHeaderLinenow takes that split for a bare header and falls back todiffHeaderReunchanged. A rename has no equal split, and itsrename from/rename tolines stay authoritative, so rename handling is untouched.An equal split can only be the separator: at a
b/inside the pathname of a same-path header the two sides differ by an odd number of bytes (the header isa/+ P ++b/+ P), so they never match.After:
Type of Change
How Has This Been Tested?
make testpasses locally (replicated on a machine withoutmake; see the raw commands below)internal/diff/parser_test.goadds two tests.TestParseDiffText_SamePathHeaderWithDelimiterInPathfails on the unpatched parser:and passes with it.
TestParseDiffText_AmbiguousRenameHeaderStillUsesRenameLinespins the boundary: a rename whose two paths both containb/keeps taking its paths from therename from/rename tolines.Raw check output on this machine (Go 1.25.9, windows/amd64, base
fabbdb2):One of several
-raceruns here intermittently failed two timing-sensitive tests in packages this change does not touch (internal/llmcancel-during-backoff,internal/mcpCloseAll timeout) under heavy parallel load; both pass in isolation and the other-raceruns passed all 24 packages.make check,make testandmake coveragecould not be invoked literally:makeandbashare not installed on this Windows machine, solicense-check/license-addand the Makefile's shell line were run by hand as the commands above.ocr review --audience agentreportsno valid LLM endpoint configuredhere, so self-review used the project's no-LLM path instead (ocr delegate preview/ocr delegate rule internal/diff/parser.go), which selectedinternal/diff/parser.go(+36/-1) against the Go rule group; I found nothing to change against those rules.Checklist
go fmt,go vet)AI/LLM disclosure: drafted with AI assistance (Codex CLI) at my request, under my direction and review. The scope, the decision to fix this rather than a claimed or architectural topic, and the checks to run were set by me; I reproduced the failure on a scratch repository, read every changed line, and the reasoning above is my own. The CLA is signed (the
license/clacheck passed).Related Issues
Closes #1690