aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils.rb1
-rw-r--r--Library/Homebrew/utils/git.rb23
2 files changed, 24 insertions, 0 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 84e2363ca..867c747f8 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -5,6 +5,7 @@ require "utils/json"
require "utils/inreplace"
require "utils/popen"
require "utils/fork"
+require "utils/git"
require "open-uri"
class Tty
diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb
new file mode 100644
index 000000000..53057cd10
--- /dev/null
+++ b/Library/Homebrew/utils/git.rb
@@ -0,0 +1,23 @@
+module Utils
+ def self.git_available?
+ git = which("git")
+ # git isn't installed by older Xcodes
+ return false if git.nil?
+ # /usr/bin/git is a popup stub when Xcode/CLT aren't installed, so bail out
+ return false if git == "/usr/bin/git" && !OS::Mac.has_apple_developer_tools?
+ true
+ end
+
+ def self.ensure_git_installed!
+ return if git_available?
+
+ require "cmd/install"
+ begin
+ oh1 "Installing git"
+ Homebrew.perform_preinstall_checks
+ Homebrew.install_formula(Formulary.factory("git"))
+ rescue
+ raise "Git is unavailable"
+ end
+ end
+end