ruby-changes:67456
From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:37 +0900 (JST)
Subject: [ruby-changes:67456] 3683781f53 (master): [rubygems/rubygems] Restore working `bundle check` behaviour
https://git.ruby-lang.org/ruby.git/commit/?id=3683781f53 From 3683781f53cc22b9fa507e4a2848c30086fa7897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Wed, 18 Aug 2021 09:58:51 +0200 Subject: [rubygems/rubygems] Restore working `bundle check` behaviour As part of a recent bug fix where bundler was accidentally hitting the network when not supposed to, I made some refactoring, and the commit I'm reverting here (https://github.com/rubygems/rubygems/commit/d74830d00bb541883377992f56818620a78930b0) was some cleanup that those refactorings allowed according to "past me". That was completely wrong, `bundle check` should never consider cached gems, only installed gems, so the code that was removed was necessary. https://github.com/rubygems/rubygems/commit/5483e98305 --- lib/bundler/cli/check.rb | 2 +- lib/bundler/definition.rb | 6 ++++++ lib/bundler/source.rb | 2 ++ lib/bundler/source/rubygems.rb | 6 ++++++ lib/bundler/source_list.rb | 4 ++++ spec/bundler/commands/check_spec.rb | 16 ++++++++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 4221fc7..65c5133 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -15,7 +15,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/check.rb#L15 definition.validate_runtime! begin - definition.resolve_with_cache! + definition.resolve_only_locally! not_installed = definition.missing_specs rescue GemNotFound, VersionConflict Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies." diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 621bda6..2bd1290 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -166,6 +166,12 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L166 @multisource_allowed end + def resolve_only_locally! + @remote = false + sources.local_only! + resolve + end + def resolve_with_cache! sources.cached! resolve diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 7bf493d..434112a 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -36,6 +36,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source.rb#L36 def local!; end + def local_only!; end + def cached!; end def remote!; end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 298ff98..2e0ecb1 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -26,6 +26,12 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/rubygems.rb#L26 Array(options["remotes"]).reverse_each {|r| add_remote(r) } end + def local_only! + @specs = nil + @allow_local = true + @allow_remote = false + end + def local! return if @allow_local diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index b97206f..d6310b7 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -136,6 +136,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source_list.rb#L136 different_sources?(lock_sources, replacement_sources) end + def local_only! + all_sources.each(&:local_only!) + end + def cached! all_sources.each(&:cached!) end diff --git a/spec/bundler/commands/check_spec.rb b/spec/bundler/commands/check_spec.rb index c48220f..7eb3fec 100644 --- a/spec/bundler/commands/check_spec.rb +++ b/spec/bundler/commands/check_spec.rb @@ -137,6 +137,22 @@ RSpec.describe "bundle check" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/check_spec.rb#L137 expect(exitstatus).to eq(1) end + it "ensures that gems are actually installed and not just cached in applications' cache" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + bundle "config set --local path vendor/bundle" + bundle :cache + + gem_command "uninstall rack", :env => { "GEM_HOME" => vendored_gems.to_s } + + bundle "check", :raise_on_error => false + expect(err).to include("* rack (1.0.0)") + expect(exitstatus).to eq(1) + end + it "ignores missing gems restricted to other platforms" do gemfile <<-G source "#{file_uri_for(gem_repo1)}" -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/