Skip to content

Commit 23047a0

Browse files
Merge pull request #8484 from rubygems/deivid-rodriguez/prefer-local-enhancements
Fix `bundle install --prefer-local` sometimes installing very old versions
2 parents 26fb733 + 118f838 commit 23047a0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

bundler/lib/bundler/resolver.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,18 @@ def filter_prereleases(specs, package)
389389
end
390390

391391
def filter_remote_specs(specs, package)
392-
return specs unless package.prefer_local?
392+
if package.prefer_local?
393+
local_specs = specs.select {|s| s.is_a?(StubSpecification) }
393394

394-
specs.select {|s| s.is_a?(StubSpecification) }
395+
if local_specs.empty?
396+
package.consider_remote_versions!
397+
specs
398+
else
399+
local_specs
400+
end
401+
else
402+
specs
403+
end
395404
end
396405

397406
# Ignore versions that depend on themselves incorrectly

bundler/spec/commands/install_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,26 @@ def run
16061606
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching b 1.0.0").and include("Installing b 1.0.0")
16071607
expect(last_command).to be_success
16081608
end
1609+
1610+
it "resolves to the latest version if no gems are available locally" do
1611+
build_repo4 do
1612+
build_gem "myreline", "0.3.8"
1613+
build_gem "debug", "0.2.1"
1614+
1615+
build_gem "debug", "1.10.0" do |s|
1616+
s.add_dependency "myreline"
1617+
end
1618+
end
1619+
1620+
install_gemfile <<~G, "prefer-local": true, verbose: true
1621+
source "https://gem.repo4"
1622+
1623+
gem "debug"
1624+
G
1625+
1626+
expect(out).to include("Fetching debug 1.10.0").and include("Installing debug 1.10.0").and include("Fetching myreline 0.3.8").and include("Installing myreline 0.3.8")
1627+
expect(last_command).to be_success
1628+
end
16091629
end
16101630

16111631
context "with a symlinked configured as bundle path and a gem with symlinks" do

0 commit comments

Comments
 (0)