ruby-changes:68424
From: David <ko1@a...>
Date: Wed, 13 Oct 2021 16:22:01 +0900 (JST)
Subject: [ruby-changes:68424] 0f1f95a3e3 (master): [rubygems/rubygems] Fix `bundle install` to force reinstallation of deleted gems
https://git.ruby-lang.org/ruby.git/commit/?id=0f1f95a3e3 From 0f1f95a3e3011b6c61fdc455e4078e5e231548e3 Mon Sep 17 00:00:00 2001 From: David Rodriguez <deivid.rodriguez@r...> Date: Sat, 9 Oct 2021 13:42:05 +0200 Subject: [rubygems/rubygems] Fix `bundle install` to force reinstallation of deleted gems https://github.com/rubygems/rubygems/commit/8950631f02 --- lib/bundler/cli/info.rb | 7 +++---- lib/bundler/rubygems_ext.rb | 4 ++++ lib/bundler/source/rubygems.rb | 2 +- spec/bundler/commands/install_spec.rb | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 00140e3bd1..3afed89ceb 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -45,7 +45,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/info.rb#L45 path = File.expand_path("../../../..", __FILE__) else path = spec.full_gem_path - unless File.directory?(path) + if spec.deleted_gem? return Bundler.ui.warn "The gem #{name} has been deleted. It was installed at: #{path}" end end @@ -56,7 +56,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/info.rb#L56 def print_gem_info(spec) metadata = spec.metadata name = spec.name - path = spec.full_gem_path gem_info = String.new gem_info << " * #{name} (#{spec.version}#{spec.git_version})\n" gem_info << "\tSummary: #{spec.summary}\n" if spec.summary @@ -68,10 +67,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/info.rb#L67 gem_info << "\tChangelog: #{metadata["changelog_uri"]}\n" if metadata.key?("changelog_uri") gem_info << "\tBug Tracker: #{metadata["bug_tracker_uri"]}\n" if metadata.key?("bug_tracker_uri") gem_info << "\tMailing List: #{metadata["mailing_list_uri"]}\n" if metadata.key?("mailing_list_uri") - gem_info << "\tPath: #{path}\n" + gem_info << "\tPath: #{spec.full_gem_path}\n" gem_info << "\tDefault Gem: yes" if spec.respond_to?(:default_gem?) && spec.default_gem? - unless File.directory?(path) + if spec.deleted_gem? return Bundler.ui.warn "The gem #{name} has been deleted. Gemspec information is still available though:\n#{gem_info}" end diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 2613207826..5d572aa73d 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -85,6 +85,10 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L85 dependencies - development_dependencies end + def deleted_gem? + !default_gem? && !File.directory?(full_gem_path) + end + private def dependencies_to_gemfile(dependencies, group = nil) diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 593f68d5cd..28c1ee3c96 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -480,7 +480,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/rubygems.rb#L480 end def installed?(spec) - installed_specs[spec].any? + installed_specs[spec].any? && !spec.deleted_gem? end def requires_sudo? diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 35c45b68b7..1e8d2295ba 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -94,6 +94,21 @@ RSpec.describe "bundle install with gem sources" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/install_spec.rb#L94 expect(the_bundle).to include_gems("rack 1.0.0") end + it "auto-heals missing gems" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G + + FileUtils.rm_rf(default_bundle_path("gems/rack-1.0.0")) + + bundle "install --verbose" + + expect(out).to include("Installing rack 1.0.0") + expect(default_bundle_path("gems/rack-1.0.0")).to exist + expect(the_bundle).to include_gems("rack 1.0.0") + end + it "fetches gems when multiple versions are specified" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/