Skip to content

Commit

Permalink
Adds rename detection on status
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed May 4, 2019
1 parent 2130072 commit 4c79d0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/git/git.ts
Expand Up @@ -978,25 +978,37 @@ export class Git {
return git<string>({ cwd: repoPath }, ...params);
}

static status(repoPath: string, porcelainVersion: number = 1): Promise<string> {
static status(
repoPath: string,
porcelainVersion: number = 1,
{ similarityThreshold }: { similarityThreshold?: number } = {}
): Promise<string> {
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
return git<string>(
{ cwd: repoPath, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
'status',
porcelain,
'--branch',
'-u'
'-u',
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--'
);
}

static status__file(repoPath: string, fileName: string, porcelainVersion: number = 1): Promise<string> {
static status__file(
repoPath: string,
fileName: string,
porcelainVersion: number = 1,
{ similarityThreshold }: { similarityThreshold?: number } = {}
): Promise<string> {
const [file, root] = Git.splitPath(fileName, repoPath);

const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
return git<string>(
{ cwd: root, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
'status',
porcelain,
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
'--',
file
);
Expand Down
8 changes: 6 additions & 2 deletions src/git/gitService.ts
Expand Up @@ -2044,7 +2044,9 @@ export class GitService implements Disposable {
async getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined> {
const porcelainVersion = Git.validateVersion(2, 11) ? 2 : 1;

const data = await Git.status__file(repoPath, fileName, porcelainVersion);
const data = await Git.status__file(repoPath, fileName, porcelainVersion, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
const status = GitStatusParser.parse(data, repoPath, porcelainVersion);
if (status === undefined || !status.files.length) return undefined;

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

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

const data = await Git.status(repoPath, porcelainVersion);
const data = await Git.status(repoPath, porcelainVersion, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
const status = GitStatusParser.parse(data, repoPath, porcelainVersion);
return status;
}
Expand Down

0 comments on commit 4c79d0f

Please sign in to comment.