Skip to content

Commit

Permalink
fix: detect changed files if they r surrounded by quotes in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
levan-giguashvili-lmnd committed Sep 12, 2024
1 parent 5fe18b3 commit 06b3117
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions libs/core/src/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ describe('git', () => {

expect(changedFiles).toEqual([]);
});

it.only('should return a changed file when it has quotes surrounding files', async () => {
jest.spyOn(childProcess, 'execSync')
.mockReturnValue(`diff --git "a/lala.png" "b/lala.png"
new file mode 100644
index 000000000..26b848d67
Binary files /dev/null and "b/lala.png" differ`);

const changedFiles = getChangedFiles({
base: branch,
cwd,
});

expect(changedFiles).toEqual([
{ filePath: 'lala.png', changedLines: [] },
]);
});
});

describe('getFileFromRevision', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? [];
Expand Down

0 comments on commit 06b3117

Please sign in to comment.