 
   constructor: ->
 
-  @_gitCommand: -> atom.config.get 'merge-conflicts.gitPath'
+  @locateGitAnd: (callback) ->
+    # Use an explicitly provided path if one is available.
+    possiblePath = atom.config.get 'merge-conflicts.gitPath'
+    if possiblePath
+      GitCmd = possiblePath
+      callback(null)
+      return
+
+    search = [
+      'git' # Search the inherited execution PATH. Unreliable on Macs.
+      '/usr/local/bin/git' # Homebrew
+      'C:\\Program Files (x86)\\Git\\bin\\git' # Reasonable Windows default
+    ]
+
+    possiblePath = search.shift()
+
+    exitHandler = (code) =>
+      if code is 0
+        GitCmd = possiblePath
+        callback(null)
+        return
+
+      possiblePath = search.shift()
+
+      unless possiblePath?
+        callback(new GitNotFoundError("Please set the 'Git Path' correctly in the Atom settings "
+          "for the Merge Conflicts package."))
+        return
+
+      @process({
+        command: possiblePath,
+        args: ['--version'],
+        exit: exitHandler
+      })
+
+    @process({
+      command: possiblePath,
+      args: ['--version'],
+      exit: exitHandler
+    })
 
   @_repoWorkDir: -> atom.project.getRepo()?.getWorkingDirectory()
 


  @checkoutSide: (sideName, filepath, callback) ->
    proc = @process({
      command: @_gitCommand(),
      args: ['checkout', "--#{sideName}", filepath],
      options: { cwd: @_repoWorkDir() },
      stdout: (line) -> console.log line

class GitNotFoundError extends Error

  constructor: (message) ->
    @name = 'GitNotFoundError'
    super(message)


GitCmd = null


class GitBridge

