aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2023-03-14 15:27:15 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-03-17 18:50:55 +0900
commitdd0f0a5e6eb10bfa0641a3ce5d4e6374df493adb (patch)
treed0fca6126fe06582ce93fdb3570fce99a59f8718
parent123bedd295b584369955461ff452ca1ec005e7dd (diff)
downloadruby-dd0f0a5e6eb10bfa0641a3ce5d4e6374df493adb.tar.gz
[rubygems/rubygems] Fix `gem uninstall` with `--install-dir`
https://github.com/rubygems/rubygems/commit/ac23687353
-rw-r--r--lib/rubygems/commands/uninstall_command.rb3
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb20
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 3c520826e5..29f6013c59 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -125,6 +125,9 @@ that is a dependency of an existing gem. You can use the
def execute
check_version
+ # Consider only gem specifications installed at `--install-dir`
+ Gem::Specification.dirs = options[:install_dir] if options[:install_dir]
+
if options[:all] && !options[:args].empty?
uninstall_specific
elsif options[:all]
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index a5df8f5022..e5090c852f 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -375,6 +375,26 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert_includes e.message, "a is not installed in GEM_HOME"
end
+ def test_execute_outside_gem_home_when_install_dir_given
+ gemhome2 = "#{@gemhome}2"
+
+ a_4, = util_gem "a", 4
+ install_gem a_4 , :install_dir => gemhome2
+
+ assert_gems_presence "a-4", dirs: [@gemhome, gemhome2]
+
+ Gem::Specification.dirs = [@gemhome]
+
+ @cmd.options[:install_dir] = gemhome2
+ @cmd.options[:args] = ["a:4"]
+
+ @cmd.execute
+
+ Gem::Specification.dirs = [gemhome2]
+
+ refute_includes Gem::Specification.all_names.sort, "a-4"
+ end
+
def test_handle_options
@cmd.handle_options %w[]