mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 01:25:42 -05:00
Fixes issues with diff with previous
Wouldn't always grab the correct commit
This commit is contained in:
@@ -21,7 +21,7 @@ export default class DiffLineWithPreviousCommand extends EditorCommand {
|
||||
}
|
||||
|
||||
line = line || editor.selection.active.line;
|
||||
const gitUri = GitUri.fromUri(uri, this.git);
|
||||
let gitUri = GitUri.fromUri(uri, this.git);
|
||||
|
||||
if (!commit || GitProvider.isUncommitted(commit.sha)) {
|
||||
const blameline = line - gitUri.offset;
|
||||
@@ -32,10 +32,10 @@ export default class DiffLineWithPreviousCommand extends EditorCommand {
|
||||
if (!blame) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
|
||||
|
||||
commit = blame.commit;
|
||||
// If the current commit matches the blame, show the previous
|
||||
if (gitUri.sha === commit.sha) {
|
||||
commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message);
|
||||
line = blame.line.line + 1 + gitUri.offset;
|
||||
|
||||
// If we don't have a sha or the current commit matches the blame, show the previous
|
||||
if (!gitUri.sha || gitUri.sha === commit.sha) {
|
||||
return commands.executeCommand(Commands.DiffWithPrevious, new GitUri(uri, commit), undefined, line);
|
||||
}
|
||||
|
||||
// If the line is uncommitted, find the previous commit and treat it as a DiffWithWorking
|
||||
@@ -53,11 +53,11 @@ export default class DiffLineWithPreviousCommand extends EditorCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
const values = await Promise.all([
|
||||
const [rhs, lhs] = await Promise.all([
|
||||
this.git.getVersionedFile(gitUri.fsPath, gitUri.repoPath, gitUri.sha),
|
||||
this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha)
|
||||
]);
|
||||
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(values[1]), Uri.file(values[0]), `${path.basename(commit.uri.fsPath)} (${commit.sha}) ↔ ${path.basename(gitUri.fsPath)} (${gitUri.sha})`);
|
||||
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(lhs), Uri.file(rhs), `${path.basename(commit.uri.fsPath)} (${commit.sha}) ↔ ${path.basename(gitUri.fsPath)} (${gitUri.sha})`);
|
||||
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
|
||||
}
|
||||
catch (ex) {
|
||||
|
||||
Reference in New Issue
Block a user