Skip to content

Commit

Permalink
fix: Commit parsing should cater for file names with square brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
steveukx committed Jul 11, 2021
1 parent 00ada06 commit ae81134
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/parsers/parse-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CommitResult } from '../../../typings';
import { LineParser, parseStringResponse } from '../utils';

const parsers: LineParser<CommitResult>[] = [
new LineParser(/\[([^\s]+)( \([^)]+\))? ([^\]]+)/, (result, [branch, root, commit]) => {
new LineParser(/^\[([^\s]+)( \([^)]+\))? ([^\]]+)/, (result, [branch, root, commit]) => {
result.branch = branch;
result.commit = commit;
result.root = !!root;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/__fixtures__/responses/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ export function commitToRepoRoot ({message = 'Commit Message', hash = 'b13bdd8',
create mode 100644 ${fileName}
`;
}

export function commitToBranch ({message = 'Commit Message', hash = 'b13bdd8', fileName = 'file-name', branch = 'branch'} = {}) {
return `
[${branch} ${hash}] ${message}
1 file changed, 1 insertion(+)
create mode 100644 ${fileName}
`;
}
9 changes: 9 additions & 0 deletions test/unit/commit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
closeWithSuccess,
commitResultNoneStaged,
commitResultSingleFile,
commitToBranch,
commitToRepoRoot,
like,
newSimpleGit
Expand Down Expand Up @@ -135,6 +136,14 @@ describe('commit', () => {
commit: 'foo',
root: true
}));
});

it('handles files with square brackets', () => {
const actual = parseCommitResult(commitToBranch({fileName: '[AB] CDE FGH.txt', branch: 'alpha'}));
expect(actual).toEqual(like({
branch: 'alpha',
root: false
}));
})

});
Expand Down

0 comments on commit ae81134

Please sign in to comment.