Skip to content

Commit 4d7be53

Browse files
authored
Merge pull request #22403 from Homebrew/rename-warning-destination-exists
Only warn on rename when migration destination exists
2 parents 2dd64a5 + 6542364 commit 4d7be53

4 files changed

Lines changed: 54 additions & 3 deletions

File tree

Library/Homebrew/cask/cask_loader.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,12 @@ def self.tap_cask_token_type(tapped_token, warn:)
715715
end
716716
end
717717

718-
opoo "Cask #{old_token} was renamed to #{new_token}." if warn && old_token && new_token
718+
if warn && old_token && new_token
719+
destination_exists = find_cask_in_tap(token, tap).exist? ||
720+
(tap.core_cask_tap? && !Homebrew::EnvConfig.no_install_from_api? &&
721+
Homebrew::API.cask_tokens.include?(token))
722+
opoo "Cask #{old_token} was renamed to #{new_token}." if destination_exists
723+
end
719724

720725
[token, tap, type]
721726
end

Library/Homebrew/formulary.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,12 @@ def self.tap_formula_name_type(tapped_name, warn:)
11901190
end
11911191
end
11921192

1193-
opoo "Formula #{old_name} was renamed to #{new_name}." if warn && old_name && new_name
1193+
if warn && old_name && new_name
1194+
destination_exists = find_formula_in_tap(name, tap).exist? ||
1195+
(tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api? &&
1196+
Homebrew::API.formula_names.include?(name))
1197+
opoo "Formula #{old_name} was renamed to #{new_name}." if destination_exists
1198+
end
11941199

11951200
[name, tap, type]
11961201
end

Library/Homebrew/test/cask/cask_loader_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
(old_tap.path/"tap_migrations.json").write tap_migrations.to_json
8282
end
8383

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

@@ -149,6 +149,26 @@
149149
end
150150
end
151151

152+
context "to a formula in another tap" do
153+
let(:token) { "some-cask" }
154+
155+
let(:old_tap) { Tap.fetch("homebrew", "foo") }
156+
let(:new_tap) { Tap.fetch("homebrew", "bar") }
157+
158+
let(:formula_file) { new_tap.formula_dir/"#{token}.rb" }
159+
160+
before do
161+
new_tap.formula_dir.mkpath
162+
FileUtils.touch formula_file
163+
end
164+
165+
it "does not warn when loading the short token" do
166+
expect do
167+
klass.for(token)
168+
end.not_to output.to_stderr
169+
end
170+
end
171+
152172
context "to the default tap" do
153173
let(:old_tap) { core_tap }
154174
let(:new_tap) { core_cask_tap }

Library/Homebrew/test/formulary_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,27 @@ def formula_json_contents(extra_items = {})
883883
# end
884884
end
885885

886+
context "to a cask in a third-party tap" do
887+
let(:old_tap) { Tap.fetch("another", "foo") }
888+
let(:new_tap) { Tap.fetch("another", "bar") }
889+
let(:cask_file) { new_tap.cask_dir/"#{token}.rb" }
890+
891+
before do
892+
new_tap.cask_dir.mkpath
893+
FileUtils.touch cask_file
894+
end
895+
896+
after do
897+
FileUtils.rm_rf HOMEBREW_TAP_DIRECTORY/"another"
898+
end
899+
900+
it "does not warn when loading the short token" do
901+
expect do
902+
klass.loader_for(token)
903+
end.not_to output.to_stderr
904+
end
905+
end
906+
886907
context "to a third-party tap" do
887908
let(:old_tap) { Tap.fetch("another", "foo") }
888909
let(:new_tap) { Tap.fetch("another", "bar") }

0 commit comments

Comments
 (0)