diagnostic: use 'Utils.git_version', simplify code

Prefer `Utils.git_version` instead of duplicating version detection
logic. Decouple unnecessary conflated availability and version checks.

Closes #351.

Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
This commit is contained in:
Martin Afanasjew 2016-06-13 02:57:35 +02:00
parent d7b6e9bba9
commit 5954877962

View File

@ -743,15 +743,15 @@ module Homebrew
EOS EOS
end end
def __check_git_version def check_git_version
# https://help.github.com/articles/https-cloning-errors # https://help.github.com/articles/https-cloning-errors
`git --version`.chomp =~ /git version ((?:\d+\.?)+)/ return unless Utils.git_available?
return unless $1 && Version.new($1) < Version.new("1.7.10") return unless Version.new(Utils.git_version) < Version.new("1.7.10")
git = Formula["git"] git = Formula["git"]
git_upgrade_cmd = git.any_version_installed? ? "upgrade" : "install" git_upgrade_cmd = git.any_version_installed? ? "upgrade" : "install"
<<-EOS.undent <<-EOS.undent
An outdated version of Git was detected in your PATH. An outdated version (#{Utils.git_version}) of Git was detected in your PATH.
Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub. Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub.
Please upgrade: Please upgrade:
brew #{git_upgrade_cmd} git brew #{git_upgrade_cmd} git
@ -759,9 +759,8 @@ module Homebrew
end end
def check_for_git def check_for_git
if Utils.git_available? return if Utils.git_available?
__check_git_version
else
<<-EOS.undent <<-EOS.undent
Git could not be found in your PATH. Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git Homebrew uses Git for several internal functions, and some formulae use Git
@ -769,7 +768,6 @@ module Homebrew
brew install git brew install git
EOS EOS
end end
end
def check_git_newline_settings def check_git_newline_settings
return unless Utils.git_available? return unless Utils.git_available?