Fixes #31 - Disable gitlens if no .git folder

This commit is contained in:
Eric Amodio
2017-02-16 10:43:28 -05:00
parent 0d7633c78a
commit 4d0c18f330
3 changed files with 83 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
export const RepoPath = 'repoPath';
export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider';
export type BuiltInCommands = 'cursorMove' | 'editor.action.showReferences' | 'editor.action.toggleRenderWhitespace' | 'editorScroll' | 'revealLine' | 'vscode.diff' | 'vscode.executeDocumentSymbolProvider' | 'vscode.executeCodeLensProvider' | 'setContext';
export const BuiltInCommands = {
CursorMove: 'cursorMove' as BuiltInCommands,
Diff: 'vscode.diff' as BuiltInCommands,
@@ -10,6 +10,7 @@ export const BuiltInCommands = {
ExecuteDocumentSymbolProvider: 'vscode.executeDocumentSymbolProvider' as BuiltInCommands,
ExecuteCodeLensProvider: 'vscode.executeCodeLensProvider' as BuiltInCommands,
RevealLine: 'revealLine' as BuiltInCommands,
SetContext: 'setContext' as BuiltInCommands,
ShowReferences: 'editor.action.showReferences' as BuiltInCommands,
ToggleRenderWhitespace: 'editor.action.toggleRenderWhitespace' as BuiltInCommands
};

View File

@@ -1,5 +1,5 @@
'use strict';
import { ExtensionContext, languages, window, workspace } from 'vscode';
import { commands, ExtensionContext, languages, window, workspace } from 'vscode';
import BlameActiveLineController from './blameActiveLineController';
import BlameAnnotationController from './blameAnnotationController';
import { configureCssCharacters } from './blameAnnotationFormatter';
@@ -17,7 +17,7 @@ import ShowQuickRepoHistoryCommand from './commands/showQuickRepoHistory';
import ToggleBlameCommand from './commands/toggleBlame';
import ToggleCodeLensCommand from './commands/toggleCodeLens';
import { IAdvancedConfig, IBlameConfig } from './configuration';
import { WorkspaceState } from './constants';
import { BuiltInCommands, WorkspaceState } from './constants';
import GitContentProvider from './gitContentProvider';
import GitProvider, { Git } from './gitProvider';
import GitRevisionCodeLensProvider from './gitRevisionCodeLensProvider';
@@ -49,9 +49,19 @@ export async function activate(context: ExtensionContext) {
if (ex.message.includes('Unable to find git')) {
await window.showErrorMessage(`GitLens: Unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.`);
}
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', false);
return;
}
let gitEnabled = workspace.getConfiguration('git').get<boolean>('enabled');
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled);
context.subscriptions.push(workspace.onDidChangeConfiguration(() => {
if (gitEnabled !== workspace.getConfiguration('git').get<boolean>('enabled')) {
gitEnabled = !gitEnabled;
commands.executeCommand(BuiltInCommands.SetContext, 'gitlens:enabled', gitEnabled);
}
}, this));
context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
const git = new GitProvider(context);