Skip to content

Commit cea0dbb

Browse files
that-github-userunknownclaude
authored
Handle binary files gracefully in diff parser (#85)
Skip "Binary files ... differ" entries in parseDiff instead of treating them as text diffs. Prevents crashes on repos with images/binaries. 1 new test verifies binary file entries are skipped. Generated by thinktank (5 agents, 72% convergence, Agent #5 recommended). Closes #68 Co-authored-by: unknown <that-github-user@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9f480ef commit cea0dbb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/scoring/diff-parser.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ diff --git a/b.ts b/b.ts
5555
assert.deepEqual(parseDiff(""), []);
5656
});
5757

58+
it("skips binary file entries", () => {
59+
const binaryDiff = `diff --git a/image.png b/image.png
60+
index abc1234..def5678 100644
61+
Binary files a/image.png and b/image.png differ
62+
diff --git a/src/auth.ts b/src/auth.ts
63+
--- a/src/auth.ts
64+
+++ b/src/auth.ts
65+
@@ -1 +1 @@
66+
+const x = 1;`;
67+
const files = parseDiff(binaryDiff);
68+
assert.equal(files.length, 1);
69+
assert.equal(files[0]!.path, "src/auth.ts");
70+
});
71+
5872
it("handles filenames with spaces (quoted paths)", () => {
5973
const quotedDiff = `diff --git "a/src/my component.tsx" "b/src/my component.tsx"
6074
--- "a/src/my component.tsx"

src/scoring/diff-parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export function parseDiff(diff: string): DiffFile[] {
3030

3131
if (!current) continue;
3232

33+
// Skip binary file entries — git emits "Binary files a/x and b/x differ"
34+
if (line.startsWith("Binary files ") && line.endsWith(" differ")) {
35+
current = null;
36+
files.pop();
37+
continue;
38+
}
39+
3340
// Skip metadata lines
3441
if (line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
3542
continue;

0 commit comments

Comments
 (0)