Merge pull request #16648 from reitermarkus/tap-migrations-rename
Allow tap migrations with renames.
This commit is contained in:
commit
7f369c500b
@ -85,9 +85,9 @@ module Cask
|
||||
# An old name for the cask.
|
||||
sig { returns(T::Array[String]) }
|
||||
def old_tokens
|
||||
@old_tokens ||= if tap
|
||||
tap.cask_renames
|
||||
.flat_map { |old_token, new_token| (new_token == token) ? old_token : [] }
|
||||
@old_tokens ||= if (tap = self.tap)
|
||||
Tap.reverse_tap_migrations_renames.fetch("#{tap}/#{token}", []) +
|
||||
tap.reverse_cask_renames.fetch(token, [])
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
@ -522,23 +522,23 @@ module Cask
|
||||
type = nil
|
||||
|
||||
if (new_token = tap.cask_renames[token].presence)
|
||||
old_token = token
|
||||
old_token = tap.core_cask_tap? ? token : tapped_token
|
||||
token = new_token
|
||||
new_token = tap.core_cask_tap? ? token : "#{tap}/#{token}"
|
||||
type = :rename
|
||||
elsif (new_tap_name = tap.tap_migrations[token].presence)
|
||||
new_tap_user, new_tap_repo, = new_tap_name.split("/")
|
||||
new_tap_name = "#{new_tap_user}/#{new_tap_repo}"
|
||||
new_tap = Tap.fetch(new_tap_name)
|
||||
new_tap_user, new_tap_repo, new_token = new_tap_name.split("/", 3)
|
||||
new_token ||= token
|
||||
new_tap = Tap.fetch(new_tap_user, new_tap_repo)
|
||||
new_tap.ensure_installed!
|
||||
new_tapped_token = "#{new_tap_name}/#{token}"
|
||||
new_tapped_token = "#{new_tap}/#{new_token}"
|
||||
|
||||
if tapped_token == new_tapped_token
|
||||
opoo "Tap migration for #{tapped_token} points to itself, stopping recursion."
|
||||
else
|
||||
old_token = tap.core_cask_tap? ? token : tapped_token
|
||||
token, tap, = tap_cask_token_type(new_tapped_token, warn: false)
|
||||
old_token = tapped_token
|
||||
new_token = new_tap.core_cask_tap? ? token : new_tapped_token
|
||||
new_token = new_tap.core_cask_tap? ? token : "#{tap}/#{token}"
|
||||
type = :migration
|
||||
end
|
||||
end
|
||||
|
||||
@ -53,7 +53,7 @@ module Cask
|
||||
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
|
||||
def self.casks(config: nil)
|
||||
tokens.sort.map do |token|
|
||||
CaskLoader.load(token, config: config)
|
||||
CaskLoader.load(token, config: config, warn: false)
|
||||
rescue TapCaskAmbiguityError
|
||||
tap_path = CaskLoader.tap_paths(token).first
|
||||
CaskLoader::FromPathLoader.new(tap_path).load(config: config)
|
||||
|
||||
@ -129,16 +129,16 @@ class Caveats
|
||||
Bash completion has been installed to:
|
||||
#{root_dir}/etc/bash_completion.d
|
||||
EOS
|
||||
when :zsh
|
||||
<<~EOS
|
||||
zsh #{installed.join(" and ")} have been installed to:
|
||||
#{root_dir}/share/zsh/site-functions
|
||||
EOS
|
||||
when :fish
|
||||
fish_caveats = +"fish #{installed.join(" and ")} have been installed to:"
|
||||
fish_caveats << "\n #{root_dir}/share/fish/vendor_completions.d" if completion_installed
|
||||
fish_caveats << "\n #{root_dir}/share/fish/vendor_functions.d" if functions_installed
|
||||
fish_caveats.freeze
|
||||
when :zsh
|
||||
<<~EOS
|
||||
zsh #{installed.join(" and ")} have been installed to:
|
||||
#{root_dir}/share/zsh/site-functions
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -540,7 +540,12 @@ class Formula
|
||||
# Old names for the formula.
|
||||
sig { returns(T::Array[String]) }
|
||||
def oldnames
|
||||
@oldnames ||= tap&.formula_oldnames&.dig(name) || []
|
||||
@oldnames ||= if (tap = self.tap)
|
||||
Tap.reverse_tap_migrations_renames.fetch("#{tap}/#{name}", []) +
|
||||
tap.formula_reverse_renames.fetch(name, [])
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
# All aliases for the formula.
|
||||
|
||||
@ -904,7 +904,7 @@ module Formulary
|
||||
|
||||
def self.tap_formula_name_type(tapped_name, warn:)
|
||||
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
|
||||
tap = Tap.fetch user, repo
|
||||
tap = Tap.fetch(user, repo)
|
||||
type = nil
|
||||
alias_name = tap.core_tap? ? name : "#{tap}/#{name}"
|
||||
|
||||
@ -912,23 +912,23 @@ module Formulary
|
||||
name = possible_alias.split("/").last
|
||||
type = :alias
|
||||
elsif (new_name = tap.formula_renames[name].presence)
|
||||
old_name = name
|
||||
old_name = tap.core_tap? ? name : tapped_name
|
||||
name = new_name
|
||||
new_name = tap.core_tap? ? name : "#{tap}/#{name}"
|
||||
type = :rename
|
||||
elsif (new_tap_name = tap.tap_migrations[name].presence)
|
||||
new_tap_user, new_tap_repo, = new_tap_name.split("/")
|
||||
new_tap_name = "#{new_tap_user}/#{new_tap_repo}"
|
||||
new_tap = Tap.fetch new_tap_name
|
||||
new_tap_user, new_tap_repo, new_name = new_tap_name.split("/", 3)
|
||||
new_name ||= name
|
||||
new_tap = Tap.fetch(new_tap_user, new_tap_repo)
|
||||
new_tap.ensure_installed!
|
||||
new_tapped_name = "#{new_tap_name}/#{name}"
|
||||
new_tapped_name = "#{new_tap}/#{new_name}"
|
||||
|
||||
if tapped_name == new_tapped_name
|
||||
opoo "Tap migration for #{tapped_name} points to itself, stopping recursion."
|
||||
else
|
||||
old_name = tap.core_tap? ? name : tapped_name
|
||||
name, tap, = tap_formula_name_type(new_tapped_name, warn: false)
|
||||
old_name = tapped_name
|
||||
new_name = new_tap.core_tap? ? name : new_tapped_name
|
||||
new_name = new_tap.core_tap? ? name : "#{tap}/#{name}"
|
||||
type = :migration
|
||||
end
|
||||
end
|
||||
|
||||
@ -335,10 +335,10 @@ class Keg
|
||||
def completion_installed?(shell)
|
||||
dir = case shell
|
||||
when :bash then path/"etc/bash_completion.d"
|
||||
when :fish then path/"share/fish/vendor_completions.d"
|
||||
when :zsh
|
||||
dir = path/"share/zsh/site-functions"
|
||||
dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") }
|
||||
when :fish then path/"share/fish/vendor_completions.d"
|
||||
end
|
||||
dir&.directory? && !dir.children.empty?
|
||||
end
|
||||
|
||||
@ -758,6 +758,15 @@ class Tap
|
||||
end
|
||||
end
|
||||
|
||||
# Hash with tap formula old names. Reverse of {#formula_renames}.
|
||||
sig { returns(T::Hash[String, T::Array[String]]) }
|
||||
def reverse_cask_renames
|
||||
@reverse_cask_renames ||= cask_renames.each_with_object({}) do |(old_name, new_name), hash|
|
||||
hash[new_name] ||= []
|
||||
hash[new_name] << old_name
|
||||
end
|
||||
end
|
||||
|
||||
# Hash with tap formula renames.
|
||||
sig { returns(T::Hash[String, String]) }
|
||||
def formula_renames
|
||||
@ -770,15 +779,30 @@ class Tap
|
||||
|
||||
# Hash with tap formula old names. Reverse of {#formula_renames}.
|
||||
sig { returns(T::Hash[String, T::Array[String]]) }
|
||||
def formula_oldnames
|
||||
@formula_oldnames ||= formula_renames.each_with_object({}) do |(old_name, new_name), hash|
|
||||
def formula_reverse_renames
|
||||
@formula_reverse_renames ||= formula_renames.each_with_object({}) do |(old_name, new_name), hash|
|
||||
hash[new_name] ||= []
|
||||
hash[new_name] << old_name
|
||||
end
|
||||
end
|
||||
|
||||
sig { returns(T::Hash[String, T::Array[String]]) }
|
||||
def self.reverse_tap_migrations_renames
|
||||
Tap.each_with_object({}) do |tap, hash|
|
||||
tap.tap_migrations.each do |old_name, new_name|
|
||||
new_tap_user, new_tap_repo, new_name = new_name.split("/", 3)
|
||||
next unless new_name
|
||||
|
||||
new_tap = Tap.fetch(new_tap_user, new_tap_repo)
|
||||
|
||||
hash["#{new_tap}/#{new_name}"] ||= []
|
||||
hash["#{new_tap}/#{new_name}"] << old_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Hash with tap migrations.
|
||||
sig { returns(Hash) }
|
||||
sig { returns(T::Hash[String, String]) }
|
||||
def tap_migrations
|
||||
@tap_migrations ||= if (migration_file = path/HOMEBREW_TAP_MIGRATIONS_FILE).file?
|
||||
JSON.parse(migration_file.read)
|
||||
|
||||
@ -301,28 +301,34 @@ describe Caveats do
|
||||
let(:caveats) { described_class.new(f).caveats }
|
||||
let(:path) { f.prefix.resolved_path }
|
||||
|
||||
let(:bash_completion_dir) { path/"etc/bash_completion.d" }
|
||||
let(:fish_vendor_completions) { path/"share/fish/vendor_completions.d" }
|
||||
let(:zsh_site_functions) { path/"share/zsh/site-functions" }
|
||||
|
||||
before do
|
||||
# don't try to load/fetch gcc/glibc
|
||||
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
||||
|
||||
allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")])
|
||||
allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell"))
|
||||
allow(Utils::Shell).to receive_messages(preferred: nil, parent: nil)
|
||||
end
|
||||
|
||||
it "gives dir where Bash completions have been installed" do
|
||||
(path/"etc/bash_completion.d").mkpath
|
||||
it "includes where Bash completions have been installed to" do
|
||||
bash_completion_dir.mkpath
|
||||
FileUtils.touch bash_completion_dir/f.name
|
||||
expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d")
|
||||
end
|
||||
|
||||
it "gives dir where zsh completions have been installed" do
|
||||
(path/"share/zsh/site-functions").mkpath
|
||||
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
|
||||
it "includes where fish completions have been installed to" do
|
||||
fish_vendor_completions.mkpath
|
||||
FileUtils.touch fish_vendor_completions/f.name
|
||||
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
||||
end
|
||||
|
||||
it "gives dir where fish completions have been installed" do
|
||||
(path/"share/fish/vendor_completions.d").mkpath
|
||||
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
||||
it "includes where zsh completions have been installed to" do
|
||||
zsh_site_functions.mkpath
|
||||
FileUtils.touch zsh_site_functions/f.name
|
||||
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,8 +8,8 @@ module Test
|
||||
def stub_cask_loader(cask, ref = cask.token, call_original: false)
|
||||
allow(::Cask::CaskLoader).to receive(:for).and_call_original if call_original
|
||||
|
||||
loader = ::Cask::CaskLoader::FromInstanceLoader.new cask
|
||||
allow(::Cask::CaskLoader).to receive(:for).with(ref, warn: true).and_return(loader)
|
||||
loader = ::Cask::CaskLoader::FromInstanceLoader.new(cask)
|
||||
allow(::Cask::CaskLoader).to receive(:for).with(ref, any_args).and_return(loader)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user