Skip to content

Commit 4c79d0f

Browse files
committed
Adds rename detection on status
1 parent 2130072 commit 4c79d0f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/git/git.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,25 +978,37 @@ export class Git {
978978
return git<string>({ cwd: repoPath }, ...params);
979979
}
980980

981-
static status(repoPath: string, porcelainVersion: number = 1): Promise<string> {
981+
static status(
982+
repoPath: string,
983+
porcelainVersion: number = 1,
984+
{ similarityThreshold }: { similarityThreshold?: number } = {}
985+
): Promise<string> {
982986
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
983987
return git<string>(
984988
{ cwd: repoPath, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
985989
'status',
986990
porcelain,
987991
'--branch',
988-
'-u'
992+
'-u',
993+
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
994+
'--'
989995
);
990996
}
991997

992-
static status__file(repoPath: string, fileName: string, porcelainVersion: number = 1): Promise<string> {
998+
static status__file(
999+
repoPath: string,
1000+
fileName: string,
1001+
porcelainVersion: number = 1,
1002+
{ similarityThreshold }: { similarityThreshold?: number } = {}
1003+
): Promise<string> {
9931004
const [file, root] = Git.splitPath(fileName, repoPath);
9941005

9951006
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
9961007
return git<string>(
9971008
{ cwd: root, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
9981009
'status',
9991010
porcelain,
1011+
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
10001012
'--',
10011013
file
10021014
);

src/git/gitService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,9 @@ export class GitService implements Disposable {
20442044
async getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined> {
20452045
const porcelainVersion = Git.validateVersion(2, 11) ? 2 : 1;
20462046

2047-
const data = await Git.status__file(repoPath, fileName, porcelainVersion);
2047+
const data = await Git.status__file(repoPath, fileName, porcelainVersion, {
2048+
similarityThreshold: Container.config.advanced.similarityThreshold
2049+
});
20482050
const status = GitStatusParser.parse(data, repoPath, porcelainVersion);
20492051
if (status === undefined || !status.files.length) return undefined;
20502052

@@ -2057,7 +2059,9 @@ export class GitService implements Disposable {
20572059

20582060
const porcelainVersion = Git.validateVersion(2, 11) ? 2 : 1;
20592061

2060-
const data = await Git.status(repoPath, porcelainVersion);
2062+
const data = await Git.status(repoPath, porcelainVersion, {
2063+
similarityThreshold: Container.config.advanced.similarityThreshold
2064+
});
20612065
const status = GitStatusParser.parse(data, repoPath, porcelainVersion);
20622066
return status;
20632067
}

0 commit comments

Comments
 (0)