Skip to content

fix(git-diff): parse numstat -z renames so renamed files keep isBinary - #176

Merged
adityankale190895 merged 1 commit into
DiffCI:mainfrom
FredApps:fix/numstat-z-renames
Nov 18, 2026
Merged

adityankale190895 merged 1 commit into
DiffCI:mainfrom
FredApps:fix/numstat-z-renames

Conversation

@FredApps

Copy link
Copy Markdown
Contributor

Fixes #175

What changed

parseNumstat (src/git/git-diff.ts) now reads the format git diff-tree --numstat -z actually writes:

  • added\tdeleted\tpath\0 for an ordinary file;
  • added\tdeleted\t\0old\0new\0 for 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\tnew record, which git doesn't write with -z. So every renamed or copied file in GitDelta.files got isBinary: undefined. The rewrite also keeps a path that contains a tab whole, since -z leaves paths unquoted. The private parseNumstatRecord helper is folded into parseNumstat, and the exported signature is unchanged.

Regression tests

  • tests/git/git-diff.parsers.test.ts: the rename test now uses the real -z bytes, 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, and analyzeGitDelta must report isBinary false and true. Before the fix both are undefined.

The old rename test fed parseNumstat a 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 test and npm run audit:boundary pass.

Not covered

Nothing in core or the CLI reads isBinary yet. This only corrects the GitDelta output.

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 FredApps left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-review at d47d3fa.

Checked:

  • I walked the new parseNumstat loop against the diff-tree -r --numstat -z call in analyzeGitDelta. 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.

@FredApps
FredApps marked this pull request as ready for review November 18, 2026 00:56
@adityankale190895
adityankale190895 merged commit 6a503b7 into DiffCI:main Nov 18, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyzeGitDelta: renamed and copied files lose isBinary (numstat -z parsed in the wrong format)

2 participants