Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundler/lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def default_specs
end

def find_bundler(version)
find_name("bundler").find {|s| s.version.to_s == version }
find_name("bundler").find {|s| s.version.to_s == version.to_s }
end

def find_name(name)
Expand Down
9 changes: 8 additions & 1 deletion bundler/lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ def clean(dry_run = false)
spec_cache_paths = []
spec_gemspec_paths = []
spec_extension_paths = []
Bundler.rubygems.add_default_gems_to(specs).values.each do |spec|
specs_to_keep = Bundler.rubygems.add_default_gems_to(specs).values

current_bundler = Bundler.rubygems.find_bundler(Bundler.gem_version)
if current_bundler
specs_to_keep << current_bundler
end

specs_to_keep.each do |spec|
spec_gem_paths << spec.full_gem_path
# need to check here in case gems are nested like for the rails git repo
md = %r{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path)
Expand Down
37 changes: 37 additions & 0 deletions bundler/spec/commands/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,41 @@ def should_not_have_gems(*gems)

expect(very_simple_binary_extensions_dir).to be_nil
end

it "does not remove the bundler version currently running" do
gemfile <<-G
source "https://gem.repo1"

gem "myrack"
G

bundle "config set path vendor/bundle"
bundle "install"

version = Bundler.gem_version.to_s
# Simulate that the locked bundler version is installed in the bundle path
# by creating the gem directory and gemspec (as would happen after bundle install with that version)
Pathname(vendored_gems("cache/bundler-#{version}.gem")).tap do |path|
path.basename.mkpath
FileUtils.touch(path)
end
FileUtils.touch(vendored_gems("gems/bundler-#{version}"))
Pathname(vendored_gems("specifications/bundler-#{version}.gemspec")).tap do |path|
path.basename.mkpath
path.write(<<~GEMSPEC)
Gem::Specification.new do |s|
s.name = "bundler"
s.version = "#{version}"
s.authors = ["bundler team"]
s.summary = "The best way to manage your application's dependencies"
end
GEMSPEC
end

should_have_gems "bundler-#{version}"

bundle :clean

should_have_gems "bundler-#{version}"
end
end