Skip to content

Commit 52f767b

Browse files
authored
Feat/name status similarity (#1025)
* Add `similarity` to the `DiffResultNameStatusFile` interface, used when getting a log/diff with the `--name-status` option. Closes #993 * Changeset
1 parent 03e1c64 commit 52f767b

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

.changeset/hot-hornets-clean.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'simple-git': minor
3+
---
4+
5+
Add `similarity` to the `DiffResultNameStatusFile` interface used when fetching log/diff with the `--name-status` option.

simple-git/src/lib/parsers/parse-diff-summary.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const nameOnlyParser = [
8989
const nameStatusParser = [
9090
new LineParser<DiffResult>(
9191
/([ACDMRTUXB])([0-9]{0,3})\t(.[^\t]*)(\t(.[^\t]*))?$/,
92-
(result, [status, _similarity, from, _to, to]) => {
92+
(result, [status, similarity, from, _to, to]) => {
9393
result.changed++;
9494
result.files.push({
9595
file: to ?? from,
@@ -99,6 +99,7 @@ const nameStatusParser = [
9999
binary: false,
100100
status: orVoid(isDiffNameStatus(status) && status),
101101
from: orVoid(!!to && from !== to && from),
102+
similarity: asNumber(similarity),
102103
});
103104
}
104105
),

simple-git/test/integration/log-name-status.spec.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,30 @@ describe('log-name-status', function () {
2626
const actual = await newSimpleGit(context.root).log(['--name-status']);
2727

2828
expect(actual.all).toEqual([
29-
mockListLogLine('two', { b: [DiffNameStatus.RENAMED, 'a'] }),
29+
mockListLogLine('two', { b: [DiffNameStatus.RENAMED, 100, 'a'] }),
3030
mockListLogLine('one', { a: [DiffNameStatus.ADDED] }),
3131
]);
3232
});
3333
});
3434

35-
function mockListLogLine(message: string, changes: Record<string, [DiffNameStatus, string?]>) {
36-
const files: DiffResultTextFile[] = Object.entries(changes).map(([file, [status, from]]) => {
37-
return {
38-
binary: false,
39-
changes: 0,
40-
deletions: 0,
41-
file,
42-
insertions: 0,
43-
status,
44-
from,
45-
};
46-
});
35+
function mockListLogLine(
36+
message: string,
37+
changes: Record<string, [DiffNameStatus, number?, string?]>
38+
) {
39+
const files: DiffResultTextFile[] = Object.entries(changes).map(
40+
([file, [status, similarity = 0, from]]) => {
41+
return {
42+
binary: false,
43+
changes: 0,
44+
deletions: 0,
45+
file,
46+
insertions: 0,
47+
similarity,
48+
status,
49+
from,
50+
};
51+
}
52+
);
4753
return like({
4854
message,
4955
diff: like({ changed: files.length, deletions: 0, insertions: 0, files }),

simple-git/test/unit/diff.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ describe('diff', () => {
329329
insertions: 0,
330330
deletions: 0,
331331
binary: false,
332+
similarity: 0,
332333
status: 'M',
333334
from: undefined,
334335
},
@@ -338,6 +339,7 @@ describe('diff', () => {
338339
insertions: 0,
339340
deletions: 0,
340341
binary: false,
342+
similarity: 100,
341343
status: 'R',
342344
from: 'from',
343345
},

simple-git/typings/response.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export interface DiffResultBinaryFile {
155155
export interface DiffResultNameStatusFile extends DiffResultTextFile {
156156
status?: DiffNameStatus;
157157
from?: string;
158+
similarity: number;
158159
}
159160

160161
export interface DiffResult {

0 commit comments

Comments
 (0)