mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-11 18:48:38 -05:00
Combines same url into same remote Adds a change event for custom remote providers Adds a repo change event for custom remote providers
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
'use strict';
|
|
import { commands, TextEditor, Uri, window } from 'vscode';
|
|
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithRemote } from './common';
|
|
import { GitService, GitUri } from '../gitService';
|
|
import { Logger } from '../logger';
|
|
import { OpenInRemoteCommandArgs } from './openInRemote';
|
|
|
|
export interface OpenRepoInRemoteCommandArgs {
|
|
remote?: string;
|
|
}
|
|
|
|
export class OpenRepoInRemoteCommand extends ActiveEditorCommand {
|
|
|
|
constructor(private git: GitService) {
|
|
super(Commands.OpenRepoInRemote);
|
|
}
|
|
|
|
protected async preExecute(context: CommandContext, args: OpenRepoInRemoteCommandArgs = {}): Promise<any> {
|
|
if (isCommandViewContextWithRemote(context)) {
|
|
args = { ...args };
|
|
args.remote = context.node.remote.name;
|
|
}
|
|
|
|
return this.execute(context.editor, context.uri, args);
|
|
}
|
|
|
|
async execute(editor?: TextEditor, uri?: Uri, args: OpenRepoInRemoteCommandArgs = {}) {
|
|
uri = getCommandUri(uri, editor);
|
|
|
|
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
|
|
|
const repoPath = gitUri === undefined ? this.git.repoPath : gitUri.repoPath;
|
|
if (!repoPath) return undefined;
|
|
|
|
try {
|
|
const remotes = (await this.git.getRemotes(repoPath)).filter(r => r.provider !== undefined);
|
|
|
|
return commands.executeCommand(Commands.OpenInRemote, uri, {
|
|
resource: {
|
|
type: 'repo'
|
|
},
|
|
remote: args.remote,
|
|
remotes
|
|
} as OpenInRemoteCommandArgs);
|
|
}
|
|
catch (ex) {
|
|
Logger.error(ex, 'OpenRepoInRemoteCommand');
|
|
return window.showErrorMessage(`Unable to open repository in remote provider. See output channel for more details`);
|
|
}
|
|
}
|
|
} |