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