summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/definition.rb2
-rw-r--r--lib/bundler/installer.rb2
-rw-r--r--lib/bundler/source.rb2
-rw-r--r--lib/bundler/source/rubygems.rb21
-rw-r--r--lib/bundler/source_list.rb4
-rw-r--r--spec/bundler/cache/gems_spec.rb5
6 files changed, 32 insertions, 4 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index c31682ce4e..c3eae50f65 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -220,6 +220,8 @@ module Bundler
def prefer_local!
@prefer_local = true
+
+ sources.prefer_local!
end
# For given dependency list returns a SpecSet with Gemspec of all the required
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 1cd49d8897..c2da63c822 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -193,7 +193,7 @@ module Bundler
def install(options)
standalone = options[:standalone]
force = options[:force]
- local = options[:local]
+ local = options[:local] || options[:"prefer-local"]
jobs = installation_parallelization
spec_installations = ParallelInstaller.call(self, @definition.specs, jobs, standalone, force, local: local)
spec_installations.each do |installation|
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 115dbd1378..232873503b 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -35,6 +35,8 @@ module Bundler
spec.source == self
end
+ def prefer_local!; end
+
def local!; end
def local_only!; end
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 36185561fa..f1d6dcb3b9 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -19,6 +19,7 @@ module Bundler
@allow_remote = false
@allow_cached = false
@allow_local = options["allow_local"] || false
+ @prefer_local = false
@checksum_store = Checksum::Store.new
Array(options["remotes"]).reverse_each {|r| add_remote(r) }
@@ -30,6 +31,10 @@ module Bundler
@caches ||= [cache_path, *Bundler.rubygems.gem_cache]
end
+ def prefer_local!
+ @prefer_local = true
+ end
+
def local_only!
@specs = nil
@allow_local = true
@@ -37,6 +42,10 @@ module Bundler
@allow_remote = false
end
+ def local_only?
+ @allow_local && !@allow_remote
+ end
+
def local!
return if @allow_local
@@ -139,9 +148,15 @@ module Bundler
index.merge!(cached_specs) if @allow_cached
index.merge!(installed_specs) if @allow_local
- # complete with default specs, only if not already available in the
- # index through remote, cached, or installed specs
- index.use(default_specs) if @allow_local
+ if @allow_local
+ if @prefer_local
+ index.merge!(default_specs)
+ else
+ # complete with default specs, only if not already available in the
+ # index through remote, cached, or installed specs
+ index.use(default_specs)
+ end
+ end
index
end
diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb
index 343bb73975..b7b2c4209a 100644
--- a/lib/bundler/source_list.rb
+++ b/lib/bundler/source_list.rb
@@ -141,6 +141,10 @@ module Bundler
different_sources?(lock_sources, replacement_sources)
end
+ def prefer_local!
+ all_sources.each(&:prefer_local!)
+ end
+
def local_only!
all_sources.each(&:local_only!)
end
diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb
index 7563580aac..c68b20225a 100644
--- a/spec/bundler/cache/gems_spec.rb
+++ b/spec/bundler/cache/gems_spec.rb
@@ -113,6 +113,11 @@ RSpec.describe "bundle cache" do
expect(out).to include("Using json #{default_json_version}")
end
+ it "does not use remote gems when installing with --prefer-local flag" do
+ install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true, "prefer-local": true
+ expect(out).to include("Using json #{default_json_version}")
+ end
+
it "caches remote and builtin gems" do
install_gemfile <<-G
source "https://gem.repo2"