Bare "diff --git" header is split inside the pathname when it contains " b/"
OpenCodeReview Version: open-code-review dev windows/amd64, built from source at fabbdb2 (main). The delimiter regex has not changed since the initial commit, so released builds behave the same.
Operating System: Windows
Installation Method: Built from source
LLM Provider: n/a - reproduced with --preview, no LLM call involved
Bug Description
A bare diff --git header is split at the wrong delimiter when the pathname contains the substring b/.
ParseDiffText takes its pathnames from diffHeaderRe (^diff --git a/(.+?) b/(.+)$). The first group is lazy, so the regex stops at the first b/ on the line, and for an unquoted header that is not necessarily the separator: git writes a/P b/P and 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 then read from a path that does not exist.
$ git status --short
M "x b/y.go"
$ git -c core.quotepath=false diff --no-ext-diff --no-textconv --find-renames --src-prefix=a/ --dst-prefix=b/ --no-color -U3 --end-of-options HEAD -- (the provider's own arguments)
diff --git a/x b/y.go b/x b/y.go
index 789ca71..aa33d82 100644
--- a/x b/y.go
+++ b/x b/y.go
@@ -1 +1,2 @@
package y
+var Changed = true
$ ocr review --preview
[ocr] WARNING: cannot read file y.go b/x b/y.go for review: resolve parent path for "y.go b/x b/y.go": GetFileAttributesEx D:\...\x b\..\y.go b: The system cannot find the file specified.
Preview: 1 file(s) changed | +1 -0
Will review (1):
[R] y.go b/x b/y.go +1 -0
The single modified file is reported as a rename to y.go b/x b/y.go, its content is never read, and a comment filed against it would name a file that does not exist. --commit mode fails the same way (cannot read file y.go b/x b/y.go at ref HEAD: exit status 128), and --from/--to goes through the same parser.
Steps to Reproduce
# any directory whose name ends in " b" - e.g. "x b", "step b", "part b"
mkdir -p "x b"
printf 'package y\n' > "x b/y.go"
git init -q && git add -A && git commit -qm init
printf 'var Changed = true\n' >> "x b/y.go"
ocr review --preview
Expected Behavior
One modified file, x b/y.go, read from the repository like any other path.
Additional Context
- The fault is in the split, not the read. In
a/x b/y.go b/x b/y.gooneb/belongs to the path and one separates the operands, and only the latter gives two equal sides. Git writes the same path on both sides of every header that is not a rename or a copy, so preferring that split identifies the separator; a rename has no such split and keeps its authoritativerename from/rename tolines. - Prior art, checked before opening this: PR #846 and PR #1472 both attempted this and were closed unmerged (the latter withdrawn by its author, who invited a takeover); PR #1498 merged quoted-pathname parsing and deliberately left the bare case to the plain regex (
splitHeaderPathsdocuments that). No issue tracked the remaining gap. - I have a fix with a regression test ready and will link it here.
AI/LLM disclosure: found and written up with AI assistance (Codex CLI) at my request, under my direction and review. I reproduced the failure myself with the commands above and checked the analysis against git's own output.