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

Commit

Permalink
use sh as SHELL for Cygwin/Git-Bash
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 committed May 4, 2018
1 parent d030653 commit b353b57
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {

if (customShell) {
sh = customShell
} else if (process.platform === 'win32') {
} else if (opts.isWindowsShell == null ? process.platform === 'win32' : opts.isWindowsShell) {
sh = process.env.comspec || 'cmd'
shFlag = '/d /s /c'
conf.windowsVerbatimArguments = true
Expand Down
44 changes: 44 additions & 0 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module.exports = spawn

const path = require('path')
const _spawn = require('child_process').spawn
const EventEmitter = require('events').EventEmitter
const _spawnSync = require('child_process').spawnSync

let progressEnabled
let running = 0
Expand All @@ -29,7 +31,49 @@ function willCmdOutput (stdio) {
return false
}

function getGitDirByRegstry (arch) {
const args = [
'QUERY',
'HKLM\\SOFTWARE\\GitForWindows',
'/v',
'InstallPath',
]

if (arch) {
args.push('/reg:' + arch)
}

const stdout = _spawnSync('reg.exe', args).stdout

if (stdout && /^\s*InstallPath\s+REG(?:_[A-Z]+)+\s+(.+?)$/im.test(stdout.toString())) {
return RegExp.$1
} else if (arch === 64) {
return getGitDirByRegstry(32)
}
}

function getGitPath(cmd) {
let gitInstRoot
if ('GIT_INSTALL_ROOT' in process.env) {
gitInstRoot = process.env.GIT_INSTALL_ROOT
} else {
const osArch = /64$/.test(process.env.PROCESSOR_ARCHITEW6432 || process.arch) ? 64 : 32
gitInstRoot = getGitDirByRegstry(osArch)
process.env.GIT_INSTALL_ROOT = gitInstRoot
}

if (gitInstRoot) {
cmd = path.join(gitInstRoot, cmd)
}
return cmd
}

function spawn (cmd, args, options, log) {

if (process.platform === "win32" && cmd[0] === "/") {
cmd = getGitPath(cmd)
}

const cmdWillOutput = willCmdOutput(options && options.stdio)

if (cmdWillOutput) startRunning(log)
Expand Down

0 comments on commit b353b57

Please sign in to comment.