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

@@ -20,11 +20,11 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
let workingFileName = commit && commit.workingFileName; let workingFileName = commit && commit.workingFileName;
const gitUri = await GitUri.fromUri(uri, this.git);
if (!sha) { if (!sha) {
if (!editor) return undefined; if (!editor) return undefined;
const gitUri = await GitUri.fromUri(uri, this.git);
const blameline = editor.selection.active.line - gitUri.offset; const blameline = editor.selection.active.line - gitUri.offset;
if (blameline < 0) return undefined; if (blameline < 0) return undefined;
@@ -54,7 +54,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
} }
if (!fileLog) { if (!fileLog) {
const log = await this.git.getLogForFile(undefined, commit ? commit.uri.fsPath : uri.fsPath, sha, undefined, 2); const log = await this.git.getLogForFile(commit ? commit.repoPath : gitUri.repoPath, commit ? commit.uri.fsPath : gitUri.fsPath, sha, undefined, 2);
if (!log) return window.showWarningMessage(`Unable to show commit file details`); if (!log) return window.showWarningMessage(`Unable to show commit file details`);
commit = log.commits.get(sha); commit = log.commits.get(sha);

View File

@@ -87,10 +87,10 @@ export class Git {
} }
static normalizePath(fileName: string, repoPath?: string) { 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) { if (repoPath) {
fileName = this.normalizePath(fileName); fileName = this.normalizePath(fileName);
repoPath = this.normalizePath(repoPath); repoPath = this.normalizePath(repoPath);
@@ -101,8 +101,8 @@ export class Git {
} }
} }
else { else {
repoPath = this.normalizePath(path.dirname(fileName)); repoPath = this.normalizePath(extract ? path.dirname(fileName) : repoPath);
fileName = this.normalizePath(path.basename(fileName)); fileName = this.normalizePath(extract ? path.basename(fileName) : fileName);
} }
return [ fileName, repoPath ]; return [ fileName, repoPath ];
@@ -111,7 +111,7 @@ export class Git {
// 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(fileName, repoPath); const [file, root] = Git.splitPath(fileName, repoPath);
const params = [`blame`, `--root`, `--incremental`]; const params = [`blame`, `--root`, `--incremental`];

View File

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

View File

@@ -304,7 +304,7 @@ export class GitService extends Disposable {
} }
private async _getBlameForFile(uri: GitUri, fileName: string, entry: GitCacheEntry | undefined): Promise<IGitBlame> { private async _getBlameForFile(uri: GitUri, fileName: string, entry: GitCacheEntry | undefined): Promise<IGitBlame> {
const [file, root] = Git.splitPath(fileName, uri.repoPath); const [file, root] = Git.splitPath(fileName, uri.repoPath, false);
const ignore = await this._gitignore; const ignore = await this._gitignore;
if (ignore && !ignore.filter([file]).length) { if (ignore && !ignore.filter([file]).length) {
@@ -317,7 +317,7 @@ export class GitService extends Disposable {
try { try {
const data = await Git.blame(root, file, uri.sha); const data = await Git.blame(root, file, uri.sha);
return GitBlameParser.parse(data, file); return GitBlameParser.parse(data, root, file);
} }
catch (ex) { catch (ex) {
// Trap and cache expected blame errors // Trap and cache expected blame errors
@@ -360,7 +360,7 @@ export class GitService extends Disposable {
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);
const blame = GitBlameParser.parse(data, fileName); const blame = GitBlameParser.parse(data, uri.repoPath, fileName);
if (!blame) return undefined; if (!blame) return undefined;
const commit = Iterables.first(blame.commits.values()); const commit = Iterables.first(blame.commits.values());
@@ -530,7 +530,7 @@ export class GitService extends Disposable {
} }
private async _getLogForFile(repoPath: string, fileName: string, sha: string, range: Range, maxCount: number, reverse: boolean, entry: GitCacheEntry | undefined): Promise<IGitLog> { private async _getLogForFile(repoPath: string, fileName: string, sha: string, range: Range, maxCount: number, reverse: boolean, entry: GitCacheEntry | undefined): Promise<IGitLog> {
const [file, root] = Git.splitPath(fileName, repoPath); const [file, root] = Git.splitPath(fileName, repoPath, false);
const ignore = await this._gitignore; const ignore = await this._gitignore;
if (ignore && !ignore.filter([file]).length) { if (ignore && !ignore.filter([file]).length) {