From 4d4740d3dbff688ab7b352a77914a8ac3fd01e92 Mon Sep 17 00:00:00 2001 From: Justin Poehnelt <jpoehnelt@google.com> Date: Mon, 14 Sep 2020 16:48:53 -0600 Subject: [PATCH] fix: handle binary files and undefined path from gitdiff-parser (#69) --- src/annotate.test.ts | 18 ++++++++++++++++++ src/annotate.ts | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/annotate.test.ts b/src/annotate.test.ts index 6851105..d6be47d 100644 --- a/src/annotate.test.ts +++ b/src/annotate.test.ts @@ -57,6 +57,24 @@ test("should annotate correctly", () => { ]); }); +test("should annotate case without newPath", () => { + // sourced from https://patch-diff.githubusercontent.com/raw/bwvalle/learnopencv/pull/7.diff + const files = [ + { + hunks: [], + newEndingNewLine: true, + newMode: "100644", + newRevision: "00c87967", + oldEndingNewLine: true, + oldRevision: "00000000", + type: "modify", + }, + ]; + + const annotations = annotate(DEFAULT_CONFIGURATION, files as any); + expect(annotations).toEqual([]); +}); + test("should get correct level from annotations", () => { expect(getLevelFromAnnotations([])).toBe(Level.OFF); expect( diff --git a/src/annotate.ts b/src/annotate.ts index 5e578d9..46ba441 100644 --- a/src/annotate.ts +++ b/src/annotate.ts @@ -29,6 +29,8 @@ export const annotate = ( for (const f of files) { if ( f.type === "delete" || + f.isBinary || + f.newPath === undefined || config.ignore.some((pattern) => minimatch(f.newPath, pattern)) ) { continue;