mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Allows showQuickRepoHistory w/o opened editor
It falls back to the folder repository
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { commands, QuickPickItem, QuickPickOptions, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
import { commands, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||||
import { EditorCommand } from './commands';
|
import { Command } from './commands';
|
||||||
import { Commands } from '../constants';
|
import { Commands } from '../constants';
|
||||||
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -32,23 +32,32 @@ class FileQuickPickItem implements QuickPickItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ShowQuickRepoHistoryCommand extends EditorCommand {
|
export default class ShowQuickRepoHistoryCommand extends Command {
|
||||||
constructor(private git: GitProvider) {
|
constructor(private git: GitProvider, public repoPath: string) {
|
||||||
super(Commands.ShowQuickRepoHistory);
|
super(Commands.ShowQuickRepoHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri) {
|
async execute(uri?: Uri) {
|
||||||
if (!(uri instanceof Uri)) {
|
if (!(uri instanceof Uri)) {
|
||||||
if (!editor.document) return undefined;
|
const document = window.activeTextEditor && window.activeTextEditor.document;
|
||||||
uri = editor.document.uri;
|
if (document) {
|
||||||
|
uri = document.uri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitUri = GitUri.fromUri(uri);
|
|
||||||
|
|
||||||
let repoPath = gitUri.repoPath;
|
|
||||||
try {
|
try {
|
||||||
|
let repoPath: string;
|
||||||
|
if (uri instanceof Uri) {
|
||||||
|
const gitUri = GitUri.fromUri(uri);
|
||||||
|
repoPath = gitUri.repoPath;
|
||||||
|
|
||||||
|
if (!repoPath) {
|
||||||
|
repoPath = await this.git.getRepoPathFromFile(gitUri.fsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!repoPath) {
|
if (!repoPath) {
|
||||||
repoPath = await this.git.getRepoPathFromFile(gitUri.fsPath);
|
repoPath = this.repoPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
||||||
@@ -72,9 +81,11 @@ export default class ShowQuickRepoHistoryCommand extends EditorCommand {
|
|||||||
|
|
||||||
if (filePick) {
|
if (filePick) {
|
||||||
const commit = new GitCommit(commitPick.commit.repoPath, commitPick.commit.sha, filePick.fileName, commitPick.commit.author, commitPick.commit.date, commitPick.commit.message, undefined, undefined, commitPick.commit.previousSha);
|
const commit = new GitCommit(commitPick.commit.repoPath, commitPick.commit.sha, filePick.fileName, commitPick.commit.author, commitPick.commit.date, commitPick.commit.message, undefined, undefined, commitPick.commit.previousSha);
|
||||||
commands.executeCommand(Commands.DiffWithWorking, filePick.uri, commit);
|
return commands.executeCommand(Commands.DiffWithWorking, filePick.uri, commit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', 'getLogLocations', ex);
|
Logger.error('[GitLens.ShowQuickRepoHistoryCommand]', 'getLogLocations', ex);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export async function activate(context: ExtensionContext) {
|
|||||||
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
||||||
context.subscriptions.push(new ShowFileHistoryCommand(git));
|
context.subscriptions.push(new ShowFileHistoryCommand(git));
|
||||||
context.subscriptions.push(new ShowQuickFileHistoryCommand(git));
|
context.subscriptions.push(new ShowQuickFileHistoryCommand(git));
|
||||||
context.subscriptions.push(new ShowQuickRepoHistoryCommand(git));
|
context.subscriptions.push(new ShowQuickRepoHistoryCommand(git, repoPath));
|
||||||
context.subscriptions.push(new ToggleCodeLensCommand(git));
|
context.subscriptions.push(new ToggleCodeLensCommand(git));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user