Repository: steveukx/git-js
Pull request #649 (2021-07-11 08:23:55)

fix: Commit parsing should cater for file names with square brackets
fix: Commit parsing should cater for file names with square brackets


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97e83b3..88ad2b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,13 +1,5 @@
 # Change History & Release Notes
 
-## [2.41.0](https://www.github.com/steveukx/git-js/compare/v2.40.0...v2.41.0) (2021-07-11)
-
-
-### Features
-
-* allow setting the scope of `git config add` to work on the `local`, `global` or `system` configuration. ([c7164e7](https://www.github.com/steveukx/git-js/commit/c7164e77b98553a5e837da301bc63430741ec092))
-* allow setting the scope of git config add to work on the `local`, `global` or `system` configuration. ([00ada06](https://www.github.com/steveukx/git-js/commit/00ada06057c21193bfbdba917b78a6d3de4ff6c9))
-
 ## [2.40.0](https://www.github.com/steveukx/git-js/compare/v2.39.1...v2.40.0) (2021-06-12)
 
 
diff --git a/package.json b/package.json
index d460b3f..6302df2 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "simple-git",
   "description": "Simple GIT interface for node.js",
-  "version": "2.41.0",
+  "version": "2.40.0",
   "author": "Steve King <steve@mydev.co>",
   "contributors": [
     {
diff --git a/src/lib/parsers/parse-commit.ts b/src/lib/parsers/parse-commit.ts
index 206d4d8..ebf508a 100644
--- a/src/lib/parsers/parse-commit.ts
+++ b/src/lib/parsers/parse-commit.ts
@@ -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;


Test patch:
diff --git a/test/unit/__fixtures__/responses/commit.ts b/test/unit/__fixtures__/responses/commit.ts
index 8048d61..41f8b86 100644
--- a/test/unit/__fixtures__/responses/commit.ts
+++ b/test/unit/__fixtures__/responses/commit.ts
@@ -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}
+`;
+}
diff --git a/test/unit/commit.spec.ts b/test/unit/commit.spec.ts
index 6e97fc5..c4b1ac5 100644
--- a/test/unit/commit.spec.ts
+++ b/test/unit/commit.spec.ts
@@ -3,6 +3,7 @@ import {
    closeWithSuccess,
    commitResultNoneStaged,
    commitResultSingleFile,
+   commitToBranch,
    commitToRepoRoot,
    like,
    newSimpleGit
@@ -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
+         }));
       })
 
    });