Skip to content

Commit

Permalink
fix(env): stop filtering process.env (#23)
Browse files Browse the repository at this point in the history
We should not be removing GIT_ values from the environment if the user
has set them.  All we now do is set two defaults if they were not
already set by the end user.
  • Loading branch information
wraithgar authored Apr 9, 2021
1 parent 0038a9d commit 4dd72ee
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 84 deletions.
34 changes: 0 additions & 34 deletions lib/env.js

This file was deleted.

9 changes: 7 additions & 2 deletions lib/opts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const gitEnv = require('./env.js')
// 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,
env: opts.env || gitEnv(),
env: opts.env || { ...gitEnv, ...process.env }
})
37 changes: 3 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"promise-inflight": "^1.0.1",
"promise-retry": "^2.0.1",
"semver": "^7.3.5",
"unique-filename": "^1.1.1",
"which": "^2.0.2"
}
}
11 changes: 0 additions & 11 deletions test/env.js

This file was deleted.

22 changes: 20 additions & 2 deletions test/opts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
const t = require('tap')
const gitOpts = require('../lib/opts.js')
const gitEnv = require('../lib/env.js')
const gitEnv = {
GIT_ASKPASS: 'echo',
GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new'
}

t.match(gitOpts().env, gitEnv(), 'got the git env by default')
t.match(gitOpts().env, gitEnv, 'got the git defaults we want')

t.test('does not override', t => {
const { GIT_ASKPASS, GIT_SSH_COMMAND } = process.env
t.teardown(() => {
process.env.GIT_ASKPASS = GIT_ASKPASS
process.env.GIT_SSH_COMMAND = GIT_SSH_COMMAND
})
process.env.GIT_ASKPASS = 'test_askpass'
process.env.GIT_SSH_COMMAND = 'test_ssh_command'
t.match(gitOpts().env, {
GIT_ASKPASS: 'test_askpass',
GIT_SSH_COMMAND: 'test_ssh_command',
}, 'values already in process.env remain')
t.end()
})

t.test('as non-root', t => {
process.getuid = () => 999
Expand Down

0 comments on commit 4dd72ee

Please sign in to comment.