Skip to content

Commit

Permalink
uninstall: allow dependent checks to be by-passed
Browse files Browse the repository at this point in the history
Dependent can be bypassed with `--ignore-dependencies`.
This is now the default for `HOMEBREW_DEVELOPER`s.
  • Loading branch information
alyssais committed Oct 25, 2016
1 parent 13d705c commit 7792acd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 22 deletions.
29 changes: 18 additions & 11 deletions Library/Homebrew/cmd/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ def uninstall
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
# --ignore-dependencies, to be consistent with install
unless ARGV.include?("--ignore-dependencies") || ARGV.homebrew_developer?
kegs = kegs_by_rack.values.flatten(1)
return if check_for_dependents kegs
end

kegs_by_rack.each do |rack, kegs|
Expand Down Expand Up @@ -81,6 +74,20 @@ def uninstall
end
end

def check_for_dependents(kegs)
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 --ignore-dependencies #{keg.name}`."
return true
end
end
false
end

def rm_pin(rack)
Formulary.from_rack(rack).unpin
rescue
Expand Down
62 changes: 51 additions & 11 deletions Library/Homebrew/test/test_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,75 @@ def install
CONTENT
end

def f1
Formulary.factory(@f1_path)
end

def f2
Formulary.factory(@f2_path)
end

def test_uninstall
cmd("install", testball)
assert_match "Uninstalling testball", cmd("uninstall", "--force", testball)
assert_empty Formulary.factory(testball).installed_kegs
end

def test_uninstall_leaving_dependents
cmd("install", "testball_f2")
assert_match "Refusing to uninstall", cmd_fail("uninstall", "testball_f1")
assert_match "Uninstalling #{Formulary.factory(@f2_path).rack}",
cmd("uninstall", "testball_f2")
run_as_not_developer do
assert_match "Refusing to uninstall",
cmd_fail("uninstall", "testball_f1")
refute_empty f1.installed_kegs
assert_match "Uninstalling #{f2.rack}",
cmd("uninstall", "testball_f2")
assert_empty f2.installed_kegs
end
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")
run_as_not_developer do
assert_match "Refusing to uninstall",
cmd_fail("uninstall", "testball_f1", "--force")
refute_empty f1.installed_kegs
assert_match "Uninstalling testball_f2",
cmd("uninstall", "testball_f2", "--force")
assert_empty f2.installed_kegs
end
end

def test_uninstall_ignore_dependencies_leaving_dependents
cmd("install", "testball_f2")
run_as_not_developer do
assert_match "Uninstalling #{f1.rack}",
cmd("uninstall", "testball_f1", "--ignore-dependencies")
assert_empty f1.installed_kegs
end
end

def test_uninstall_leaving_dependents_developer
cmd("install", "testball_f2")
assert_match "Uninstalling #{f1.rack}",
cmd("uninstall", "testball_f1")
assert_empty f1.installed_kegs
end

def test_uninstall_dependent_first
cmd("install", "testball_f2")
assert_match "Uninstalling #{Formulary.factory(@f1_path).rack}",
cmd("uninstall", "testball_f2", "testball_f1")
run_as_not_developer do
assert_match "Uninstalling #{f1.rack}",
cmd("uninstall", "testball_f2", "testball_f1")
assert_empty f1.installed_kegs
end
end

def test_uninstall_dependent_last
cmd("install", "testball_f2")
assert_match "Uninstalling #{Formulary.factory(@f2_path).rack}",
cmd("uninstall", "testball_f1", "testball_f2")
run_as_not_developer do
assert_match "Uninstalling #{f2.rack}",
cmd("uninstall", "testball_f1", "testball_f2")
assert_empty f2.installed_kegs
end
end
end

0 comments on commit 7792acd

Please sign in to comment.