Skip to content

Commit

Permalink
Merge pull request #17385 from pe/migrations-broken
Browse files Browse the repository at this point in the history
Fix migrations of formulae and casks to non homebrew taps
  • Loading branch information
apainintheneck authored Jun 9, 2024
2 parents 8aef364 + 20fb068 commit f8b1d1f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def self.try_new(ref, warn: false)

loaders = Tap.select { |tap| tap.installed? && !tap.core_cask_tap? }
.filter_map { |tap| super("#{tap}/#{token}", warn:) }
.uniq(&:path)
.select { |tap| tap.path.exist? }

case loaders.count
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def self.try_new(ref, from: T.unsafe(nil), warn: false)

loaders = Tap.select { |tap| tap.installed? && !tap.core_tap? }
.filter_map { |tap| super("#{tap}/#{name}", warn:) }
.uniq(&:path)
.select { |tap| tap.path.exist? }

case loaders.count
Expand Down
35 changes: 35 additions & 0 deletions Library/Homebrew/test/cask/cask_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@
(old_tap.path/"tap_migrations.json").write tap_migrations.to_json
end

context "to a cask in an other tap" do
# Can't use local-caffeine. It is a fixture in the :core_cask_tap and would take precendence over :new_tap.
let(:token) { "some-cask" }

let(:old_tap) { Tap.fetch("homebrew", "foo") }
let(:new_tap) { Tap.fetch("homebrew", "bar") }

let(:cask_file) { new_tap.cask_dir/"#{token}.rb" }

before do
new_tap.cask_dir.mkpath
FileUtils.touch cask_file
end

# FIXME
# It would be preferable not to print a warning when installing with the short token
it "warns when loading the short token" do
expect do
described_class.for(token)
end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{new_tap}/#{token}\.}).to_stderr
end

it "does not warn when loading the full token in the new tap" do
expect do
described_class.for("#{new_tap}/#{token}")
end.not_to output.to_stderr
end

it "warns when loading the full token in the old tap" do
expect do
described_class.for("#{old_tap}/#{token}")
end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{new_tap}/#{token}\.}).to_stderr
end
end

context "to a formula in the default tap" do
let(:old_tap) { core_cask_tap }
let(:new_tap) { core_tap }
Expand Down
39 changes: 39 additions & 0 deletions Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,45 @@ def formula_json_contents(extra_items = {})
# end
# end
end

context "to a third-party tap" do
let(:old_tap) { Tap.fetch("another", "foo") }
let(:new_tap) { Tap.fetch("another", "bar") }
let(:formula_file) { new_tap.formula_dir/"#{token}.rb" }

before do
new_tap.formula_dir.mkpath
FileUtils.touch formula_file
end

after do
FileUtils.rm_rf Tap::TAP_DIRECTORY/"another"
end

# FIXME
# It would be preferable not to print a warning when installing with the short token
it "warns when loading the short token" do
expect do
described_class.loader_for(token)
end.to output(
a_string_including("Formula #{old_tap}/#{token} was renamed to #{new_tap}/#{token}.").once,
).to_stderr
end

it "does not warn when loading the full token in the new tap" do
expect do
described_class.loader_for("#{new_tap}/#{token}")
end.not_to output.to_stderr
end

it "warns when loading the full token in the old tap" do
expect do
described_class.loader_for("#{old_tap}/#{token}")
end.to output(
a_string_including("Formula #{old_tap}/#{token} was renamed to #{new_tap}/#{token}.").once,
).to_stderr
end
end
end
end
end
Expand Down

0 comments on commit f8b1d1f

Please sign in to comment.