Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 

65 rader
2.0 KiB

'use strict';
import { commands, TextEditor, Uri, window } from 'vscode';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitService';
import { Logger } from '../logger';
import {
ActiveEditorCommand,
CommandContext,
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
isCommandViewContextWithRemote
} from './common';
import { OpenInRemoteCommandArgs } from './openInRemote';
export interface OpenBranchesInRemoteCommandArgs {
remote?: string;
}
export class OpenBranchesInRemoteCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenBranchesInRemote);
}
protected async preExecute(context: CommandContext, args: OpenBranchesInRemoteCommandArgs = {}): 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: OpenBranchesInRemoteCommandArgs = {}) {
uri = getCommandUri(uri, editor);
const gitUri = uri && (await GitUri.fromUri(uri));
const repoPath = await getRepoPathOrActiveOrPrompt(
gitUri,
editor,
`Open branches on remote for which repository${GlyphChars.Ellipsis}`
);
if (!repoPath) return undefined;
try {
const remotes = await Container.git.getRemotes(repoPath);
return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'branches'
},
remote: args.remote,
remotes
} as OpenInRemoteCommandArgs);
}
catch (ex) {
Logger.error(ex, 'OpenBranchesInRemoteCommand');
return window.showErrorMessage(
`Unable to open branches on remote provider. See output channel for more details`
);
}
}
}