Adds Open Branches in Remote command to the Remote custom view items

Adds Open Repository in Remote command to the Remote custom view items
This commit is contained in:
Eric Amodio
2017-09-03 16:33:52 -04:00
parent 22378d5f25
commit 2bba14260f
6 changed files with 75 additions and 13 deletions

View File

@@ -1,18 +1,32 @@
'use strict';
import { Arrays } from '../system';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
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);
}
async execute(editor?: TextEditor, uri?: Uri) {
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);
}
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);
@@ -21,7 +35,11 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand {
if (!repoPath) return undefined;
try {
const remotes = Arrays.uniqueBy(await this.git.getRemotes(repoPath), _ => _.url, _ => !!_.provider);
let remotes = Arrays.uniqueBy(await this.git.getRemotes(repoPath), r => r.url, r => !!r.provider);
if (args.remote !== undefined) {
remotes = remotes.filter(r => r.name === args.remote);
}
return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'repo'