Skip to content

Commit

Permalink
Fix bundle remove by invalidating cached Bundle.defintion.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
duckinator authored and deivid-rodriguez committed Jun 1, 2022
1 parent 7f464c0 commit aa0794d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bundler/lib/bundler/injector.rb
Expand Up @@ -72,6 +72,10 @@ def remove(gemfile_path, lockfile_path)

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
Expand Down
30 changes: 30 additions & 0 deletions bundler/spec/commands/remove_spec.rb
Expand Up @@ -13,6 +13,36 @@
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
Expand Down

0 comments on commit aa0794d

Please sign in to comment.