Skip to content

Commit

Permalink
Merge pull request desktop#4085 from desktop/hard-coded-paths-not-eve…
Browse files Browse the repository at this point in the history
…n-twice

use SYSTEMROOT environment variable when spawning tools under System32
  • Loading branch information
iAmWillShepherd authored Feb 26, 2018
2 parents 2184c70 + 52c6bd0 commit 3ed0689
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/lib/is-git-on-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn } from 'child_process'
import * as Path from 'path'

export function isGitOnPath(): Promise<boolean> {
// Modern versions of macOS ship with a Git shim that guides you through
Expand All @@ -12,16 +13,19 @@ export function isGitOnPath(): Promise<boolean> {
// adapted from http://stackoverflow.com/a/34953561/1363815
return new Promise<boolean>((resolve, reject) => {
if (__WIN32__) {
const process = spawn('C:\\Windows\\System32\\where.exe', ['git'])
const windowsRoot = process.env.SystemRoot || 'C:\\Windows'
const wherePath = Path.join(windowsRoot, 'System32', 'where.exe')

process.on('error', error => {
const cp = spawn(wherePath, ['git'])

cp.on('error', error => {
log.warn('Unable to spawn where.exe', error)
resolve(false)
})

// `where` will return 0 when the executable
// is found under PATH, or 1 if it cannot be found
process.on('close', function(code) {
cp.on('close', function(code) {
resolve(code === 0)
})
return
Expand Down

0 comments on commit 3ed0689

Please sign in to comment.