aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-09-01 16:52:15 +0800
committerXu Cheng2015-09-02 15:24:52 +0800
commit71f794260b8ea0312b5a733095e2856c9a4719bb (patch)
tree4d64bb145154e606fe16789fc40e2cb0fbe5279d /Library
parent370df177c46e9f13415b2da99b868fe56546764c (diff)
downloadbrew-71f794260b8ea0312b5a733095e2856c9a4719bb.tar.bz2
add git utils
Two methods: * `Utils.git_available?` checks whether git is installed. * `Utils.ensure_git_installed!` installs git for users who don't install Xcode or CLT.
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