Skip to content

Commit 46f7d6c

Browse files
committed
Fixes #736 - unsupported find-renames on older git
1 parent 98e225f commit 46f7d6c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/git/git.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -990,14 +990,19 @@ export class Git {
990990
porcelainVersion: number = 1,
991991
{ similarityThreshold }: { similarityThreshold?: number } = {}
992992
): Promise<string> {
993-
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
994-
return git<string>(
995-
{ cwd: repoPath, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
993+
const params = [
996994
'status',
997-
porcelain,
995+
porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain',
998996
'--branch',
999-
'-u',
1000-
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
997+
'-u'
998+
];
999+
if (Git.validateVersion(2, 18)) {
1000+
params.push(`--find-renames=${similarityThreshold == null ? '' : `${similarityThreshold}%`}`);
1001+
}
1002+
1003+
return git<string>(
1004+
{ cwd: repoPath, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
1005+
...params,
10011006
'--'
10021007
);
10031008
}
@@ -1010,12 +1015,14 @@ export class Git {
10101015
): Promise<string> {
10111016
const [file, root] = Git.splitPath(fileName, repoPath);
10121017

1013-
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
1018+
const params = ['status', porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain'];
1019+
if (Git.validateVersion(2, 18)) {
1020+
params.push(`--find-renames=${similarityThreshold == null ? '' : `${similarityThreshold}%`}`);
1021+
}
1022+
10141023
return git<string>(
10151024
{ cwd: root, configs: ['-c', 'color.status=false'], env: { GIT_OPTIONAL_LOCKS: '0' } },
1016-
'status',
1017-
porcelain,
1018-
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
1025+
...params,
10191026
'--',
10201027
file
10211028
);

0 commit comments

Comments
 (0)