From adda8081826102ae30277f53ddfc9eb24bbabf1b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 28 Feb 2018 01:37:21 -0500 Subject: [PATCH] Moves filter into getRemotes --- src/commands/openBranchInRemote.ts | 2 +- src/commands/openBranchesInRemote.ts | 2 +- src/commands/openCommitInRemote.ts | 2 +- src/commands/openFileInRemote.ts | 2 +- src/commands/openRepoInRemote.ts | 2 +- src/gitService.ts | 10 +++++++--- src/quickPicks/branchHistoryQuickPick.ts | 2 +- src/quickPicks/commitFileQuickPick.ts | 2 +- src/quickPicks/commitQuickPick.ts | 2 +- src/quickPicks/fileHistoryQuickPick.ts | 2 +- 10 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/commands/openBranchInRemote.ts b/src/commands/openBranchInRemote.ts index 5c50e45..e6a89a2 100644 --- a/src/commands/openBranchInRemote.ts +++ b/src/commands/openBranchInRemote.ts @@ -52,7 +52,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand { if (args.branch === undefined) return undefined; } - const remotes = (await Container.git.getRemotes(repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(repoPath); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { diff --git a/src/commands/openBranchesInRemote.ts b/src/commands/openBranchesInRemote.ts index f1b384c..051ffb1 100644 --- a/src/commands/openBranchesInRemote.ts +++ b/src/commands/openBranchesInRemote.ts @@ -34,7 +34,7 @@ export class OpenBranchesInRemoteCommand extends ActiveEditorCommand { if (!repoPath) return undefined; try { - const remotes = (await Container.git.getRemotes(repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(repoPath); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { diff --git a/src/commands/openCommitInRemote.ts b/src/commands/openCommitInRemote.ts index 4992565..15dcf47 100644 --- a/src/commands/openCommitInRemote.ts +++ b/src/commands/openCommitInRemote.ts @@ -66,7 +66,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand { args.sha = commit.sha; } - const remotes = (await Container.git.getRemotes(gitUri.repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(gitUri.repoPath); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 8d3489e..544cdb2 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -45,7 +45,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand { } try { - const remotes = (await Container.git.getRemotes(gitUri.repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(gitUri.repoPath); const range = (args.range && editor !== undefined) ? new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 })) : undefined; diff --git a/src/commands/openRepoInRemote.ts b/src/commands/openRepoInRemote.ts index 2c2ed5b..33a00ca 100644 --- a/src/commands/openRepoInRemote.ts +++ b/src/commands/openRepoInRemote.ts @@ -34,7 +34,7 @@ export class OpenRepoInRemoteCommand extends ActiveEditorCommand { if (!repoPath) return undefined; try { - const remotes = (await Container.git.getRemotes(repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(repoPath); return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { diff --git a/src/gitService.ts b/src/gitService.ts index 1d9b07b..d644068 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -1073,15 +1073,19 @@ export class GitService extends Disposable { } } - async getRemotes(repoPath: string | undefined): Promise { + async getRemotes(repoPath: string | undefined, options: { includeAll?: boolean } = {}): Promise { if (repoPath === undefined) return []; Logger.log(`getRemotes('${repoPath}')`); const repository = await this.getRepository(repoPath); - if (repository !== undefined) return repository.getRemotes(); + const remotes = repository !== undefined + ? repository.getRemotes() + : this.getRemotesCore(repoPath); - return this.getRemotesCore(repoPath); + if (options.includeAll) return remotes; + + return (await remotes).filter(r => r.provider !== undefined); } async getRemotesCore(repoPath: string | undefined, providerMap?: RemoteProviderMap): Promise { diff --git a/src/quickPicks/branchHistoryQuickPick.ts b/src/quickPicks/branchHistoryQuickPick.ts index 6df569c..2290d40 100644 --- a/src/quickPicks/branchHistoryQuickPick.ts +++ b/src/quickPicks/branchHistoryQuickPick.ts @@ -36,7 +36,7 @@ export class BranchHistoryQuickPick { } as ShowQuickBranchHistoryCommandArgs ]); - const remotes = (await Container.git.getRemotes((uri && uri.repoPath) || log.repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes((uri && uri.repoPath) || log.repoPath); if (remotes.length) { items.splice(0, 0, new OpenRemotesCommandQuickPickItem(remotes, { type: 'branch', diff --git a/src/quickPicks/commitFileQuickPick.ts b/src/quickPicks/commitFileQuickPick.ts index bbf1729..41d4493 100644 --- a/src/quickPicks/commitFileQuickPick.ts +++ b/src/quickPicks/commitFileQuickPick.ts @@ -120,7 +120,7 @@ export class CommitFileQuickPick { } items.push(new OpenCommitFileRevisionCommandQuickPickItem(commit)); - const remotes = (await Container.git.getRemotes(commit.repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(commit.repoPath); if (remotes.length) { if (commit.workingFileName && commit.status !== 'D') { const branch = await Container.git.getBranch(commit.repoPath); diff --git a/src/quickPicks/commitQuickPick.ts b/src/quickPicks/commitQuickPick.ts index 01cd8ab..e0cdf2a 100644 --- a/src/quickPicks/commitQuickPick.ts +++ b/src/quickPicks/commitQuickPick.ts @@ -129,7 +129,7 @@ export class CommitQuickPick { else { items.splice(index++, 0, new ShowCommitInResultsQuickPickItem(commit)); - const remotes = (await Container.git.getRemotes(commit.repoPath)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(commit.repoPath); if (remotes.length) { items.splice(index++, 0, new OpenRemotesCommandQuickPickItem(remotes, { type: 'commit', diff --git a/src/quickPicks/fileHistoryQuickPick.ts b/src/quickPicks/fileHistoryQuickPick.ts index 4450b48..55b61cd 100644 --- a/src/quickPicks/fileHistoryQuickPick.ts +++ b/src/quickPicks/fileHistoryQuickPick.ts @@ -110,7 +110,7 @@ export class FileHistoryQuickPick { ])); } - const remotes = (await Container.git.getRemotes(uri.repoPath!)).filter(r => r.provider !== undefined); + const remotes = await Container.git.getRemotes(uri.repoPath!); if (remotes.length) { const resource = uri.sha !== undefined ? {