Skip to content

Commit f8b1d1f

Browse files
Merge pull request #17385 from pe/migrations-broken
Fix migrations of formulae and casks to non homebrew taps
2 parents 8aef364 + 20fb068 commit f8b1d1f

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

Library/Homebrew/cask/cask_loader.rb

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def self.try_new(ref, warn: false)
458458

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

463464
case loaders.count

Library/Homebrew/formulary.rb

+1
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ def self.try_new(ref, from: T.unsafe(nil), warn: false)
827827

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

832833
case loaders.count

Library/Homebrew/test/cask/cask_loader_spec.rb

+35
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,41 @@
8282
(old_tap.path/"tap_migrations.json").write tap_migrations.to_json
8383
end
8484

85+
context "to a cask in an other tap" do
86+
# Can't use local-caffeine. It is a fixture in the :core_cask_tap and would take precendence over :new_tap.
87+
let(:token) { "some-cask" }
88+
89+
let(:old_tap) { Tap.fetch("homebrew", "foo") }
90+
let(:new_tap) { Tap.fetch("homebrew", "bar") }
91+
92+
let(:cask_file) { new_tap.cask_dir/"#{token}.rb" }
93+
94+
before do
95+
new_tap.cask_dir.mkpath
96+
FileUtils.touch cask_file
97+
end
98+
99+
# FIXME
100+
# It would be preferable not to print a warning when installing with the short token
101+
it "warns when loading the short token" do
102+
expect do
103+
described_class.for(token)
104+
end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{new_tap}/#{token}\.}).to_stderr
105+
end
106+
107+
it "does not warn when loading the full token in the new tap" do
108+
expect do
109+
described_class.for("#{new_tap}/#{token}")
110+
end.not_to output.to_stderr
111+
end
112+
113+
it "warns when loading the full token in the old tap" do
114+
expect do
115+
described_class.for("#{old_tap}/#{token}")
116+
end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{new_tap}/#{token}\.}).to_stderr
117+
end
118+
end
119+
85120
context "to a formula in the default tap" do
86121
let(:old_tap) { core_cask_tap }
87122
let(:new_tap) { core_tap }

Library/Homebrew/test/formulary_spec.rb

+39
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,45 @@ def formula_json_contents(extra_items = {})
641641
# end
642642
# end
643643
end
644+
645+
context "to a third-party tap" do
646+
let(:old_tap) { Tap.fetch("another", "foo") }
647+
let(:new_tap) { Tap.fetch("another", "bar") }
648+
let(:formula_file) { new_tap.formula_dir/"#{token}.rb" }
649+
650+
before do
651+
new_tap.formula_dir.mkpath
652+
FileUtils.touch formula_file
653+
end
654+
655+
after do
656+
FileUtils.rm_rf Tap::TAP_DIRECTORY/"another"
657+
end
658+
659+
# FIXME
660+
# It would be preferable not to print a warning when installing with the short token
661+
it "warns when loading the short token" do
662+
expect do
663+
described_class.loader_for(token)
664+
end.to output(
665+
a_string_including("Formula #{old_tap}/#{token} was renamed to #{new_tap}/#{token}.").once,
666+
).to_stderr
667+
end
668+
669+
it "does not warn when loading the full token in the new tap" do
670+
expect do
671+
described_class.loader_for("#{new_tap}/#{token}")
672+
end.not_to output.to_stderr
673+
end
674+
675+
it "warns when loading the full token in the old tap" do
676+
expect do
677+
described_class.loader_for("#{old_tap}/#{token}")
678+
end.to output(
679+
a_string_including("Formula #{old_tap}/#{token} was renamed to #{new_tap}/#{token}.").once,
680+
).to_stderr
681+
end
682+
end
644683
end
645684
end
646685
end

0 commit comments

Comments
 (0)