Skip to content
Merged

Pr/1180 #1195

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-diffs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'simple-git': patch
---

Parse binary rename entries without byte counts in diff summaries.
8 changes: 8 additions & 0 deletions simple-git/src/lib/parsers/parse-diff-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const statParser = [
});
}
),
new LineParser<DiffResult>(/^(.+)\s+\|\s+Bin\s*$/, (result, [file]) => {
result.files.push({
file: file.trim(),
before: 0,
after: 0,
binary: true,
});
}),
new LineParser<DiffResult>(
/(\d+) files? changed\s*((?:, \d+ [^,]+){0,2})/,
(result, [changed, summary]) => {
Expand Down
54 changes: 54 additions & 0 deletions simple-git/test/integration/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,58 @@ describe('diff', () => {
})
);
});

describe('renaming files', () => {
let context: SimpleGitTestContext;

beforeEach(async () => {
context = await createTestContext();
await setUpInit(context);
});

it('detects renamed text files', async () => {
const git = newSimpleGit(context.root);
const original = 'uploads/original.txt';
const renamed = 'uploads/renamed.txt';

await context.file(['uploads', 'original.txt'], 'text content');
await git.add(original).commit('add text file');
const beforeRename = await git.revparse('HEAD');

await git.mv(original, renamed).commit('rename text file');
const diff = await git.diffSummary([beforeRename, 'HEAD']);

expect(diff.files).toEqual([
{
file: 'uploads/{original.txt => renamed.txt}',
changes: 0,
insertions: 0,
deletions: 0,
binary: false,
},
]);
});

it('detects renamed binary files', async () => {
const git = newSimpleGit(context.root);
const original = 'uploads/image.png';
const renamed = 'uploads/image-test.png';

await context.file(['uploads', 'image.png'], '\0binary image content');
await git.add(original).commit('add binary file');
const beforeRename = await git.revparse('HEAD');

await git.mv(original, renamed).commit('rename binary file');
const diff = await git.diffSummary([beforeRename, 'HEAD']);

expect(diff.files).toEqual([
{
file: 'uploads/{image.png => image-test.png}',
before: 0,
after: 0,
binary: true,
},
]);
});
});
});
21 changes: 21 additions & 0 deletions simple-git/test/unit/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ describe('diff', () => {
);
});

it('bin summary without byte counts', () => {
const summary = getDiffParser(LogFormat.STAT)(`
uploads/{image.png => image-test.png} | Bin
1 file changed, 0 insertions(+), 0 deletions(-)
`);
expect(summary).toEqual(
like({
insertions: 0,
deletions: 0,
files: [
{
file: 'uploads/{image.png => image-test.png}',
before: 0,
after: 0,
binary: true,
},
],
})
);
});

it('single text file with changes', () => {
const actual = getDiffParser(LogFormat.STAT)(
diffSummarySingleFile(1, 2, 'package.json').stdOut
Expand Down
Loading