formulary: update logic and add regression test

This commit is contained in:
apainintheneck 2024-02-11 13:09:53 -08:00
parent d01de7545c
commit 70ffc31338
2 changed files with 9 additions and 4 deletions

View File

@ -909,7 +909,7 @@ module Formulary
alias_name = tap.core_tap? ? name : "#{tap}/#{name}" alias_name = tap.core_tap? ? name : "#{tap}/#{name}"
if (possible_alias = tap.alias_table[alias_name].presence) if (possible_alias = tap.alias_table[alias_name].presence)
name = possible_alias name = possible_alias.split("/").last
type = :alias type = :alias
elsif (new_name = tap.formula_renames[name].presence) elsif (new_name = tap.formula_renames[name].presence)
old_name = name old_name = name
@ -943,14 +943,12 @@ module Formulary
if tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api? if tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api?
if type == :alias if type == :alias
alias_name = tapped_name[HOMEBREW_TAP_FORMULA_REGEX, 3] return AliasAPILoader.new(name)
return AliasAPILoader.new(alias_name)
elsif Homebrew::API::Formula.all_formulae.key?(name) elsif Homebrew::API::Formula.all_formulae.key?(name)
return FormulaAPILoader.new(name) return FormulaAPILoader.new(name)
end end
end end
name = name.split("/").last if name != :nil && type == :alias
path = find_formula_in_tap(name, tap) path = find_formula_in_tap(name, tap)
TapLoader.new(name, path, tap: tap) TapLoader.new(name, path, tap: tap)
end end

View File

@ -243,6 +243,13 @@ describe Formulary do
expect(described_class.factory("bar")).to be_a(Formula) expect(described_class.factory("bar")).to be_a(Formula)
end end
it "returns a Formula from a fully qualified Alias path" do
alias_dir = tap.path/"Aliases"
alias_dir.mkpath
FileUtils.ln_s formula_path, alias_dir/"bar"
expect(described_class.factory("#{tap}/bar")).to be_a(Formula)
end
it "raises an error when the Formula cannot be found" do it "raises an error when the Formula cannot be found" do
expect do expect do
described_class.factory("#{tap}/not_existed_formula") described_class.factory("#{tap}/not_existed_formula")