summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-06-18 08:59:40 +0000
committerBundlerbot <bot@bundler.io>2019-06-18 08:59:40 +0000
commit0b5da910e71760eb585b34d08d43ea31b988ca24 (patch)
treee33d50bbbad79e8ba78757189d0b5be1fbfb71f1
parent4dc6d1d115802640e4a8c20769c428932f641340 (diff)
parent0646f9e286ff330a227cea01812b1ead4fa601cd (diff)
downloadbundler-0b5da910e71760eb585b34d08d43ea31b988ca24.tar.gz
Merge #7211
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 https://github.com/rubygems/rubygems/pull/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>
-rw-r--r--lib/bundler/definition.rb2
-rw-r--r--spec/commands/clean_spec.rb26
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 76950ff96a..4664eec24d 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -317,7 +317,7 @@ module Bundler
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
diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb
index 0053947c85..a3bbe9f01f 100644
--- a/spec/commands/clean_spec.rb
+++ b/spec/commands/clean_spec.rb
@@ -183,6 +183,32 @@ RSpec.describe "bundle clean" do
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"))