ATL-1145: Suppress error if Git is not on $PATH.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2021-03-31 16:21:18 +02:00 committed by Akos Kitta
parent d45dd6beef
commit a8df2444a9
2 changed files with 49 additions and 0 deletions

View File

@ -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();
@ -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);
});

View File

@ -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();
}
}