diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-05-01 13:38:49 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-05-07 09:24:56 +0000 |
| commit | 9cc8943d8ddd7b4aae9b41cadb3f753cecaef16b (patch) | |
| tree | 5f4cc1683827731b105453521119a3581e810e67 | |
| parent | ddabda72215c93af76f9fcc3c79660072833e683 (diff) | |
[ruby/rubygems] Mark transitive-only overrides as changed against the lockfile
converge_dependencies only iterates @dependencies (Gemfile-declared
direct deps), so an override that targets a gem present only as a
transitive dependency never registered as a change. With an existing
lockfile, @dependency_changes stayed false, the resolver was skipped,
and the override was a silent no-op. After the direct-dep loop,
inspect @overrides for any String target that is locked but not a
direct dep and force it onto @gems_to_unlock / @changed_dependencies
so resolution runs and the Resolver-side override hook applies.
https://github.com/ruby/rubygems/commit/a4f8f386f2
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | lib/bundler/definition.rb | 16 | ||||
| -rw-r--r-- | spec/bundler/install/gemfile/override_spec.rb | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index c2eab0efc6..a64b67cb44 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -1054,9 +1054,25 @@ module Bundler @changed_dependencies << name if dep_changed end + converge_overrides_outside_dependencies + @changed_dependencies.any? end + def converge_overrides_outside_dependencies + @overrides.each do |override| + next unless override.target.is_a?(String) + + name = override.target + next if @changed_dependencies.include?(name) + next if @dependencies.any? {|d| d.name == name } + next if @originally_locked_specs[name].empty? + + @gems_to_unlock << name + @changed_dependencies << name + end + end + # Remove elements from the locked specs that are expired. This will most # commonly happen if the Gemfile has changed since the lockfile was last # generated diff --git a/spec/bundler/install/gemfile/override_spec.rb b/spec/bundler/install/gemfile/override_spec.rb index 8a00186d60..7a7f8078a8 100644 --- a/spec/bundler/install/gemfile/override_spec.rb +++ b/spec/bundler/install/gemfile/override_spec.rb @@ -109,5 +109,24 @@ RSpec.describe "override DSL" do expect(the_bundle).to include_gems "myrack 1.0.0", "myrack_middleware 1.0" end + + it "applies a transitive-only override against an existing lockfile" do + install_gemfile <<-G + source "https://gem.repo1" + gem "myrack_middleware" + G + + expect(the_bundle).to include_gems "myrack 0.9.1", "myrack_middleware 1.0" + + gemfile <<-G + source "https://gem.repo1" + override "myrack", version: "= 1.0.0" + gem "myrack_middleware" + G + + bundle :install + + expect(the_bundle).to include_gems "myrack 1.0.0", "myrack_middleware 1.0" + end end end |
