Skip to content

Commit

Permalink
[rubygems/rubygems] Allow bundle update to downgrade gems by changi…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Nov 19, 2021
1 parent 55f5741 commit 80f39d7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def compute_requires
def additional_base_requirements_for_resolve
return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources)
dependencies_by_name = dependencies.inject({}) {|memo, dep| memo.update(dep.name => dep) }
@locked_gems.specs.reduce({}) do |requirements, locked_spec|
converge_specs(@locked_gems.specs).reduce({}) do |requirements, locked_spec|
name = locked_spec.name
dependency = dependencies_by_name[name]
next requirements if @locked_gems.dependencies[name] != dependency
Expand Down
61 changes: 61 additions & 0 deletions spec/bundler/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,67 @@

expect(the_bundle).to include_gems("a 1.0", "b 1.0")
end

it "should still downgrade if forced by the Gemfile, when transitive dependencies also need downgrade" do
build_repo4 do
build_gem "activesupport", "6.1.4.1" do |s|
s.add_dependency "tzinfo", "~> 2.0"
end

build_gem "activesupport", "6.0.4.1" do |s|
s.add_dependency "tzinfo", "~> 1.1"
end

build_gem "tzinfo", "2.0.4"
build_gem "tzinfo", "1.2.9"
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "activesupport", "~> 6.1.0"
G

expect(the_bundle).to include_gems("activesupport 6.1.4.1", "tzinfo 2.0.4")

gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "activesupport", "~> 6.0.0"
G

original_lockfile = lockfile

expected_lockfile = <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
activesupport (6.0.4.1)
tzinfo (~> 1.1)
tzinfo (1.2.9)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
activesupport (~> 6.0.0)
BUNDLED WITH
#{Bundler::VERSION}
L

bundle "update activesupport"
expect(the_bundle).to include_gems("activesupport 6.0.4.1", "tzinfo 1.2.9")
expect(lockfile).to eq(expected_lockfile)

lockfile original_lockfile
bundle "update"
expect(the_bundle).to include_gems("activesupport 6.0.4.1", "tzinfo 1.2.9")
expect(lockfile).to eq(expected_lockfile)

lockfile original_lockfile
bundle "lock --update"
expect(the_bundle).to include_gems("activesupport 6.0.4.1", "tzinfo 1.2.9")
expect(lockfile).to eq(expected_lockfile)
end
end

describe "with --local option" do
Expand Down

0 comments on commit 80f39d7

Please sign in to comment.