Skip to content

Commit

Permalink
Merge pull request #16715 from reitermarkus/tap-ensure-installed
Browse files Browse the repository at this point in the history
Clean up `Tap#ensure_installed!` usage.
  • Loading branch information
MikeMcQuaid committed Feb 22, 2024
2 parents 689b76c + 9f5e1f2 commit 89fd696
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
6 changes: 4 additions & 2 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ def tap_or_untap_core_taps_if_necessary

if Homebrew::EnvConfig.no_install_from_api?
return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
return if CoreTap.instance.installed?

CoreTap.ensure_installed!
core_tap = CoreTap.instance
return if core_tap.installed?

core_tap.ensure_installed!
revision = CoreTap.instance.git_head
ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision
ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision
Expand Down
14 changes: 7 additions & 7 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,21 @@ def check_brew_git_origin
end

def check_coretap_integrity
coretap = CoreTap.instance
unless coretap.installed?
core_tap = CoreTap.instance
unless core_tap.installed?
return unless EnvConfig.no_install_from_api?

CoreTap.ensure_installed!
core_tap.ensure_installed!
end

broken_tap(coretap) || examine_git_origin(coretap.git_repo, Homebrew::EnvConfig.core_git_remote)
broken_tap(core_tap) || examine_git_origin(core_tap.git_repo, Homebrew::EnvConfig.core_git_remote)
end

def check_casktap_integrity
default_cask_tap = CoreCaskTap.instance
return unless default_cask_tap.installed?
core_cask_tap = CoreCaskTap.instance
return unless core_cask_tap.installed?

broken_tap(default_cask_tap) || examine_git_origin(default_cask_tap.git_repo, default_cask_tap.remote)
broken_tap(core_cask_tap) || examine_git_origin(core_cask_tap.git_repo, core_cask_tap.remote)
end

sig { returns(T.nilable(String)) }
Expand Down
20 changes: 11 additions & 9 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def self.from_path(path)

sig { returns(CoreCaskTap) }
def self.default_cask_tap
odisabled "Tap.default_cask_tap", "CoreCaskTap.instance"
odisabled "`Tap.default_cask_tap`", "`CoreCaskTap.instance`"

CoreCaskTap.instance
end

sig { params(force: T::Boolean).returns(T::Boolean) }
def self.install_default_cask_tap_if_necessary(force: false)
odisabled "Tap.install_default_cask_tap_if_necessary", "CoreCaskTap.ensure_installed!"
odisabled "`Tap.install_default_cask_tap_if_necessary`", "`CoreCaskTap.instance.ensure_installed!`"

false
end
Expand Down Expand Up @@ -968,6 +968,8 @@ def ensure_installed!

sig { void }
def self.ensure_installed!
# odeprecated "`#{self}.ensure_installed!`", "`#{self}.instance.ensure_installed!`"

instance.ensure_installed!
end

Expand Down Expand Up @@ -1043,7 +1045,7 @@ def linuxbrew_core?
sig { returns(Pathname) }
def formula_dir
@formula_dir ||= begin
self.class.ensure_installed!
ensure_installed!
super
end
end
Expand All @@ -1065,7 +1067,7 @@ def new_formula_path(name)
sig { returns(Pathname) }
def alias_dir
@alias_dir ||= begin
self.class.ensure_installed!
ensure_installed!
super
end
end
Expand All @@ -1074,7 +1076,7 @@ def alias_dir
sig { returns(T::Hash[String, String]) }
def formula_renames
@formula_renames ||= if Homebrew::EnvConfig.no_install_from_api?
self.class.ensure_installed!
ensure_installed!
super
else
Homebrew::API::Formula.all_renames
Expand All @@ -1085,7 +1087,7 @@ def formula_renames
sig { returns(Hash) }
def tap_migrations
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api?
self.class.ensure_installed!
ensure_installed!
super
else
migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json",
Expand All @@ -1098,7 +1100,7 @@ def tap_migrations
sig { returns(Hash) }
def audit_exceptions
@audit_exceptions ||= begin
self.class.ensure_installed!
ensure_installed!
super
end
end
Expand All @@ -1107,7 +1109,7 @@ def audit_exceptions
sig { returns(Hash) }
def style_exceptions
@style_exceptions ||= begin
self.class.ensure_installed!
ensure_installed!
super
end
end
Expand All @@ -1116,7 +1118,7 @@ def style_exceptions
sig { returns(Hash) }
def pypi_formula_mappings
@pypi_formula_mappings ||= begin
self.class.ensure_installed!
ensure_installed!
super
end
end
Expand Down

0 comments on commit 89fd696

Please sign in to comment.