Skip to content

Commit

Permalink
Don't crash while trying to parse a diff for binary files, fix BetaHu…
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Aug 22, 2022
1 parent e84bc1e commit e2f1dc0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class Git {
// split diff into separate entries for separate files. \ndiff --git should be a reliable way to detect the separation, as content of files is always indented
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
const lines = fileDiff.split('\n')
if (lines.length === 0) return resultDict; // ignore binary files

const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = ''
Expand Down

0 comments on commit e2f1dc0

Please sign in to comment.