From 54740786fec54f61d1d9f2e6d508003fbdbc8917 Mon Sep 17 00:00:00 2001 From: kv979w Date: Fri, 6 May 2022 11:05:52 -0400 Subject: [PATCH] fix(parse-commit): allow whitespace in file names Update regex for files added, removed, or modified to allow whitespace in the parsed commit output. Resolves: https://github.com/wayfair/git-parse/issues/63 --- CHANGELOG.md | 1 + src/__tests__/__snapshots__/parse_commit_spec.ts.snap | 9 +++++++++ src/__tests__/parse_commit_spec.ts | 3 +++ src/parse_commit.ts | 6 +++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78919bf..21da486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Upgrade `minimist` dep `^1.2.6` +- Allow whitespace in file names for files modified, deleted, or added in parsed commit output. ## 2.1.1 (March 29, 2022) diff --git a/src/__tests__/__snapshots__/parse_commit_spec.ts.snap b/src/__tests__/__snapshots__/parse_commit_spec.ts.snap index 423e53d..0e03cc9 100644 --- a/src/__tests__/__snapshots__/parse_commit_spec.ts.snap +++ b/src/__tests__/__snapshots__/parse_commit_spec.ts.snap @@ -9,16 +9,25 @@ Object { Object { "path": "packages/distillery/src/index.js", }, + Object { + "path": "directory/t t.md", + }, ], "filesDeleted": Array [ Object { "path": "packages/git-parse/index.js", }, + Object { + "path": "directory/t2 t2.md", + }, ], "filesModified": Array [ Object { "path": "README.md", }, + Object { + "path": "READ ME.md", + }, ], "filesRenamed": Array [ Object { diff --git a/src/__tests__/parse_commit_spec.ts b/src/__tests__/parse_commit_spec.ts index f0b791c..ab68f71 100644 --- a/src/__tests__/parse_commit_spec.ts +++ b/src/__tests__/parse_commit_spec.ts @@ -10,9 +10,12 @@ describe("parseCommit", () => { "add flow", "GITPARSEFILES", "M README.md", + "M READ ME.md", "R078 packages/git-parse/__tests__/index.spec.js packages/distillery/src/__tests__/index.spec.js", "A packages/distillery/src/index.js", + "A directory/t t.md", "D packages/git-parse/index.js", + "D directory/t2 t2.md", ]; it("returns a parsed git commit", () => { diff --git a/src/parse_commit.ts b/src/parse_commit.ts index b6634b7..016b010 100644 --- a/src/parse_commit.ts +++ b/src/parse_commit.ts @@ -22,9 +22,9 @@ const parseCommit = (commit: string[]): GitCommit => { const message = commit.slice(messageIndex + 1, fileIndex).join("\n"); const files = commit.slice(fileIndex + 1); - const addPattern = /^A\s([^\s]+)/; - const deletePattern = /^D\s([^\s]+)/; - const modifyPattern = /^M\s([^\s]+)/; + const addPattern = /^A\s(.+)/; + const deletePattern = /^D\s(.+)/; + const modifyPattern = /^M\s(.+)/; const renamePattern = /^R[0-9]+\s(.+)\s(.+)/; const filterFileChanges = (pattern: RegExp): FileModification[] => {