utils/git: various improvement
* Use `ENV/scm/git` to check whether git is installed. * Use `brew install git` to enforce pre-install checks such as sudo check.
This commit is contained in:
parent
8ca79a6df5
commit
e0e277ecde
@ -1,27 +1,20 @@
|
|||||||
module Utils
|
module Utils
|
||||||
def self.git_available?
|
def self.git_available?
|
||||||
return @git if instance_variable_defined?(:@git)
|
return @git if instance_variable_defined?(:@git)
|
||||||
# check git in original path in case it's the wrapper script of Library/ENV/scm
|
@git = quiet_system HOMEBREW_ENV_PATH/"scm/git", "--version"
|
||||||
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
|
end
|
||||||
|
|
||||||
def self.ensure_git_installed!
|
def self.ensure_git_installed!
|
||||||
return if git_available?
|
return if git_available?
|
||||||
|
|
||||||
require "cmd/install"
|
|
||||||
begin
|
begin
|
||||||
oh1 "Installing git"
|
oh1 "Installing git"
|
||||||
Homebrew.perform_preinstall_checks
|
safe_system HOMEBREW_BREW_FILE, "install", "git"
|
||||||
Homebrew.install_formula(Formulary.factory("git"))
|
|
||||||
rescue
|
rescue
|
||||||
raise "Git is unavailable"
|
raise "Git is unavailable"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clear_git_available_cache
|
||||||
raise "Git is unavailable" unless git_available?
|
raise "Git is unavailable" unless git_available?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user