From bc90e7e0c14171c18d45fa264f583713523e3d05 Mon Sep 17 00:00:00 2001 From: Steve King Date: Sat, 14 Sep 2024 14:17:09 +0100 Subject: [PATCH] Pr/1019 (#1021) * Fixed FileStatusSummary consturctor * Fixed parcing to turn renames inside the FileStatusSummary and FileStatusResult. * Removed useless changes * Add test * Changeset --------- Co-authored-by: Mark Kanafeev --- .changeset/slimy-clocks-drum.md | 6 ++++++ simple-git/src/lib/responses/FileStatusSummary.ts | 8 ++++---- simple-git/src/lib/responses/StatusSummary.ts | 2 +- simple-git/test/integration/status.spec.ts | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changeset/slimy-clocks-drum.md diff --git a/.changeset/slimy-clocks-drum.md b/.changeset/slimy-clocks-drum.md new file mode 100644 index 00000000..2a49ef53 --- /dev/null +++ b/.changeset/slimy-clocks-drum.md @@ -0,0 +1,6 @@ +--- +'simple-git': minor +--- + +Fixes an issue with reporting name changes in the `files` array returned by `git.status`. +Thank you @mark-codesphere for the contribution. diff --git a/simple-git/src/lib/responses/FileStatusSummary.ts b/simple-git/src/lib/responses/FileStatusSummary.ts index 957aa197..92ce0af1 100644 --- a/simple-git/src/lib/responses/FileStatusSummary.ts +++ b/simple-git/src/lib/responses/FileStatusSummary.ts @@ -1,6 +1,6 @@ import { FileStatusResult } from '../../../typings'; -export const fromPathRegex = /^(.+) -> (.+)$/; +export const fromPathRegex = /^(.+)\0(.+)$/; export class FileStatusSummary implements FileStatusResult { public readonly from: string | undefined; @@ -10,10 +10,10 @@ export class FileStatusSummary implements FileStatusResult { public index: string, public working_dir: string ) { - if ('R' === index + working_dir) { + if (index === 'R' || working_dir === 'R') { const detail = fromPathRegex.exec(path) || [null, path, path]; - this.from = detail[1] || ''; - this.path = detail[2] || ''; + this.from = detail[2] || ''; + this.path = detail[1] || ''; } } } diff --git a/simple-git/src/lib/responses/StatusSummary.ts b/simple-git/src/lib/responses/StatusSummary.ts index 1a0c95b5..0cfb3169 100644 --- a/simple-git/src/lib/responses/StatusSummary.ts +++ b/simple-git/src/lib/responses/StatusSummary.ts @@ -200,7 +200,7 @@ function splitLine(result: StatusResult, lineStr: string) { } if (raw !== '##' && raw !== '!!') { - result.files.push(new FileStatusSummary(path.replace(/\0.+$/, ''), index, workingDir)); + result.files.push(new FileStatusSummary(path, index, workingDir)); } } } diff --git a/simple-git/test/integration/status.spec.ts b/simple-git/test/integration/status.spec.ts index 364e8526..74e12051 100644 --- a/simple-git/test/integration/status.spec.ts +++ b/simple-git/test/integration/status.spec.ts @@ -24,7 +24,7 @@ describe('status', () => { expect(status).toEqual( like({ - files: [like({ path: 'gamma' }), like({ path: 'dirty-dir/dirty' })], + files: [like({ path: 'gamma', from: 'alpha' }), like({ path: 'dirty-dir/dirty' })], renamed: [{ from: 'alpha', to: 'gamma' }], }) );