mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 09:35:40 -05:00
Rewrites blame annotation controller and provider - fixes whitespace issues, reduces overhead, and provides better performance Rewrites status bar blame support - reduces overhead and provides better performance Adds showFileHistory command to status bar Renames showHistory to showFileHistory Fixes log to use iso 8601 for dates
53 lines
2.4 KiB
TypeScript
53 lines
2.4 KiB
TypeScript
'use strict';
|
|
import { Iterables } from '../system';
|
|
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
|
import { EditorCommand } from './commands';
|
|
import { BuiltInCommands, Commands } from '../constants';
|
|
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
|
import { Logger } from '../logger';
|
|
import * as path from 'path';
|
|
|
|
export default class DiffWithWorkingCommand extends EditorCommand {
|
|
constructor(private git: GitProvider) {
|
|
super(Commands.DiffWithWorking);
|
|
}
|
|
|
|
async execute(editor: TextEditor): Promise<any>;
|
|
async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise<any>;
|
|
async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise<any> {
|
|
if (!(uri instanceof Uri)) {
|
|
if (!editor.document) return undefined;
|
|
uri = editor.document.uri;
|
|
}
|
|
|
|
line = line || editor.selection.active.line;
|
|
|
|
if (!commit || GitProvider.isUncommitted(commit.sha)) {
|
|
const gitUri = GitUri.fromUri(uri);
|
|
|
|
try {
|
|
const log = await this.git.getLogForFile(gitUri.fsPath);
|
|
if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
|
|
|
|
commit = (gitUri.sha && log.commits.get(gitUri.sha)) || Iterables.first(log.commits.values());
|
|
}
|
|
catch (ex) {
|
|
Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogForFile(${gitUri.fsPath})`, ex);
|
|
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
|
|
}
|
|
}
|
|
|
|
const gitUri = GitUri.fromUri(uri);
|
|
|
|
try {
|
|
const compare = await this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha);
|
|
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), gitUri.fileUri(), `${path.basename(commit.uri.fsPath)} (${commit.sha}) ↔ ${path.basename(gitUri.fsPath)}`);
|
|
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
|
|
}
|
|
catch (ex) {
|
|
Logger.error('[GitLens.DiffWithWorkingCommand]', 'getVersionedFile', ex);
|
|
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
|
|
}
|
|
}
|
|
}
|