From e606126e818198bf54881a6fde264e04845ef420 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 23 Feb 2022 14:58:57 -0800 Subject: [PATCH] fix(cli): don't crash when there are no changes (#334) code-suggester CLI is trying to parse an empty string as a valid file diff and crashing. Fixes #229 --- src/bin/handle-git-dir-change.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/handle-git-dir-change.ts b/src/bin/handle-git-dir-change.ts index b8f9828f..7f100b72 100644 --- a/src/bin/handle-git-dir-change.ts +++ b/src/bin/handle-git-dir-change.ts @@ -147,7 +147,8 @@ export function getAllDiffs(gitRootDir: string): string[] { }) .toString() // strictly return buffer for mocking purposes. sinon ts doesn't infer {encoding: 'utf-8'} .trimRight() // remove the trailing new line - .split('\n'); + .split('\n') + .filter(line => !!line.trim()); execSync('git reset .', {cwd: gitRootDir}); return diffs; }