Skip to content

Commit ae81134

Browse files
committed
fix: Commit parsing should cater for file names with square brackets
1 parent 00ada06 commit ae81134

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/lib/parsers/parse-commit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CommitResult } from '../../../typings';
22
import { LineParser, parseStringResponse } from '../utils';
33

44
const parsers: LineParser<CommitResult>[] = [
5-
new LineParser(/\[([^\s]+)( \([^)]+\))? ([^\]]+)/, (result, [branch, root, commit]) => {
5+
new LineParser(/^\[([^\s]+)( \([^)]+\))? ([^\]]+)/, (result, [branch, root, commit]) => {
66
result.branch = branch;
77
result.commit = commit;
88
result.root = !!root;

test/unit/__fixtures__/responses/commit.ts

+8
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ export function commitToRepoRoot ({message = 'Commit Message', hash = 'b13bdd8',
2424
create mode 100644 ${fileName}
2525
`;
2626
}
27+
28+
export function commitToBranch ({message = 'Commit Message', hash = 'b13bdd8', fileName = 'file-name', branch = 'branch'} = {}) {
29+
return `
30+
[${branch} ${hash}] ${message}
31+
1 file changed, 1 insertion(+)
32+
create mode 100644 ${fileName}
33+
`;
34+
}

test/unit/commit.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
closeWithSuccess,
44
commitResultNoneStaged,
55
commitResultSingleFile,
6+
commitToBranch,
67
commitToRepoRoot,
78
like,
89
newSimpleGit
@@ -135,6 +136,14 @@ describe('commit', () => {
135136
commit: 'foo',
136137
root: true
137138
}));
139+
});
140+
141+
it('handles files with square brackets', () => {
142+
const actual = parseCommitResult(commitToBranch({fileName: '[AB] CDE FGH.txt', branch: 'alpha'}));
143+
expect(actual).toEqual(like({
144+
branch: 'alpha',
145+
root: false
146+
}));
138147
})
139148

140149
});

0 commit comments

Comments
 (0)