Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect changed files if they r surrounded by quotes in diff #34

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading