From e906bfcb9ef51c5ec8cc748b1e2cdee48218267c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 24 Mar 2017 11:41:20 -0400 Subject: [PATCH] Hides remote commands when there are no remotes --- package.json | 6 +++--- src/commands.ts | 1 + src/extension.ts | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bdd7e65..c2befcc 100644 --- a/package.json +++ b/package.json @@ -585,11 +585,11 @@ }, { "command": "gitlens.openCommitInRemote", - "when": "editorTextFocus && gitlens:enabled && gitlens:isBlameable && config.gitlens.insiders" + "when": "editorTextFocus && gitlens:enabled && gitlens:hasRemotes && gitlens:isBlameable" }, { "command": "gitlens.openFileInRemote", - "when": "editorTextFocus && gitlens:enabled && config.gitlens.insiders" + "when": "editorTextFocus && gitlens:enabled && gitlens:hasRemotes" } ], "explorer/context": [ @@ -600,7 +600,7 @@ }, { "command": "gitlens.openFileInRemote", - "when": "gitlens:enabled && config.gitlens.insiders", + "when": "gitlens:enabled && gitlens:hasRemotes", "group": "gitlens@2" }, { diff --git a/src/commands.ts b/src/commands.ts index 84e2d42..8565cc7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -36,6 +36,7 @@ export type CommandContext = 'gitlens:canToggleCodeLens' | 'gitlens:enabled' | ' export const CommandContext = { CanToggleCodeLens: 'gitlens:canToggleCodeLens' as CommandContext, Enabled: 'gitlens:enabled' as CommandContext, + HasRemotes: 'gitlens:hasRemotes' as CommandContext, IsBlameable: 'gitlens:isBlameable' as CommandContext, Key: 'gitlens:key' as CommandContext }; diff --git a/src/extension.ts b/src/extension.ts index 6006918..2a2d24a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -76,6 +76,8 @@ export async function activate(context: ExtensionContext) { const git = new GitService(context); context.subscriptions.push(git); + setRemoteCommandsContext(context, git); + const blameabilityTracker = new BlameabilityTracker(git); context.subscriptions.push(blameabilityTracker); @@ -150,4 +152,13 @@ async function notifyOnUnsupportedGitVersion(context: ExtensionContext, version: context.globalState.update(WorkspaceState.SuppressGitVersionWarning, true); } } +} + +async function setRemoteCommandsContext(context: ExtensionContext, git: GitService): Promise { + let hasRemotes = false; + if (git.config.insiders) { + const remotes = await git.getRemotes(git.repoPath); + hasRemotes = remotes.length !== 0; + } + setCommandContext(CommandContext.HasRemotes, hasRemotes); } \ No newline at end of file