uninstall: check for dependents even with --force
This commit is contained in:
parent
b42f76939c
commit
ecb1075390
@ -15,14 +15,27 @@ module Homebrew
|
||||
raise KegUnspecifiedError if ARGV.named.empty?
|
||||
|
||||
kegs_by_rack = if ARGV.force?
|
||||
ARGV.named.map do |name|
|
||||
Hash[ARGV.named.map do |name|
|
||||
rack = Formulary.to_rack(name)
|
||||
[rack, rack.subdirs.map { |d| Keg.new(d) }]
|
||||
end
|
||||
end]
|
||||
else
|
||||
ARGV.kegs.group_by(&:rack)
|
||||
end
|
||||
|
||||
kegs = kegs_by_rack.values.flatten(1)
|
||||
|
||||
kegs.each do |keg|
|
||||
dependents = keg.installed_dependents - kegs
|
||||
if dependents.any?
|
||||
dependents_output = dependents.map { |k| "#{k.name} #{k.version}" }.join(", ")
|
||||
conjugation = dependents.count == 1 ? "is" : "are"
|
||||
ofail "Refusing to uninstall #{keg} because it is required by #{dependents_output}, which #{conjugation} currently installed."
|
||||
# puts "You can override this and force removal with `brew uninstall --force #{keg.name}`."
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
kegs_by_rack.each do |rack, kegs|
|
||||
if ARGV.force?
|
||||
name = rack.basename
|
||||
@ -38,15 +51,6 @@ module Homebrew
|
||||
rm_pin rack
|
||||
else
|
||||
kegs.each do |keg|
|
||||
dependents = keg.installed_dependents - ARGV.kegs
|
||||
if dependents.any?
|
||||
dependents_output = dependents.map { |k| "#{k.name} #{k.version}" }.join(", ")
|
||||
conjugation = dependents.count == 1 ? "is" : "are"
|
||||
ofail "Refusing to uninstall #{keg} because it is required by #{dependents_output}, which #{conjugation} currently installed."
|
||||
puts "You can override this and force removal with `brew uninstall --force #{keg.name}`."
|
||||
next
|
||||
end
|
||||
|
||||
keg.lock do
|
||||
puts "Uninstalling #{keg}... (#{keg.abv})"
|
||||
keg.unlink
|
||||
|
||||
@ -29,6 +29,14 @@ class IntegrationCommandTestUninstall < IntegrationCommandTestCase
|
||||
cmd("uninstall", "testball_f2")
|
||||
end
|
||||
|
||||
def test_uninstall_force_leaving_dependents
|
||||
cmd("install", "testball_f2")
|
||||
assert_match "Refusing to uninstall",
|
||||
cmd_fail("uninstall", "testball_f1", "--force")
|
||||
assert_match "Uninstalling testball_f2",
|
||||
cmd("uninstall", "testball_f2", "--force")
|
||||
end
|
||||
|
||||
def test_uninstall_dependent_first
|
||||
cmd("install", "testball_f2")
|
||||
assert_match "Uninstalling #{Formulary.factory(@f1_path).rack}",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user