Skip to content

Commit ca2043b

Browse files
authored
πŸ› Don't crash while trying to parse a diff for binary files, fix #128 (#242)
1 parent e84bc1e commit ca2043b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

β€Ždist/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -21657,6 +21657,8 @@ class Git {
2165721657
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
2165821658
const lines = fileDiff.split('\n')
2165921659
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
21660+
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files
21661+
2166021662
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
2166121663
let filePath = ''
2166221664
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files

β€Žsrc/git.js

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class Git {
160160
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
161161
const lines = fileDiff.split('\n')
162162
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
163+
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files
164+
163165
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
164166
let filePath = ''
165167
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files

0 commit comments

Comments
Β (0)