Fixes #55 - adds fallback for previous git versions

Reverts git version requirement to >= 2.2.0
This commit is contained in:
Eric Amodio
2017-03-27 10:56:58 -04:00
parent 758d331e69
commit 46ff70e969
5 changed files with 64 additions and 17 deletions

View File

@@ -109,6 +109,11 @@ export class Git {
return [ fileName, repoPath ];
}
static validateVersion(major: number, minor: number): boolean {
const [gitMajor, gitMinor] = git.version.split('.');
return (parseInt(gitMajor, 10) >= major && parseInt(gitMinor, 10) >= minor);
}
// Git commands
static blame(repoPath: string, fileName: string, sha?: string, startLine?: number, endLine?: number) {
@@ -230,15 +235,17 @@ export class Git {
return gitCommand(repoPath, ...params);
}
static status(repoPath: string): Promise<string> {
const params = ['status', '--porcelain=v2', '--branch'];
static status(repoPath: string, porcelainVersion: number = 1): Promise<string> {
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
const params = ['status', porcelain, '--branch'];
return gitCommand(repoPath, ...params);
}
static status_file(repoPath: string, fileName: string): Promise<string> {
static status_file(repoPath: string, fileName: string, porcelainVersion: number = 1): Promise<string> {
const [file, root] = Git.splitPath(fileName, repoPath);
const params = ['status', '--porcelain=v2', file];
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
const params = ['status', porcelain, file];
return gitCommand(root, ...params);
}
}