Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit b353b57

Browse files
committed
use sh as SHELL for Cygwin/Git-Bash
1 parent d030653 commit b353b57

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
280280

281281
if (customShell) {
282282
sh = customShell
283-
} else if (process.platform === 'win32') {
283+
} else if (opts.isWindowsShell == null ? process.platform === 'win32' : opts.isWindowsShell) {
284284
sh = process.env.comspec || 'cmd'
285285
shFlag = '/d /s /c'
286286
conf.windowsVerbatimArguments = true

lib/spawn.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
module.exports = spawn
44

5+
const path = require('path')
56
const _spawn = require('child_process').spawn
67
const EventEmitter = require('events').EventEmitter
8+
const _spawnSync = require('child_process').spawnSync
79

810
let progressEnabled
911
let running = 0
@@ -29,7 +31,49 @@ function willCmdOutput (stdio) {
2931
return false
3032
}
3133

34+
function getGitDirByRegstry (arch) {
35+
const args = [
36+
'QUERY',
37+
'HKLM\\SOFTWARE\\GitForWindows',
38+
'/v',
39+
'InstallPath',
40+
]
41+
42+
if (arch) {
43+
args.push('/reg:' + arch)
44+
}
45+
46+
const stdout = _spawnSync('reg.exe', args).stdout
47+
48+
if (stdout && /^\s*InstallPath\s+REG(?:_[A-Z]+)+\s+(.+?)$/im.test(stdout.toString())) {
49+
return RegExp.$1
50+
} else if (arch === 64) {
51+
return getGitDirByRegstry(32)
52+
}
53+
}
54+
55+
function getGitPath(cmd) {
56+
let gitInstRoot
57+
if ('GIT_INSTALL_ROOT' in process.env) {
58+
gitInstRoot = process.env.GIT_INSTALL_ROOT
59+
} else {
60+
const osArch = /64$/.test(process.env.PROCESSOR_ARCHITEW6432 || process.arch) ? 64 : 32
61+
gitInstRoot = getGitDirByRegstry(osArch)
62+
process.env.GIT_INSTALL_ROOT = gitInstRoot
63+
}
64+
65+
if (gitInstRoot) {
66+
cmd = path.join(gitInstRoot, cmd)
67+
}
68+
return cmd
69+
}
70+
3271
function spawn (cmd, args, options, log) {
72+
73+
if (process.platform === "win32" && cmd[0] === "/") {
74+
cmd = getGitPath(cmd)
75+
}
76+
3377
const cmdWillOutput = willCmdOutput(options && options.stdio)
3478

3579
if (cmdWillOutput) startRunning(log)

0 commit comments

Comments
 (0)