Fixes pathing issues on Windows

This commit is contained in:
Eric Amodio
2017-03-21 14:01:36 -04:00
parent 3e84ec88e2
commit 97f88489a4
2 changed files with 16 additions and 12 deletions

View File

@@ -91,22 +91,26 @@ export class Git {
static splitPath(fileName: string, repoPath?: string): [string, string] { static splitPath(fileName: string, repoPath?: string): [string, string] {
if (repoPath) { if (repoPath) {
return [ const normalizedRepoPath = (repoPath.endsWith('/') ? repoPath : `${repoPath}/`).toLowerCase();
fileName.replace(repoPath.endsWith('/') ? repoPath : `${repoPath}/`, ''), if (fileName.toLowerCase().startsWith(normalizedRepoPath)) {
repoPath fileName = fileName.substring(normalizedRepoPath.length);
]; }
}
else {
repoPath = path.dirname(fileName);
fileName = path.basename(fileName);
} }
return [ return [
path.basename(fileName).replace(/\\/g, '/'), this.normalizePath(fileName),
path.dirname(fileName).replace(/\\/g, '/') this.normalizePath(repoPath)
]; ];
} }
// Git commands // Git commands
static blame(repoPath: string, fileName: string, sha?: string, startLine?: number, endLine?: number) { static blame(repoPath: string, fileName: string, sha?: string, startLine?: number, endLine?: number) {
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath); const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
const params = [`blame`, `--root`, `--incremental`]; const params = [`blame`, `--root`, `--incremental`];
@@ -152,7 +156,7 @@ export class Git {
} }
static show(repoPath: string, fileName: string, branchOrSha: string) { static show(repoPath: string, fileName: string, branchOrSha: string) {
const [file, root] = Git.splitPath(Git.normalizePath(fileName), repoPath); const [file, root] = Git.splitPath(fileName, repoPath);
branchOrSha = branchOrSha.replace('^', ''); branchOrSha = branchOrSha.replace('^', '');
if (Git.isUncommitted(branchOrSha)) return Promise.reject(new Error(`sha=${branchOrSha} is uncommitted`)); if (Git.isUncommitted(branchOrSha)) return Promise.reject(new Error(`sha=${branchOrSha} is uncommitted`));
@@ -178,7 +182,7 @@ export class Git {
} }
static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) { static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) {
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath); const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
const params = [...defaultLogParams, `--no-merges`, `--follow`]; const params = [...defaultLogParams, `--no-merges`, `--follow`];
if (maxCount && !reverse) { if (maxCount && !reverse) {
@@ -211,7 +215,7 @@ export class Git {
} }
static status_file(repoPath: string, fileName: string): Promise<string> { static status_file(repoPath: string, fileName: string): Promise<string> {
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath); const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
const params = ['status', '--porcelain=v2', file]; const params = ['status', '--porcelain=v2', file];
return gitCommand(root, ...params); return gitCommand(root, ...params);

View File

@@ -276,7 +276,7 @@ export class GitService extends Disposable {
async getBlameForFile(uri: GitUri): Promise<IGitBlame | undefined> { async getBlameForFile(uri: GitUri): Promise<IGitBlame | undefined> {
Logger.log(`getBlameForFile('${uri.repoPath}', '${uri.fsPath}', ${uri.sha})`); Logger.log(`getBlameForFile('${uri.repoPath}', '${uri.fsPath}', ${uri.sha})`);
const fileName = Git.normalizePath(uri.fsPath, uri.repoPath); const fileName = Git.normalizePath(uri.fsPath);
let entry: GitCacheEntry | undefined; let entry: GitCacheEntry | undefined;
if (this.UseGitCaching && !uri.sha) { if (this.UseGitCaching && !uri.sha) {
@@ -356,7 +356,7 @@ export class GitService extends Disposable {
} as IGitBlameLine; } as IGitBlameLine;
} }
const fileName = Git.normalizePath(uri.fsPath, uri.repoPath); const fileName = Git.normalizePath(uri.fsPath);
try { try {
const data = await Git.blame(uri.repoPath, fileName, uri.sha, line + 1, line + 1); const data = await Git.blame(uri.repoPath, fileName, uri.sha, line + 1, line + 1);