From f6c6795c7cb42c793e082cb544e56ac353d14626 Mon Sep 17 00:00:00 2001 From: Levan Giguashvili Date: Thu, 12 Sep 2024 14:11:43 +0300 Subject: [PATCH] fix: detect changed files if they r surrounded by quotes in diff (#34) --- libs/core/src/git.spec.ts | 19 +++++++++++++++++++ libs/core/src/git.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libs/core/src/git.spec.ts b/libs/core/src/git.spec.ts index 37176af..ff57547 100644 --- a/libs/core/src/git.spec.ts +++ b/libs/core/src/git.spec.ts @@ -188,6 +188,25 @@ describe('git', () => { expect(changedFiles).toEqual([]); }); + + it('should return a changed file when it has quotes surrounding files', async () => { + const execSpy = jest.spyOn(childProcess, 'execSync') + .mockReturnValue(`diff --git "a/lala.ts" "b/lala.ts" +new file mode 100644 +index 000000000..26b848d67 +Binary files /dev/null and "b/lala.ts" differ`); + + const changedFiles = getChangedFiles({ + base: branch, + cwd, + }); + + expect(changedFiles).toEqual([ + { filePath: 'lala.ts', changedLines: [] }, + ]); + + execSpy.mockRestore(); + }); }); describe('getFileFromRevision', () => { diff --git a/libs/core/src/git.ts b/libs/core/src/git.ts index 4a1f958..c26f1f7 100644 --- a/libs/core/src/git.ts +++ b/libs/core/src/git.ts @@ -102,7 +102,7 @@ export function getChangedFiles({ .slice(1) .map((file) => { /* istanbul ignore next */ - const filePath = file.match(/(?<= a\/).*(?= b\/)/g)?.[0] ?? ''; + const filePath = (file.match(/(?<=["\s]a\/).*(?=["\s]b\/)/g)?.[0] ?? '').replace('"', '').trim(); /* istanbul ignore next */ const changedLines = file.match(/(?<=@@ -.* \+)\d*(?=.* @@)/g)?.map((line) => +line) ?? [];