Files
vscode/extensions/git/src/main.ts
2017-01-30 20:17:29 +00:00

78 lines
2.8 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { ExtensionContext, workspace, window, Disposable } from 'vscode';
import { findGit, Git } from './git';
import { Model } from './model';
import { GitSCMProvider } from './scmProvider';
import { CommandCenter } from './commands';
import { CheckoutStatusBar, SyncStatusBar } from './statusbar';
import { filterEvent, anyEvent } from './util';
import { GitContentProvider } from './contentProvider';
import { AutoFetcher } from './autofetch';
import { MergeDecorator } from './merge';
import { CommitHandler } from './commit';
import * as nls from 'vscode-nls';
const localize = nls.config()();
async function init(disposables: Disposable[]): Promise<void> {
const rootPath = workspace.rootPath;
if (!rootPath) {
return;
}
const fsWatcher = workspace.createFileSystemWatcher('**');
const onWorkspaceChange = anyEvent(fsWatcher.onDidChange, fsWatcher.onDidCreate, fsWatcher.onDidDelete);
const onGitChange = filterEvent(onWorkspaceChange, uri => /^\.git\//.test(workspace.asRelativePath(uri)));
const pathHint = workspace.getConfiguration('git').get<string>('path');
const info = await findGit(pathHint);
const git = new Git({ gitPath: info.path, version: info.version });
const repository = git.open(rootPath);
const repositoryRoot = await repository.getRoot();
const model = new Model(repositoryRoot, repository, onWorkspaceChange);
const outputChannel = window.createOutputChannel('Git');
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
git.onOutput(str => outputChannel.append(str), null, disposables);
const commandCenter = new CommandCenter(model, outputChannel);
const provider = new GitSCMProvider(model, commandCenter);
const contentProvider = new GitContentProvider(git, rootPath, onGitChange);
const checkoutStatusBar = new CheckoutStatusBar(model);
const syncStatusBar = new SyncStatusBar(model);
const autoFetcher = new AutoFetcher(model);
const mergeDecorator = new MergeDecorator(model);
const commitHandler = new CommitHandler(model);
disposables.push(
commandCenter,
provider,
contentProvider,
outputChannel,
fsWatcher,
checkoutStatusBar,
syncStatusBar,
autoFetcher,
mergeDecorator,
commitHandler
);
}
export function activate(context: ExtensionContext): any {
if (!workspace.rootPath) {
return;
}
const disposables: Disposable[] = [];
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
init(disposables)
.catch(err => console.error(err));
}