-
Notifications
You must be signed in to change notification settings - Fork 148
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
support for executing an external Git environment #85
Merged
+105
−80
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as path from 'path' | ||
|
||
/** | ||
* Find the path to the embedded Git environment | ||
*/ | ||
function resolveGitDir(): string { | ||
if (process.env.LOCAL_GIT_DIRECTORY) { | ||
return path.resolve(process.env.LOCAL_GIT_DIRECTORY) | ||
} else { | ||
return path.join(__dirname, '..', '..', 'git') | ||
} | ||
} | ||
|
||
/** | ||
* Find the path to the embedded Git binary | ||
*/ | ||
function resolveGitBinary(): string { | ||
const gitDir = resolveGitDir() | ||
if (process.platform === 'darwin' || process.platform === 'linux') { | ||
return path.join(gitDir, 'bin', 'git') | ||
} else if (process.platform === 'win32') { | ||
return path.join(gitDir, 'cmd', 'git.exe') | ||
} | ||
|
||
throw new Error('Git not supported on platform: ' + process.platform) | ||
} | ||
|
||
/** | ||
* Find the path to the embedded git exec path. | ||
*/ | ||
function resolveGitExecPath(): string { | ||
const gitDir = resolveGitDir() | ||
if (process.platform === 'darwin' || process.platform === 'linux') { | ||
return path.join(gitDir, 'libexec', 'git-core') | ||
} else if (process.platform === 'win32') { | ||
return path.join(gitDir, 'mingw64', 'libexec', 'git-core') | ||
} | ||
|
||
throw new Error('Git not supported on platform: ' + process.platform) | ||
} | ||
|
||
/** | ||
* Setup the process environment before invoking Git. | ||
* | ||
* This method resolves the Git executable and creates the array of key-value | ||
* pairs which should be used as environment variables. | ||
* | ||
* @param additional options to include with the process | ||
*/ | ||
export function setupEnvironment(environmentVariables: Object): { env: Object, gitLocation: string } { | ||
const gitLocation = resolveGitBinary() | ||
|
||
let envPath: string = process.env.PATH || '' | ||
const gitDir = resolveGitDir() | ||
|
||
if (process.platform === 'win32') { | ||
envPath = `${gitDir}\\mingw64\\bin;${envPath}` | ||
} | ||
|
||
const env = Object.assign({}, process.env, { | ||
GIT_EXEC_PATH: resolveGitExecPath(), | ||
PATH: envPath, | ||
}, environmentVariables) | ||
|
||
if (process.platform === 'win32') { | ||
// while reading the environment variable is case-insensitive | ||
// you can create a hash with multiple values, which means the | ||
// wrong value might be used when spawning the child process | ||
// | ||
// this ensures we only ever supply one value for PATH | ||
if (env.Path) { | ||
delete env.Path | ||
} | ||
} | ||
|
||
if (process.platform === 'darwin' || process.platform === 'linux') { | ||
// templates are used to populate your .git folder | ||
// when a repository is initialized locally | ||
const templateDir = `${gitDir}/share/git-core/templates` | ||
env.GIT_TEMPLATE_DIR = templateDir | ||
} | ||
|
||
if (process.platform === 'linux') { | ||
// when building Git for Linux and then running it from | ||
// an arbitrary location, you should set PREFIX for the | ||
// process to ensure that it knows how to resolve things | ||
env.PREFIX = gitDir | ||
|
||
// bypass whatever certificates might be set and use | ||
// the bundle included in the distibution | ||
const sslCABundle = `${gitDir}/ssl/cacert.pem` | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
env.GIT_SSL_CAINFO = sslCABundle | ||
} | ||
|
||
return { env, gitLocation } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.