Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arduino-ide-extension/src/node/arduino-ide-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { NotificationServiceServerImpl } from './notification-service-server';
import { NotificationServiceServer, NotificationServiceClient, NotificationServicePath } from '../common/protocol';
import { BackendApplication } from './theia/core/backend-application';
import { BoardDiscovery } from './board-discovery';
import { DefaultGitInit } from './theia/git/git-init';
import { GitInit } from '@theia/git/lib/node/init/git-init';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -164,4 +166,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
return parentLogger.child('monitor-service');
}).inSingletonScope().whenTargetNamed('monitor-service');

bind(DefaultGitInit).toSelf();
rebind(GitInit).toService(DefaultGitInit);

});
44 changes: 44 additions & 0 deletions arduino-ide-extension/src/node/theia/git/git-init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { injectable } from 'inversify';
import findGit from 'find-git-exec';
import { dirname } from 'path';
import { pathExists } from 'fs-extra';
import { GitInit } from '@theia/git/lib/node/init/git-init';
import { DisposableCollection } from '@theia/core/lib/common/disposable';

@injectable()
export class DefaultGitInit implements GitInit {

protected readonly toDispose = new DisposableCollection();

async init(): Promise<void> {
const { env } = process;
try {
const { execPath, path, version } = await findGit();
if (!!execPath && !!path && !!version) {
const dir = dirname(dirname(path));
const [execPathOk, pathOk, dirOk] = await Promise.all([pathExists(execPath), pathExists(path), pathExists(dir)]);
if (execPathOk && pathOk && dirOk) {
if (typeof env.LOCAL_GIT_DIRECTORY !== 'undefined' && env.LOCAL_GIT_DIRECTORY !== dir) {
console.error(`Misconfigured env.LOCAL_GIT_DIRECTORY: ${env.LOCAL_GIT_DIRECTORY}. dir was: ${dir}`);
return;
}
if (typeof env.GIT_EXEC_PATH !== 'undefined' && env.GIT_EXEC_PATH !== execPath) {
console.error(`Misconfigured env.GIT_EXEC_PATH: ${env.GIT_EXEC_PATH}. execPath was: ${execPath}`);
return;
}
process.env.LOCAL_GIT_DIRECTORY = dir;
process.env.GIT_EXEC_PATH = execPath;
console.info(`Using Git [${version}] from the PATH. (${path})`);
return;
}
}
} catch (err) {
console.error(err);
}
}

dispose(): void {
this.toDispose.dispose();
}

}