diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index 8d4486e..0822124 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -10,6 +10,7 @@ import { OpenInRemoteCommandArgs } from './openInRemote'; export interface OpenBranchInRemoteCommandArgs { branch?: string; + remote?: string; } export class OpenBranchInRemoteCommand extends ActiveEditorCommand { @@ -21,7 +22,9 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { protected async preExecute(context: CommandContext, args: OpenBranchInRemoteCommandArgs = {}): Promise { if (isCommandViewContextWithBranch(context)) { args = { ...args }; + args.branch = context.node.branch.name; + args.remote = context.node.branch.getRemote(); return this.execute(context.editor, context.uri, args); } @@ -57,6 +60,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { type: 'branch', branch: args.branch }, + remote: args.remote, remotes } as OpenInRemoteCommandArgs); } diff --git a/src/commands/openBranchesInRemote.ts b/src/commands/openBranchesInRemote.ts index ddee149..0b1775b 100644 --- a/src/commands/openBranchesInRemote.ts +++ b/src/commands/openBranchesInRemote.ts @@ -35,15 +35,13 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand { if (!repoPath) return undefined; try { - 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); - } + const remotes = Arrays.uniqueBy(await this.git.getRemotes(repoPath), r => r.url, r => !!r.provider); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { type: 'branches' }, + remote: args.remote, remotes } as OpenInRemoteCommandArgs); } diff --git a/src/commands/openInRemote.ts b/src/commands/openInRemote.ts index a5bc29a..4b78cbb 100644 --- a/src/commands/openInRemote.ts +++ b/src/commands/openInRemote.ts @@ -8,6 +8,7 @@ import { Logger } from '../logger'; import { CommandQuickPickItem, OpenRemoteCommandQuickPickItem, RemotesQuickPick } from '../quickPicks'; export interface OpenInRemoteCommandArgs { + remote?: string; remotes?: GitRemote[]; resource?: RemoteResource; @@ -26,6 +27,14 @@ export class OpenInRemoteCommand extends ActiveEditorCommand { args = { ...args }; if (args.remotes === undefined || args.resource === undefined) return undefined; + if (args.remote !== undefined) { + const remotes = args.remotes.filter(r => r.name === args.remote); + // Only filter if we get some results + if (remotes.length > 0) { + args.remotes = remotes; + } + } + try { if (args.remotes.length === 1) { this.ensureRemoteBranchName(args); diff --git a/src/commands/openRepoInRemote.ts b/src/commands/openRepoInRemote.ts index 82bbe8b..67a91cb 100644 --- a/src/commands/openRepoInRemote.ts +++ b/src/commands/openRepoInRemote.ts @@ -35,15 +35,13 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand { if (!repoPath) return undefined; try { - 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); - } + const remotes = Arrays.uniqueBy(await this.git.getRemotes(repoPath), r => r.url, r => !!r.provider); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { type: 'repo' }, + remote: args.remote, remotes } as OpenInRemoteCommandArgs); }