-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-3736: Use the system Git in electron. #3747
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { GitInit } from '../../node/init/git-init'; | ||
import { ElectronGitInit } from './electron-git-init'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(ElectronGitInit).toSelf(); | ||
bind(GitInit).toService(ElectronGitInit); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import findGit from 'find-git-exec'; | ||
import { dirname } from 'path'; | ||
import { pathExists } from 'fs-extra'; | ||
import { ILogger } from '@theia/core/lib/common/logger'; | ||
import { DefaultGitInit } from '../../node/init/git-init'; | ||
|
||
/** | ||
* The Git initializer for electron. If Git can be found on the `PATH`, it will be used instead of the embedded Git shipped with `dugite`. | ||
*/ | ||
@injectable() | ||
export class ElectronGitInit extends DefaultGitInit { | ||
|
||
@inject(ILogger) | ||
protected readonly logger: ILogger; | ||
|
||
async init(): Promise<void> { | ||
const { env } = process; | ||
if (typeof env.LOCAL_GIT_DIRECTORY !== 'undefined' || typeof env.GIT_EXEC_PATH !== 'undefined') { | ||
await this.handleExternalNotFound('Cannot use Git from the PATH when the LOCAL_GIT_DIRECTORY or the GIT_EXEC_PATH environment variables are set.'); | ||
} else { | ||
try { | ||
const { execPath, path, version } = await findGit(); | ||
if (!!execPath && !!path && !!version) { | ||
// https://github.com/desktop/dugite/issues/111#issuecomment-323222834 | ||
// Instead of the executable path, we need the root directory of Git. | ||
const dir = dirname(dirname(path)); | ||
const [execPathOk, pathOk, dirOk] = await Promise.all([pathExists(execPath), pathExists(path), pathExists(dir)]); | ||
if (execPathOk && pathOk && dirOk) { | ||
process.env.LOCAL_GIT_DIRECTORY = dir; | ||
process.env.GIT_EXEC_PATH = execPath; | ||
this.logger.info(`Using Git [${version}] from the PATH. (${path})`); | ||
return; | ||
} | ||
} | ||
await this.handleExternalNotFound(); | ||
} catch (err) { | ||
await this.handleExternalNotFound(err); | ||
} | ||
} | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
protected async handleExternalNotFound(err?: any): Promise<void> { | ||
if (err) { | ||
this.logger.error(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we notify users in such cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Oh sure. I did not want to log the stack trace; the user cannot do much with that, but I wanted to "log" Could not find Git on the PATH. Falling back to the embedded Git. via the |
||
} | ||
this.logger.info('Could not find Git on the PATH. Falling back to the embedded Git.'); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { GitInit, DefaultGitInit } from './git-init'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(DefaultGitInit).toSelf(); | ||
bind(GitInit).toService(DefaultGitInit); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
path
is e.g./usr/local/bin/git
,dir
is supposed to be/usr/local
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ Yes, there is the comment above the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! ;-)