-
Notifications
You must be signed in to change notification settings - Fork 17
fix: smarter git ssh override #194
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
Merged
+200
−25
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6061bd4
fix: remove git ssh override
dennishenry 5f58104
update logic to only overwrite when git config is also not set
fcd6c9f
add requested changes to cache config, as well as namespace node incl…
60964aa
making suggested changes to mock testdir and file rather then use rea…
6072489
removing clear cache and instead testing loadGitConfig
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 hidden or 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 |
|---|---|---|
| @@ -1,12 +1,60 @@ | ||
| // Values we want to set if they're not already defined by the end user | ||
| // This defaults to accepting new ssh host key fingerprints | ||
| const gitEnv = { | ||
| GIT_ASKPASS: 'echo', | ||
| GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new', | ||
| } | ||
| module.exports = (opts = {}) => ({ | ||
| stdioString: true, | ||
| ...opts, | ||
| shell: false, | ||
| env: opts.env || { ...gitEnv, ...process.env }, | ||
| }) | ||
| const fs = require('node:fs') | ||
| const os = require('node:os') | ||
| const path = require('node:path') | ||
| const ini = require('ini') | ||
|
|
||
| const gitConfigPath = path.join(os.homedir(), '.gitconfig') | ||
|
|
||
| let cachedConfig = null | ||
|
|
||
| // Function to load and cache the git config | ||
| const loadGitConfig = () => { | ||
| if (cachedConfig === null) { | ||
| try { | ||
| if (fs.existsSync(gitConfigPath)) { | ||
| const configContent = fs.readFileSync(gitConfigPath, 'utf-8') | ||
| cachedConfig = ini.parse(configContent) | ||
| } else { | ||
| cachedConfig = {} | ||
| } | ||
| } catch (error) { | ||
| cachedConfig = {} | ||
| } | ||
| } | ||
| return cachedConfig | ||
| } | ||
|
|
||
| const isGitSshCommandSetInConfig = () => { | ||
| const config = loadGitConfig() | ||
| return config.core && config.core.sshCommand !== undefined | ||
| } | ||
|
|
||
| const isGitAskPassSetInConfig = () => { | ||
| const config = loadGitConfig() | ||
| return config.core && config.core.askpass !== undefined | ||
dennishenry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| module.exports = (opts = {}) => { | ||
| const sshCommandSetInEnv = process.env.GIT_SSH_COMMAND !== undefined | ||
| const sshCommandSetInConfig = isGitSshCommandSetInConfig() | ||
| const askPassSetInEnv = process.env.GIT_ASKPASS !== undefined | ||
| const askPassSetInConfig = isGitAskPassSetInConfig() | ||
|
|
||
| // Values we want to set if they're not already defined by the end user | ||
| // This defaults to accepting new ssh host key fingerprints | ||
| const finalGitEnv = { | ||
| ...(askPassSetInEnv || askPassSetInConfig ? {} : { | ||
| GIT_ASKPASS: 'echo', | ||
| }), | ||
| ...(sshCommandSetInEnv || sshCommandSetInConfig ? {} : { | ||
| GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new', | ||
| }), | ||
| } | ||
|
|
||
| return { | ||
| stdioString: true, | ||
| ...opts, | ||
| shell: false, | ||
| env: opts.env || { ...finalGitEnv, ...process.env }, | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.