Xu Cheng 3638c057f0 FormulaInstaller: reset git_available? when installing git
Closes Homebrew/homebrew#43693

Signed-off-by: Xu Cheng <xucheng@me.com>
2015-09-09 12:22:03 +08:00

32 lines
968 B
Ruby

module Utils
def self.git_available?
return @git if instance_variable_defined?(:@git)
# check git in original path in case it's the wrapper script of Library/ENV/scm
git = which("git", ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
# git isn't installed by older Xcodes
return @git = false if git.nil?
# /usr/bin/git is a popup stub when Xcode/CLT aren't installed, so bail out
return @git = false if git == "/usr/bin/git" && !OS::Mac.has_apple_developer_tools?
@git = 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
raise "Git is unavailable" unless git_available?
end
def self.clear_git_available_cache
remove_instance_variable(:@git) if instance_variable_defined?(:@git)
end
end