Skip to content

Commit f6c6795

Browse files
fix: detect changed files if they r surrounded by quotes in diff (#34)
1 parent 5fe18b3 commit f6c6795

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

libs/core/src/git.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,25 @@ describe('git', () => {
188188

189189
expect(changedFiles).toEqual([]);
190190
});
191+
192+
it('should return a changed file when it has quotes surrounding files', async () => {
193+
const execSpy = jest.spyOn(childProcess, 'execSync')
194+
.mockReturnValue(`diff --git "a/lala.ts" "b/lala.ts"
195+
new file mode 100644
196+
index 000000000..26b848d67
197+
Binary files /dev/null and "b/lala.ts" differ`);
198+
199+
const changedFiles = getChangedFiles({
200+
base: branch,
201+
cwd,
202+
});
203+
204+
expect(changedFiles).toEqual([
205+
{ filePath: 'lala.ts', changedLines: [] },
206+
]);
207+
208+
execSpy.mockRestore();
209+
});
191210
});
192211

193212
describe('getFileFromRevision', () => {

libs/core/src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function getChangedFiles({
102102
.slice(1)
103103
.map((file) => {
104104
/* istanbul ignore next */
105-
const filePath = file.match(/(?<= a\/).*(?= b\/)/g)?.[0] ?? '';
105+
const filePath = (file.match(/(?<=["\s]a\/).*(?=["\s]b\/)/g)?.[0] ?? '').replace('"', '').trim();
106106
/* istanbul ignore next */
107107
const changedLines =
108108
file.match(/(?<=@@ -.* \+)\d*(?=.* @@)/g)?.map((line) => +line) ?? [];

0 commit comments

Comments
 (0)