Skip to content
Snippets Groups Projects
Commit 71f79426 authored by Xu Cheng's avatar Xu Cheng
Browse files

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.
parent 370df177
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ require "utils/json"
require "utils/inreplace"
require "utils/popen"
require "utils/fork"
require "utils/git"
require "open-uri"
class Tty
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment