Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7211
Browse files Browse the repository at this point in the history
7211: Use real paths for `bundle clean` r=colby-swandale a=deivid-rodriguez

Fixes #7208.

### What was the end-user problem that led to this PR?

The problem was that since rubygems 3.0, `bundle clean` incorrectly cleans git gems when they are installed to a symlinked location, but still being used.

### What was your diagnosis of the problem?

My diagnosis was that since rubygems/rubygems#2352, `Gem.dir` returns an array of realpaths, not symlinked ones. However, we don't do the same resolution on the `bundler` side, so in this situation git gems are not correctly skipped from the cleanup.

### What is your fix for the problem, implemented in this PR?

My fix is to resolve the array of paths `bundle clean` uses to do its thing into an array of real paths, just like rubygems does now.

### Why did you choose this fix out of the possible options?

I chose this fix because it fixes the problem.


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Jun 18, 2019
2 parents 4dc6d1d + 0646f9e commit 0b5da91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/definition.rb
Expand Up @@ -317,7 +317,7 @@ def has_local_dependencies?
end

def spec_git_paths
sources.git_sources.map {|s| s.path.to_s }
sources.git_sources.map {|s| File.realpath(s.path) }
end

def groups
Expand Down
26 changes: 26 additions & 0 deletions spec/commands/clean_spec.rb
Expand Up @@ -183,6 +183,32 @@ def should_not_have_gems(*gems)
expect(vendored_gems("bin/rackup")).to exist
end

it "keeps used git gems even if installed to a symlinked location" do
build_git "foo", :path => lib_path("foo")
git_path = lib_path("foo")
revision = revision_for(git_path)

gemfile <<-G
source "file://#{gem_repo1}"
gem "rack", "1.0.0"
git "#{git_path}", :ref => "#{revision}" do
gem "foo"
end
G

FileUtils.mkdir_p(bundled_app("real-path"))
FileUtils.ln_sf(bundled_app("real-path"), bundled_app("symlink-path"))

bundle "install", forgotten_command_line_options(:path => bundled_app("symlink-path"))

bundle :clean

expect(out).not_to include("Removing foo (#{revision[0..11]})")

expect(bundled_app("symlink-path/#{Bundler.ruby_scope}/bundler/gems/foo-#{revision[0..11]}")).to exist
end

it "removes old git gems" do
build_git "foo-bar", :path => lib_path("foo-bar")
revision = revision_for(lib_path("foo-bar"))
Expand Down

0 comments on commit 0b5da91

Please sign in to comment.