Skip to content

Commit ee7b747

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Fix --prefer-local not respecting default gems
ruby/rubygems@3df86cd9c6
1 parent 891ecc6 commit ee7b747

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

lib/bundler/definition.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def remotely!
220220

221221
def prefer_local!
222222
@prefer_local = true
223+
224+
sources.prefer_local!
223225
end
224226

225227
# For given dependency list returns a SpecSet with Gemspec of all the required

lib/bundler/installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def generate_standalone_bundler_executable_stubs(spec, options = {})
193193
def install(options)
194194
standalone = options[:standalone]
195195
force = options[:force]
196-
local = options[:local]
196+
local = options[:local] || options[:"prefer-local"]
197197
jobs = installation_parallelization
198198
spec_installations = ParallelInstaller.call(self, @definition.specs, jobs, standalone, force, local: local)
199199
spec_installations.each do |installation|

lib/bundler/source.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def can_lock?(spec)
3535
spec.source == self
3636
end
3737

38+
def prefer_local!; end
39+
3840
def local!; end
3941

4042
def local_only!; end

lib/bundler/source/rubygems.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def initialize(options = {})
1919
@allow_remote = false
2020
@allow_cached = false
2121
@allow_local = options["allow_local"] || false
22+
@prefer_local = false
2223
@checksum_store = Checksum::Store.new
2324

2425
Array(options["remotes"]).reverse_each {|r| add_remote(r) }
@@ -30,13 +31,21 @@ def caches
3031
@caches ||= [cache_path, *Bundler.rubygems.gem_cache]
3132
end
3233

34+
def prefer_local!
35+
@prefer_local = true
36+
end
37+
3338
def local_only!
3439
@specs = nil
3540
@allow_local = true
3641
@allow_cached = false
3742
@allow_remote = false
3843
end
3944

45+
def local_only?
46+
@allow_local && !@allow_remote
47+
end
48+
4049
def local!
4150
return if @allow_local
4251

@@ -139,9 +148,15 @@ def specs
139148
index.merge!(cached_specs) if @allow_cached
140149
index.merge!(installed_specs) if @allow_local
141150

142-
# complete with default specs, only if not already available in the
143-
# index through remote, cached, or installed specs
144-
index.use(default_specs) if @allow_local
151+
if @allow_local
152+
if @prefer_local
153+
index.merge!(default_specs)
154+
else
155+
# complete with default specs, only if not already available in the
156+
# index through remote, cached, or installed specs
157+
index.use(default_specs)
158+
end
159+
end
145160

146161
index
147162
end

lib/bundler/source_list.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def expired_sources?(replacement_sources)
141141
different_sources?(lock_sources, replacement_sources)
142142
end
143143

144+
def prefer_local!
145+
all_sources.each(&:prefer_local!)
146+
end
147+
144148
def local_only!
145149
all_sources.each(&:local_only!)
146150
end

spec/bundler/cache/gems_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
expect(out).to include("Using json #{default_json_version}")
114114
end
115115

116+
it "does not use remote gems when installing with --prefer-local flag" do
117+
install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true, "prefer-local": true
118+
expect(out).to include("Using json #{default_json_version}")
119+
end
120+
116121
it "caches remote and builtin gems" do
117122
install_gemfile <<-G
118123
source "https://gem.repo2"

0 commit comments

Comments
 (0)