Repository navigation
fix(git-diff): parse numstat -z renames so renamed files keep isBinary - #176
Merged
Merged
Conversation
git diff-tree --numstat -z writes a rename or copy as an empty-path header followed by the old and new paths as separate NUL fields. parseNumstat expected a tab-separated form git never writes with -z, so every renamed or copied file got isBinary: undefined. A path with a tab is now also kept whole. Fixes DiffCI#175 Signed-off-by: FredApps <[email protected]>
FredApps
commented
Nov 17, 2026
FredApps
left a comment
Contributor
Author
There was a problem hiding this comment.
Cross-review at d47d3fa.
Checked:
- I walked the new
parseNumstatloop against thediff-tree -r --numstat -zcall inanalyzeGitDelta. An ordinary record keeps a path containing a tab whole. A rename or copy record (empty path) takes the new path two fields on and skips both path fields, so a path with tabs in it is never misread as a record. - The three new tests fail without the change and pass with it.
- The branch is up to date with main, and CI is green.
Fixed: nothing needed.
Open: nothing reads isBinary yet, as the PR notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #175
What changed
parseNumstat(src/git/git-diff.ts) now reads the formatgit diff-tree --numstat -zactually writes:added\tdeleted\tpath\0for an ordinary file;added\tdeleted\t\0old\0new\0for a rename or copy: an empty path, then both paths as their own fields.Before, it parsed each NUL-separated piece as a tab-separated
added\tdeleted\told\tnewrecord, which git doesn't write with-z. So every renamed or copied file inGitDelta.filesgotisBinary: undefined. The rewrite also keeps a path that contains a tab whole, since-zleaves paths unquoted. The privateparseNumstatRecordhelper is folded intoparseNumstat, and the exported signature is unchanged.Regression tests
tests/git/git-diff.parsers.test.ts: the rename test now uses the real-zbytes, and a new test covers a tab inside a path. Both fail before the fix.tests/git/git-diff.temp-repo.test.ts: a temp repository renames a text file and a binary file, andanalyzeGitDeltamust reportisBinaryfalseandtrue. Before the fix both areundefined.The old rename test fed
parseNumstata tab-separated form git never produces, which is why it passed. I replaced it with the real format rather than keeping both.Validation
npm run typecheck,npm testandnpm run audit:boundarypass.Not covered
Nothing in core or the CLI reads
isBinaryyet. This only corrects theGitDeltaoutput.