Skip to content

Commit

Permalink
fix(uninstall): Use the correct 'brew' in multi-installation setups
Browse files Browse the repository at this point in the history
  • Loading branch information
beeftornado committed Jan 25, 2022
1 parent 5ef564c commit e755439
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/brew-rmtree.rb
Expand Up @@ -40,6 +40,7 @@
require 'dependencies'
require 'shellwords'
require 'set'
require 'pathname'
require 'cmd/deps'
require 'cmd/uses'
require 'cli/parser'
Expand All @@ -59,6 +60,19 @@ def bash(command)
return %x! bash -c #{escaped_command} !
end

# Find the path to the currently running version of homebrew
# Fixes #46
def brew_path()
brew_home = Pathname.new(ENV["HOMEBREW_PREFIX"])
if brew_home.directory?
brew_bin = brew_home / "bin/brew"
if brew_bin.executable?
return brew_bin.realpath
end
end
return "brew"
end

# replaces Kernel#puts w/ do-nothing method
def puts_off
Kernel.module_eval %q{
Expand Down Expand Up @@ -114,16 +128,16 @@ def remove_keg(keg_name, dry_run)
end

# Remove old versions of keg
puts bash "brew cleanup #{keg_name} 2>/dev/null"
puts bash "#{brew_path} cleanup #{keg_name} 2>/dev/null"

# Remove current keg
puts bash "brew uninstall #{keg_name}"
puts bash "#{brew_path} uninstall #{keg_name}"
end

# A list of dependencies of keg_name that are still installed after removal
# of the keg
def orphaned_dependencies(keg_name)
bash("join <(sort <(brew leaves)) <(sort <(brew deps #{keg_name}))").split("\n")
bash("join <(sort <(#{brew_path} leaves)) <(sort <(#{brew_path} deps #{keg_name}))").split("\n")
end

# A list of kegs that use keg_name, using homebrew code instead of shell cmd
Expand Down

0 comments on commit e755439

Please sign in to comment.