Merge pull request #16654 from reitermarkus/fix-cask-rename-warning
Fix cask migration warnings.
This commit is contained in:
commit
24c8c0e745
@ -437,6 +437,23 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Loader which tries loading casks from the default tap.
|
||||||
|
class FromDefaultNameLoader < FromTapLoader
|
||||||
|
sig {
|
||||||
|
params(ref: T.any(String, Pathname, Cask, URI::Generic), warn: T::Boolean)
|
||||||
|
.returns(T.nilable(T.attached_class))
|
||||||
|
}
|
||||||
|
def self.try_new(ref, warn: false)
|
||||||
|
return unless ref.is_a?(String)
|
||||||
|
return unless (token = ref[HOMEBREW_DEFAULT_TAP_CASK_REGEX, :token])
|
||||||
|
return unless (tap = CoreCaskTap.instance).installed?
|
||||||
|
|
||||||
|
return unless (loader = super("#{tap}/#{token}", warn: warn))
|
||||||
|
|
||||||
|
loader if loader.path.exist?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Loader which tries loading casks from tap paths, failing
|
# Loader which tries loading casks from tap paths, failing
|
||||||
# if the same token exists in multiple taps.
|
# if the same token exists in multiple taps.
|
||||||
class FromNameLoader < FromTapLoader
|
class FromNameLoader < FromTapLoader
|
||||||
@ -458,11 +475,6 @@ module Cask
|
|||||||
when 1
|
when 1
|
||||||
loaders.first
|
loaders.first
|
||||||
when 2..Float::INFINITY
|
when 2..Float::INFINITY
|
||||||
# Always prefer the default tap, i.e. behave the same as if loading from the API.
|
|
||||||
if (default_tap_loader = loaders.find { _1.tap.core_cask_tap? })
|
|
||||||
return default_tap_loader
|
|
||||||
end
|
|
||||||
|
|
||||||
raise TapCaskAmbiguityError.new(token, loaders.map(&:tap))
|
raise TapCaskAmbiguityError.new(token, loaders.map(&:tap))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -555,6 +567,7 @@ module Cask
|
|||||||
FromURILoader,
|
FromURILoader,
|
||||||
FromAPILoader,
|
FromAPILoader,
|
||||||
FromTapLoader,
|
FromTapLoader,
|
||||||
|
FromDefaultNameLoader,
|
||||||
FromNameLoader,
|
FromNameLoader,
|
||||||
FromPathLoader,
|
FromPathLoader,
|
||||||
FromInstalledPathLoader,
|
FromInstalledPathLoader,
|
||||||
|
|||||||
@ -66,5 +66,45 @@ describe Cask::CaskLoader, :cask do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when not using the API" do
|
||||||
|
before do
|
||||||
|
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a cask is migrated to the default tap" do
|
||||||
|
let(:token) { "local-caffeine" }
|
||||||
|
let(:tap_migrations) do
|
||||||
|
{
|
||||||
|
token => default_tap.name,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:old_tap) { CoreTap.instance }
|
||||||
|
let(:default_tap) { CoreCaskTap.instance }
|
||||||
|
|
||||||
|
before do
|
||||||
|
(old_tap.path/"tap_migrations.json").write tap_migrations.to_json
|
||||||
|
old_tap.clear_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not warn when loading the short token" do
|
||||||
|
expect do
|
||||||
|
described_class.for(token)
|
||||||
|
end.not_to output.to_stderr
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not warn when loading the full token in the default tap" do
|
||||||
|
expect do
|
||||||
|
described_class.for("#{default_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 #{token}\.}).to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -528,4 +528,47 @@ describe Formulary do
|
|||||||
expect(described_class.convert_to_string_or_symbol(":foo")).to eq :foo
|
expect(described_class.convert_to_string_or_symbol(":foo")).to eq :foo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "::loader_for" do
|
||||||
|
context "when not using the API" do
|
||||||
|
before do
|
||||||
|
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a formula is migrated to the default tap" do
|
||||||
|
let(:token) { "local-caffeine" }
|
||||||
|
let(:tap_migrations) do
|
||||||
|
{
|
||||||
|
token => default_tap.name,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:old_tap) { CoreCaskTap.instance }
|
||||||
|
let(:default_tap) { CoreTap.instance }
|
||||||
|
|
||||||
|
before do
|
||||||
|
old_tap.path.mkpath
|
||||||
|
(old_tap.path/"tap_migrations.json").write tap_migrations.to_json
|
||||||
|
old_tap.clear_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not warn when loading the short token" do
|
||||||
|
expect do
|
||||||
|
described_class.loader_for(token)
|
||||||
|
end.not_to output.to_stderr
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not warn when loading the full token in the default tap" do
|
||||||
|
expect do
|
||||||
|
described_class.loader_for("#{default_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(%r{Formula #{old_tap}/#{token} was renamed to #{token}\.}).to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user