diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index f64a5c70ae24a..361520c73bfd7 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -715,7 +715,12 @@ def self.tap_cask_token_type(tapped_token, warn:) end end - opoo "Cask #{old_token} was renamed to #{new_token}." if warn && old_token && new_token + if warn && old_token && new_token + destination_exists = find_cask_in_tap(token, tap).exist? || + (tap.core_cask_tap? && !Homebrew::EnvConfig.no_install_from_api? && + Homebrew::API.cask_tokens.include?(token)) + opoo "Cask #{old_token} was renamed to #{new_token}." if destination_exists + end [token, tap, type] end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 6c5e1128f6c3e..b51b5f11b0ea2 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -1190,7 +1190,12 @@ def self.tap_formula_name_type(tapped_name, warn:) end end - opoo "Formula #{old_name} was renamed to #{new_name}." if warn && old_name && new_name + if warn && old_name && new_name + destination_exists = find_formula_in_tap(name, tap).exist? || + (tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api? && + Homebrew::API.formula_names.include?(name)) + opoo "Formula #{old_name} was renamed to #{new_name}." if destination_exists + end [name, tap, type] end diff --git a/Library/Homebrew/test/cask/cask_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader_spec.rb index 4bd2bd601599f..ee95caa4ca95f 100644 --- a/Library/Homebrew/test/cask/cask_loader_spec.rb +++ b/Library/Homebrew/test/cask/cask_loader_spec.rb @@ -81,7 +81,7 @@ (old_tap.path/"tap_migrations.json").write tap_migrations.to_json end - context "to a cask in an other tap" do + context "to a cask in another tap" do # Can't use local-caffeine. It is a fixture in the :core_cask_tap and would take precedence over :new_tap. let(:token) { "some-cask" } @@ -149,6 +149,26 @@ end end + context "to a formula in another tap" do + let(:token) { "some-cask" } + + let(:old_tap) { Tap.fetch("homebrew", "foo") } + let(:new_tap) { Tap.fetch("homebrew", "bar") } + + let(:formula_file) { new_tap.formula_dir/"#{token}.rb" } + + before do + new_tap.formula_dir.mkpath + FileUtils.touch formula_file + end + + it "does not warn when loading the short token" do + expect do + klass.for(token) + end.not_to output.to_stderr + end + end + context "to the default tap" do let(:old_tap) { core_tap } let(:new_tap) { core_cask_tap } diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 2063b4d412540..e0433f1886685 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -883,6 +883,27 @@ def formula_json_contents(extra_items = {}) # end end + context "to a cask in a third-party tap" do + let(:old_tap) { Tap.fetch("another", "foo") } + let(:new_tap) { Tap.fetch("another", "bar") } + let(:cask_file) { new_tap.cask_dir/"#{token}.rb" } + + before do + new_tap.cask_dir.mkpath + FileUtils.touch cask_file + end + + after do + FileUtils.rm_rf HOMEBREW_TAP_DIRECTORY/"another" + end + + it "does not warn when loading the short token" do + expect do + klass.loader_for(token) + end.not_to output.to_stderr + end + end + context "to a third-party tap" do let(:old_tap) { Tap.fetch("another", "foo") } let(:new_tap) { Tap.fetch("another", "bar") }