Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass original tap to formula when loaded from the API via TapLoader #16216

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def self.tap_formula_name_path(tapped_name, warn:)
new_tap = Tap.fetch new_tap_name
new_tap.ensure_installed!
new_tapped_name = "#{new_tap_name}/#{name}"
name, path = Formulary.tap_formula_name_path(new_tapped_name, warn: false)
name, path, tap = Formulary.tap_formula_name_path(new_tapped_name, warn: false)
old_name = tapped_name
new_name = new_tap.core_tap? ? name : new_tapped_name
end
Expand All @@ -926,7 +926,7 @@ def self.tap_formula_name_path(tapped_name, warn:)
def self.tap_loader_for(tapped_name, warn:)
name, path, tap = Formulary.tap_formula_name_path(tapped_name, warn: warn)

if name.exclude?("/") && !Homebrew::EnvConfig.no_install_from_api? &&
if tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api? &&
Homebrew::API::Formula.all_formulae.key?(name)
FormulaAPILoader.new(name)
else
Expand Down
42 changes: 42 additions & 0 deletions Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,48 @@ class Wrong#{described_class.class_s(formula_name)} < Formula
end
end

context "when migrating from a Tap" do
let(:tap) { Tap.new("homebrew", "foo") }
let(:another_tap) { Tap.new("homebrew", "bar") }
let(:tap_migrations_path) { tap.path/"tap_migrations.json" }
let(:another_tap_formula_path) { another_tap.path/"Formula/#{formula_name}.rb" }

before do
tap.path.mkpath
another_tap_formula_path.dirname.mkpath
another_tap_formula_path.write formula_content
end

after do
FileUtils.rm_rf tap.path
FileUtils.rm_rf another_tap.path
end

it "returns a Formula that has gone through a tap migration into homebrew/core" do
tap_migrations_path.write <<~EOS
{
"#{formula_name}": "homebrew/core"
}
EOS
formula = described_class.factory("#{tap}/#{formula_name}")
expect(formula).to be_a(Formula)
expect(formula.tap).to eq(CoreTap.instance)
expect(formula.path).to eq(formula_path)
end

it "returns a Formula that has gone through a tap migration into another tap" do
tap_migrations_path.write <<~EOS
{
"#{formula_name}": "#{another_tap}"
}
EOS
formula = described_class.factory("#{tap}/#{formula_name}")
expect(formula).to be_a(Formula)
expect(formula.tap).to eq(another_tap)
expect(formula.path).to eq(another_tap_formula_path)
end
end

context "when loading from Tap" do
let(:tap) { Tap.new("homebrew", "foo") }
let(:another_tap) { Tap.new("homebrew", "bar") }
Expand Down