mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 17:25:33 -05:00
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
'use strict';
|
|
import { commands, TextEditor, Uri, window } from 'vscode';
|
|
import { ActiveEditorCommand, Commands } from '../commands';
|
|
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
|
import { Logger } from '../logger';
|
|
import { CommandQuickPickItem } from './quickPickItems';
|
|
import { FileCommitsQuickPick } from './quickPicks';
|
|
|
|
export default class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
|
|
|
constructor(private git: GitProvider) {
|
|
super(Commands.ShowQuickFileHistory);
|
|
}
|
|
|
|
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, commit?: GitCommit, goBackCommand?: CommandQuickPickItem) {
|
|
if (!(uri instanceof Uri)) {
|
|
uri = editor && editor.document && editor.document.uri;
|
|
}
|
|
|
|
if (!uri) {
|
|
return commands.executeCommand(Commands.ShowQuickRepoHistory);
|
|
}
|
|
|
|
const gitUri = GitUri.fromUri(uri, this.git);
|
|
|
|
if (maxCount == null) {
|
|
maxCount = this.git.config.advanced.maxQuickHistory;
|
|
}
|
|
|
|
try {
|
|
if (!commit) {
|
|
const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
|
if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`);
|
|
|
|
let pick = await FileCommitsQuickPick.show(log, uri, maxCount, this.git.config.advanced.maxQuickHistory, goBackCommand);
|
|
if (!pick) return undefined;
|
|
|
|
if (pick instanceof CommandQuickPickItem) {
|
|
return pick.execute();
|
|
}
|
|
|
|
commit = pick.commit;
|
|
}
|
|
|
|
return commands.executeCommand(Commands.ShowQuickCommitDetails,
|
|
new GitUri(commit.uri, commit),
|
|
commit.sha, commit,
|
|
new CommandQuickPickItem({
|
|
label: `go back \u21A9`,
|
|
description: null
|
|
}, Commands.ShowQuickFileHistory, [uri, maxCount, undefined, goBackCommand]),
|
|
{ showFileHistory: false });
|
|
}
|
|
catch (ex) {
|
|
Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex);
|
|
return window.showErrorMessage(`Unable to show file history. See output channel for more details`);
|
|
}
|
|
}
|
|
} |