mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-14 18:48:28 -05:00
Adds support for custom git installation locations
Also gracefully deals with the times when git isn't in the PATH
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
import { ExtensionContext, extensions, languages, workspace } from 'vscode';
|
||||
import { ExtensionContext, extensions, languages, window, workspace } from 'vscode';
|
||||
import BlameAnnotationController from './blameAnnotationController';
|
||||
import BlameStatusBarController from './blameStatusBarController';
|
||||
import GitContentProvider from './gitContentProvider';
|
||||
@@ -7,6 +7,8 @@ import GitBlameCodeLensProvider from './gitBlameCodeLensProvider';
|
||||
import GitBlameContentProvider from './gitBlameContentProvider';
|
||||
import GitProvider, { Git } from './gitProvider';
|
||||
import { WorkspaceState } from './constants';
|
||||
import { IAdvancedConfig } from './configuration';
|
||||
import { Logger } from './logger';
|
||||
import DiffWithPreviousCommand from './commands/diffWithPrevious';
|
||||
import DiffLineWithPreviousCommand from './commands/diffLineWithPrevious';
|
||||
import DiffWithWorkingCommand from './commands/diffWithWorking';
|
||||
@@ -16,10 +18,9 @@ import ShowBlameHistoryCommand from './commands/showBlameHistory';
|
||||
import ShowHistoryCommand from './commands/showHistory';
|
||||
import ToggleBlameCommand from './commands/toggleBlame';
|
||||
import ToggleCodeLensCommand from './commands/toggleCodeLens';
|
||||
import { Logger } from './logger';
|
||||
|
||||
// this method is called when your extension is activated
|
||||
export function activate(context: ExtensionContext) {
|
||||
export async function activate(context: ExtensionContext) {
|
||||
// Workspace not using a folder. No access to git repo.
|
||||
if (!workspace.rootPath) {
|
||||
Logger.warn('GitLens inactive: no rootPath');
|
||||
@@ -30,34 +31,44 @@ export function activate(context: ExtensionContext) {
|
||||
const rootPath = workspace.rootPath.replace(/\\/g, '/');
|
||||
Logger.log(`GitLens active: ${rootPath}`);
|
||||
|
||||
Git.repoPath(rootPath).then(repoPath => {
|
||||
context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
|
||||
context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined);
|
||||
const gitPath = workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').git;
|
||||
|
||||
const git = new GitProvider(context);
|
||||
context.subscriptions.push(git);
|
||||
let repoPath: string;
|
||||
try {
|
||||
repoPath = await Git.repoPath(rootPath, gitPath);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex);
|
||||
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.`);
|
||||
return;
|
||||
}
|
||||
|
||||
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitContentProvider.scheme, new GitContentProvider(context, git)));
|
||||
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitBlameContentProvider.scheme, new GitBlameContentProvider(context, git)));
|
||||
context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
|
||||
context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined);
|
||||
|
||||
context.subscriptions.push(languages.registerCodeLensProvider(GitBlameCodeLensProvider.selector, new GitBlameCodeLensProvider(context, git)));
|
||||
const git = new GitProvider(context);
|
||||
context.subscriptions.push(git);
|
||||
|
||||
const annotationController = new BlameAnnotationController(context, git);
|
||||
context.subscriptions.push(annotationController);
|
||||
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitContentProvider.scheme, new GitContentProvider(context, git)));
|
||||
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitBlameContentProvider.scheme, new GitBlameContentProvider(context, git)));
|
||||
|
||||
const statusBarController = new BlameStatusBarController(context, git);
|
||||
context.subscriptions.push(statusBarController);
|
||||
context.subscriptions.push(languages.registerCodeLensProvider(GitBlameCodeLensProvider.selector, new GitBlameCodeLensProvider(context, git)));
|
||||
|
||||
context.subscriptions.push(new DiffWithWorkingCommand(git));
|
||||
context.subscriptions.push(new DiffLineWithWorkingCommand(git));
|
||||
context.subscriptions.push(new DiffWithPreviousCommand(git));
|
||||
context.subscriptions.push(new DiffLineWithPreviousCommand(git));
|
||||
context.subscriptions.push(new ShowBlameCommand(git, annotationController));
|
||||
context.subscriptions.push(new ToggleBlameCommand(git, annotationController));
|
||||
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
||||
context.subscriptions.push(new ShowHistoryCommand(git));
|
||||
context.subscriptions.push(new ToggleCodeLensCommand(git));
|
||||
}).catch(reason => Logger.warn(reason));
|
||||
const annotationController = new BlameAnnotationController(context, git);
|
||||
context.subscriptions.push(annotationController);
|
||||
|
||||
const statusBarController = new BlameStatusBarController(context, git);
|
||||
context.subscriptions.push(statusBarController);
|
||||
|
||||
context.subscriptions.push(new DiffWithWorkingCommand(git));
|
||||
context.subscriptions.push(new DiffLineWithWorkingCommand(git));
|
||||
context.subscriptions.push(new DiffWithPreviousCommand(git));
|
||||
context.subscriptions.push(new DiffLineWithPreviousCommand(git));
|
||||
context.subscriptions.push(new ShowBlameCommand(git, annotationController));
|
||||
context.subscriptions.push(new ToggleBlameCommand(git, annotationController));
|
||||
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
||||
context.subscriptions.push(new ShowHistoryCommand(git));
|
||||
context.subscriptions.push(new ToggleCodeLensCommand(git));
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
|
||||
Reference in New Issue
Block a user