[前][次][番号順一覧][スレッド一覧]

ruby-changes:72034

From: Ellen <ko1@a...>
Date: Wed, 1 Jun 2022 19:01:31 +0900 (JST)
Subject: [ruby-changes:72034] 1177665e62 (master): [rubygems/rubygems] Fix `bundle remove` by invalidating cached `Bundle.defintion`.

https://git.ruby-lang.org/ruby.git/commit/?id=1177665e62

From 1177665e6224f8491db82997c8774e9485564e41 Mon Sep 17 00:00:00 2001
From: Ellen Marie Dash <the@s...>
Date: Thu, 31 Mar 2022 23:44:31 +0000
Subject: [rubygems/rubygems] Fix `bundle remove` by invalidating cached
 `Bundle.defintion`.

Prior to this commit, `bundle add GEM_NAME` updated the lockfile,
but `bundle remove GEM_NAME` left GEM_NAME in the lockfile.

By invalidating the cached `Bundle.definition`, the existing code
handles that without a problem.

https://github.com/rubygems/rubygems/commit/aa0794d6a9
---
 lib/bundler/injector.rb              |  4 ++++
 spec/bundler/commands/remove_spec.rb | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index 42f837a919..f6550abe88 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -72,6 +72,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/injector.rb#L72
 
         deps.each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep, false)} was removed." }
       end
+
+      # Invalidate the cached Bundler.definition.
+      # This prevents e.g. `bundle remove ...` from using outdated information.
+      Bundler.reset_paths!
     end
 
     private
diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb
index 95d6e75e9f..ceba6c5ede 100644
--- a/spec/bundler/commands/remove_spec.rb
+++ b/spec/bundler/commands/remove_spec.rb
@@ -13,6 +13,36 @@ RSpec.describe "bundle remove" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/remove_spec.rb#L13
     end
   end
 
+  context "after 'bundle install' is run" do
+    describe "running 'bundle remove GEM_NAME'" do
+      it "removes it from the lockfile" do
+        rack_dep = <<~L
+
+          DEPENDENCIES
+            rack
+
+        L
+
+        gemfile <<-G
+          source "#{file_uri_for(gem_repo1)}"
+
+          gem "rack"
+        G
+
+        bundle "install"
+
+        expect(lockfile).to include(rack_dep)
+
+        bundle "remove rack"
+
+        expect(gemfile).to eq <<~G
+          source "#{file_uri_for(gem_repo1)}"
+        G
+        expect(lockfile).to_not include(rack_dep)
+      end
+    end
+  end
+
   context "when --install flag is specified", :bundler => "< 3" do
     it "removes gems from .bundle" do
       gemfile <<-G
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]