Fixes issue showing repo history w/ no active editor

This commit is contained in:
Eric Amodio
2017-03-15 12:00:33 -04:00
parent 564a0b8f64
commit 2ef6c37c89
7 changed files with 57 additions and 27 deletions

View File

@@ -11,7 +11,9 @@ export class GitUri extends Uri {
repoPath?: string | undefined;
sha?: string | undefined;
constructor(uri?: Uri, commit?: IGitCommitInfo) {
constructor(uri?: Uri, commit?: IGitCommitInfo);
constructor(uri?: Uri, repoPath?: string);
constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) {
super();
if (!uri) return;
@@ -33,12 +35,18 @@ export class GitUri extends Uri {
this.repoPath = data.repoPath;
}
}
else if (commit) {
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
else if (commitOrRepoPath) {
if (typeof commitOrRepoPath === 'string') {
this.repoPath = commitOrRepoPath;
}
else {
const commit = commitOrRepoPath;
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
if (!Git.isUncommitted(commit.sha)) {
this.sha = commit.sha;
this.repoPath = commit.repoPath;
if (!Git.isUncommitted(commit.sha)) {
this.sha = commit.sha;
this.repoPath = commit.repoPath;
}
}
}
}
@@ -51,6 +59,16 @@ export class GitUri extends Uri {
return Uri.file(this.sha ? this.path : this.fsPath);
}
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
let directory = path.dirname(this.fsPath);
if (this.repoPath) {
directory = path.relative(this.repoPath, directory);
}
return (!directory || directory === '.')
? path.basename(this.fsPath)
: `${path.basename(this.fsPath)}${separator}${directory}`;
}
static async fromUri(uri: Uri, git: GitProvider) {
if (uri instanceof GitUri) return uri;
@@ -64,7 +82,7 @@ export class GitUri extends Uri {
if (commit) return new GitUri(uri, commit);
}
return new GitUri(uri);
return new GitUri(uri, git && git.repoPath);
}
}