Browse files

Keep older gems needed for deps. Fixes #67

  • Loading branch information...
1 parent ed1098d commit 294aa56e222c54be0c26229a88f8cb721cd84700 @evanphx evanphx committed Mar 11, 2012
Showing with 26 additions and 0 deletions.
  1. +7 −0 lib/rubygems/commands/cleanup_command.rb
  2. +19 −0 test/rubygems/test_gem_commands_cleanup_command.rb
View
7 lib/rubygems/commands/cleanup_command.rb
@@ -26,6 +26,9 @@ def description # :nodoc:
<<-EOF
The cleanup command removes old gems from GEM_HOME. If an older version is
installed elsewhere in GEM_PATH the cleanup command won't touch it.
+
+Older gems that are required to satisify the dependencies of gems
+are not removed.
EOF
end
@@ -56,6 +59,8 @@ def execute
primary_gems[spec.name].version != spec.version
}
+ full = Gem::DependencyList.from_specs
+
deplist = Gem::DependencyList.new
gems_to_cleanup.uniq.each do |spec| deplist.add spec end
@@ -64,6 +69,8 @@ def execute
original_path = Gem.path
deps.each do |spec|
+ next unless full.ok_to_remove?(spec.full_name)
+
if options[:dryrun] then
say "Dry Run Mode: Would uninstall #{spec.full_name}"
else
View
19 test/rubygems/test_gem_commands_cleanup_command.rb
@@ -85,5 +85,24 @@ def test_execute_dry_run
assert_path_exists @a_1.gem_dir
end
+ def test_execute_keeps_older_versions_with_deps
+ @b_1 = quick_spec 'b', 1
+ @b_2 = quick_spec 'b', 2
+
+ @c = quick_spec 'c', 1 do |s|
+ s.add_dependency 'b', '1'
+ end
+
+ install_gem @c
+ install_gem @b_1
+ install_gem @b_2
+
+ @cmd.options[:args] = []
+
+ @cmd.execute
+
+ assert_path_exists @b_1.gem_dir
+ end
+
end

0 comments on commit 294aa56

Please sign in to comment.