Fixes issues with diff with previous

Wouldn't always grab the correct commit
This commit is contained in:
Eric Amodio
2017-02-13 11:42:54 -05:00
parent 3ef538b713
commit d5d0c3a28d
6 changed files with 20 additions and 48 deletions

View File

@@ -34,7 +34,7 @@ export default class DiffWithPreviousCommand extends EditorCommand {
const gitUri = GitUri.fromUri(uri, this.git);
try {
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, rangeOrLine as Range);
const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range);
if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
const sha = (commit && commit.sha) || gitUri.sha;
@@ -51,38 +51,10 @@ export default class DiffWithPreviousCommand extends EditorCommand {
}
try {
let rhs: string;
try {
rhs = await this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha);
}
catch (ex) {
if (ex.message.includes(`fatal: Path '${commit.originalFileName}' does not exist in '${commit.sha}'`)) {
try {
rhs = await this.git.getVersionedFile(commit.fileName, commit.repoPath, commit.sha);
}
catch (ex) {
Logger.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
}
}
}
let lhs: string;
try {
lhs = await this.git.getVersionedFile(commit.previousUri.fsPath, commit.repoPath, commit.previousSha);
}
catch (ex) {
if (ex.message.includes(`fatal: Path '${commit.previousFileName}' does not exist in '${commit.previousSha}'`)) {
try {
lhs = await this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.previousSha);
}
catch (ex) {
Logger.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
}
}
}
const [rhs, lhs] = await Promise.all([
this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha),
this.git.getVersionedFile(commit.previousUri.fsPath, commit.repoPath, commit.previousSha)
]);
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(lhs), Uri.file(rhs), `${path.basename(commit.previousUri.fsPath)} (${commit.previousSha}) ↔ ${path.basename(commit.uri.fsPath)} (${commit.sha})`);
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
}