Skip to content

Commit

Permalink
fix: detect changed files if they r surrounded by quotes in diff (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
levan-giguashvili-lmnd authored Sep 12, 2024
1 parent 5fe18b3 commit f6c6795
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions libs/core/src/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
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 f6c6795

Please sign in to comment.