summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-07-25 20:08:54 +0000
committerThe Bundler Bot <bot@bundler.io>2017-07-25 20:08:54 +0000
commita77bb6a39a7a96f3695a42ff18b3925b9b8aea3f (patch)
tree74a0f52ce557cdcc2add21554c4eb536f5bb2668
parent964f63deb46a1a1651de1ee897281a2843801709 (diff)
parent1f564fc439d5f50920514fe582a91b42448bc3a7 (diff)
downloadbundler-a77bb6a39a7a96f3695a42ff18b3925b9b8aea3f.tar.gz
Auto merge of #5896 - bundler:seg-globally-cache-git-repos, r=indirect
[Source::Git] Cache repos globally ### What was the end-user problem that led to this PR? Closes https://github.com/bundler/bundler/issues/5895. The problem was: > Now that we have a "global" user-wide cache of gems, it would be great to also have a user-wide place to keep git repos. In 1.x, the default system path provided that user-wide cache, and losing it because of the default 2.0 path will slow down installs with git repos by a lot. ### What was your diagnosis of the problem? My diagnosis was we needed to change the git cache location to something global ### What is your fix for the problem, implemented in this PR? My fix uses the global "~/.bundle/cache" directory to cache git gems ### Why did you choose this fix out of the possible options? I chose this fix because it means the cache (which only contains _downloaded_ information, nothing evaluated at runtime) can be shared across every app and every ruby version
-rw-r--r--lib/bundler.rb4
-rw-r--r--lib/bundler/source/git.rb8
-rw-r--r--spec/commands/clean_spec.rb9
-rw-r--r--spec/install/gemfile/git_spec.rb15
4 files changed, 21 insertions, 15 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index edef1620e8..5eb2d1bca4 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -207,10 +207,6 @@ module Bundler
bundle_path.join("specifications")
end
- def cache
- bundle_path.join("cache/bundler")
- end
-
def user_cache
user_bundle_path.join("cache")
end
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index eb605771f4..fd8f6debea 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -211,11 +211,11 @@ module Bundler
@cache_path ||= begin
git_scope = "#{base_name}-#{uri_hash}"
- if Bundler.requires_sudo?
- Bundler.user_bundle_path.join("cache/git", git_scope)
+ if Bundler.requires_sudo? || Bundler.feature_flag.global_gem_cache?
+ Bundler.user_cache
else
- Bundler.cache.join("git", git_scope)
- end
+ Bundler.bundle_path.join("cache", "bundler")
+ end.join("git", git_scope)
end
end
diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb
index 9be8f24fda..be8f80065c 100644
--- a/spec/commands/clean_spec.rb
+++ b/spec/commands/clean_spec.rb
@@ -142,7 +142,8 @@ RSpec.describe "bundle clean" do
bundle :clean
digest = Digest::SHA1.hexdigest(git_path.to_s)
- expect(vendored_gems("cache/bundler/git/foo-1.0-#{digest}")).to exist
+ cache_path = Bundler::VERSION.start_with?("1.") ? vendored_gems("cache/bundler/git/foo-1.0-#{digest}") : home(".bundle/cache/git/foo-1.0-#{digest}")
+ expect(cache_path).to exist
end
it "removes unused git gems" do
@@ -671,7 +672,7 @@ RSpec.describe "bundle clean" do
gem "foo"
G
- bundle "install", forgotten_command_line_options(:path => "vendor/bundle", :clean => false)
+ bundle! "install", forgotten_command_line_options(:path => "vendor/bundle", :clean => false)
gemfile <<-G
source "file://#{gem_repo1}"
@@ -680,8 +681,8 @@ RSpec.describe "bundle clean" do
gem "weakling"
G
- bundle "config auto_install 1"
- bundle :clean
+ bundle! "config auto_install 1"
+ bundle! :clean
expect(out).to include("Installing weakling 0.0.3")
should_have_gems "thin-1.0", "rack-1.0.0", "weakling-0.0.3"
should_not_have_gems "foo-1.0"
diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb
index a3e69325cc..feafb568dd 100644
--- a/spec/install/gemfile/git_spec.rb
+++ b/spec/install/gemfile/git_spec.rb
@@ -26,8 +26,15 @@ RSpec.describe "bundle install with git sources" do
expect(out).to eq("WIN")
end
- it "caches the git repo" do
- expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"].size).to eq(1)
+ it "caches the git repo", :bundler => "< 2" do
+ expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"]).to have_attributes :size => 1
+ end
+
+ it "caches the git repo globally" do
+ simulate_new_machine
+ bundle! "config global_gem_cache true"
+ bundle! :install
+ expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes :size => 1
end
it "caches the evaluated gemspec" do
@@ -278,6 +285,8 @@ RSpec.describe "bundle install with git sources" do
sys_exec!("git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1")
end
+ bundle! "config global_gem_cache true"
+
install_gemfile! <<-G
git "#{lib_path("foo-1.0")}" do
gem "foo"
@@ -287,7 +296,7 @@ RSpec.describe "bundle install with git sources" do
# ensure we also git fetch after cloning
bundle! :update, :all => bundle_update_requires_all?
- Dir.chdir(Dir[default_bundle_path("cache/bundler/git/foo-*")].first) do
+ Dir.chdir(Dir[home(".bundle/cache/git/foo-*")].first) do
sys_exec("git ls-remote .")
end