diagnostic: refactor git origin checks

This commit is contained in:
Jonathan Chang 2019-02-18 13:09:58 +11:00
parent d3c0d687cc
commit f274fa44d8

View File

@ -106,6 +106,32 @@ module Homebrew
EOS EOS
end end
def examine_git_origin(repository_path, desired_origin)
return if !Utils.git_available? || !repository_path.git?
current_origin = repository_path.git_origin
if current_origin.nil?
<<~EOS
Missing #{desired_origin} git origin remote.
Without a correctly configured origin, Homebrew won't update
properly. You can solve this by adding the remote:
git -C "#{repository_path}" remote add origin #{Formatter.url("https://github.com/#{desired_origin}.git")}
EOS
elsif current_origin !~ %r{#{desired_origin}(\.git|/)?$}i
<<~EOS
Suspicious #{desired_origin} git origin remote found.
The current git origin is:
#{current_origin}
With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
git -C "#{repository_path}" remote set-url origin #{Formatter.url("https://github.com/#{desired_origin}.git")}
EOS
end
end
def check_for_installed_developer_tools def check_for_installed_developer_tools
return if DevelopmentTools.installed? return if DevelopmentTools.installed?
@ -529,60 +555,13 @@ module Homebrew
end end
def check_brew_git_origin def check_brew_git_origin
return if !Utils.git_available? || !(HOMEBREW_REPOSITORY/".git").exist? examine_git_origin(HOMEBREW_REPOSITORY, "Homebrew/brew")
origin = HOMEBREW_REPOSITORY.git_origin
if origin.nil?
<<~EOS
Missing Homebrew/brew git origin remote.
Without a correctly configured origin, Homebrew won't update
properly. You can solve this by adding the Homebrew remote:
git -C "#{HOMEBREW_REPOSITORY}" remote add origin #{Formatter.url("https://github.com/Homebrew/brew.git")}
EOS
elsif origin !~ %r{Homebrew/brew(\.git|/)?$}
<<~EOS
Suspicious Homebrew/brew git origin remote found.
With a non-standard origin, Homebrew won't pull updates from
the main repository. The current git origin is:
#{origin}
Unless you have compelling reasons, consider setting the
origin remote to point at the main repository by running:
git -C "#{HOMEBREW_REPOSITORY}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/brew.git")}
EOS
end
end end
def check_coretap_git_origin def check_coretap_git_origin
coretap_path = CoreTap.instance.path examine_git_origin(CoreTap.instance.path, CoreTap.instance.full_name)
return if !Utils.git_available? || !(coretap_path/".git").exist?
origin = coretap_path.git_origin
if origin.nil?
<<~EOS
Missing #{CoreTap.instance} git origin remote.
Without a correctly configured origin, Homebrew won't update
properly. You can solve this by adding the Homebrew remote:
git -C "#{coretap_path}" remote add origin #{Formatter.url(CoreTap.instance.default_remote)}
EOS
elsif origin !~ %r{#{CoreTap.instance.full_name}(\.git|/)?$}i
<<~EOS
Suspicious #{CoreTap.instance} git origin remote found.
With a non-standard origin, Homebrew won't pull updates from
the main repository. The current git origin is:
#{origin}
Unless you have compelling reasons, consider setting the
origin remote to point at the main repository by running:
git -C "#{coretap_path}" remote set-url origin #{Formatter.url(CoreTap.instance.default_remote)}
EOS
end end
end end
def check_coretap_git_branch def check_coretap_git_branch