Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2019-07-02 03:46:25 +0300
committerisaacs <i@izs.me>2019-07-03 20:08:32 +0300
commit3cbd577120a9da6e51bb8b13534d1bf71ea5712c (patch)
tree9693080b4acac74a9fc785fe54e26068ea0e476d /test
parentc1522be2406a0ea4f14c85753edd42ddd8d7e180 (diff)
fix(git): strip GIT environs when running git
When running an npm command from within a git environment, such as installing or testing during a git rebase or bisect, these environment variables will be passed to the child process, causing it to fetch/checkout/etc in the root project instead of doing what the user intends. Strip them out so that they are not passed to the child process. Also, remove git environs from the test environment, so that spawning git in a test to set up a dummy repo doesn't mess with the main project's git repository. This enables adding `exec npm test` in a `git rebase -i` list to run tests between commits.
Diffstat (limited to 'test')
-rw-r--r--test/common-tap.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/common-tap.js b/test/common-tap.js
index d54a86999..e15d5dab2 100644
--- a/test/common-tap.js
+++ b/test/common-tap.js
@@ -7,6 +7,12 @@ var readCmdShim = require('read-cmd-shim')
var isWindows = require('../lib/utils/is-windows.js')
var Bluebird = require('bluebird')
+// remove any git envs so that we don't mess with the main repo
+// when running git subprocesses in tests
+Object.keys(process.env).filter(k => /^GIT/.test(k)).forEach(
+ k => delete process.env[k]
+)
+
// cheesy hackaround for test deps (read: nock) that rely on setImmediate
if (!global.setImmediate || !require('timers').setImmediate) {
require('timers').setImmediate = global.setImmediate = function () {