From 2b68d97019dc440a41a83fe4e2555c76bce237e8 Mon Sep 17 00:00:00 2001 From: Morisaki Mikiya Date: Fri, 17 Dec 2021 15:19:47 +0900 Subject: [PATCH 1/2] Fix not parse "Binary files ..." line --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index f4a9238..68dbf80 100644 --- a/index.js +++ b/index.js @@ -59,6 +59,7 @@ switch (infoType) { case 'diff': // diff --git + case 'Binary': i--; break simiLoop; From 863f5de6eed4cf144413a9c9e67f9d9c44afba62 Mon Sep 17 00:00:00 2001 From: Morisaki Mikiya Date: Fri, 17 Dec 2021 15:20:29 +0900 Subject: [PATCH 2/2] Add 'oldPath' and 'newPath' on binary diff --- index.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 68dbf80..365ca9f 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,7 @@ currentInfo.oldMode = currentInfo.newMode = segs[1]; } break; - + case 'copy': case 'rename': @@ -126,11 +126,27 @@ } else if (line.indexOf('Binary') === 0) { currentInfo.isBinary = true; - currentInfo.type = line.indexOf('/dev/null and') >= 0 - ? 'add' - : (line.indexOf('and /dev/null') >= 0 ? 'delete' : 'modify'); + + // line: "Binary files {oldPath} and {newPath} differ" + let oldPath = line.split(' ')[2] + let newPath = line.split(' ')[4] + if (oldPath === '/dev/null') { + currentInfo.type = 'add'; + currentInfo.oldPath = oldPath; + currentInfo.newPath = newPath.slice(2); + } + else if (newPath === '/dev/null') { + currentInfo.type = 'delete'; + currentInfo.oldPath = oldPath.slice(2); + currentInfo.newPath = newPath; + } + else { + currentInfo.type = 'modify'; + currentInfo.oldPath = oldPath.slice(2); + currentInfo.newPath = newPath.slice(2); + } + stat = STAT_START; - currentInfo = null; } else if (stat === STAT_HUNK) { if (line.indexOf('@@') === 0) {