Skip to content

Commit

Permalink
Pr/1019 (#1021)
Browse files Browse the repository at this point in the history
* Fixed FileStatusSummary consturctor

* Fixed parcing to turn renames inside the FileStatusSummary and FileStatusResult.

* Removed useless changes

* Add test

* Changeset

---------

Co-authored-by: Mark Kanafeev <mark@codesphere.com>
  • Loading branch information
steveukx and mark-codesphere authored Sep 14, 2024
1 parent 4297fdc commit bc90e7e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-clocks-drum.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 4 additions & 4 deletions simple-git/src/lib/responses/FileStatusSummary.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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] || '';
}
}
}
2 changes: 1 addition & 1 deletion simple-git/src/lib/responses/StatusSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
2 changes: 1 addition & 1 deletion simple-git/test/integration/status.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
})
);
Expand Down

0 comments on commit bc90e7e

Please sign in to comment.