Fixes more issues with paths :(

This commit is contained in:
Eric Amodio
2017-03-22 03:04:52 -04:00
parent 671f1ca6c1
commit 43e4337358
4 changed files with 16 additions and 17 deletions

View File

@@ -87,10 +87,10 @@ export class Git {
}
static normalizePath(fileName: string, repoPath?: string) {
return fileName.replace(/\\/g, '/');
return fileName && fileName.replace(/\\/g, '/');
}
static splitPath(fileName: string, repoPath?: string): [string, string] {
static splitPath(fileName: string, repoPath: string | undefined, extract: boolean = true): [string, string] {
if (repoPath) {
fileName = this.normalizePath(fileName);
repoPath = this.normalizePath(repoPath);
@@ -101,8 +101,8 @@ export class Git {
}
}
else {
repoPath = this.normalizePath(path.dirname(fileName));
fileName = this.normalizePath(path.basename(fileName));
repoPath = this.normalizePath(extract ? path.dirname(fileName) : repoPath);
fileName = this.normalizePath(extract ? path.basename(fileName) : fileName);
}
return [ fileName, repoPath ];
@@ -111,7 +111,7 @@ export class Git {
// Git commands
static blame(repoPath: string, fileName: string, sha?: string, startLine?: number, endLine?: number) {
const [file, root]: [string, string] = Git.splitPath(fileName, repoPath);
const [file, root] = Git.splitPath(fileName, repoPath);
const params = [`blame`, `--root`, `--incremental`];

View File

@@ -116,7 +116,7 @@ export class GitBlameParser {
return entries;
}
static parse(data: string, fileName: string): IGitBlame {
static parse(data: string, repoPath: string, fileName: string): IGitBlame {
const entries = this._parseEntries(data);
if (!entries) return undefined;
@@ -124,16 +124,15 @@ export class GitBlameParser {
const commits: Map<string, GitCommit> = new Map();
const lines: Array<IGitCommitLine> = [];
let repoPath: string;
let relativeFileName: string;
let relativeFileName = repoPath && fileName;
for (let i = 0, len = entries.length; i < len; i++) {
const entry = entries[i];
if (i === 0) {
if (i === 0 && !repoPath) {
// Try to get the repoPath from the most recent commit
repoPath = Git.normalizePath(fileName.replace(`/${entry.fileName}`, ''));
relativeFileName = path.relative(repoPath, fileName).replace(/\\/g, '/');
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
}
let commit = commits.get(entry.sha);