Skip to content

Commit 248e1ba

Browse files
hsbtclaude
andcommitted
Mark overridden gems as changed against the existing lockfile
converge_dependencies compared the original Gemfile dependency against the locked spec, so adding `override "foo", version: "= X"` to a previously installed bundle did not register as a change. additional_base_requirements_to_prevent_downgrades then kept forwarding the locked version as a >= base requirement, which intersected the override and made it a no-op. Pass overrides into Definition.new positionally so they are available before the constructor calls converge_dependencies, and compare each direct dep's effective requirement (after override) to the locked spec. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6f397af commit 248e1ba

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

bundler/lib/bundler/definition.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def self.build(gemfile, lockfile, unlock)
5959
# to be updated or true if all gems should be updated
6060
# @param ruby_version [Bundler::RubyVersion, nil] Requested Ruby Version
6161
# @param optional_groups [Array(String)] A list of optional groups
62-
def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, optional_groups = [], gemfiles = [])
62+
def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, optional_groups = [], gemfiles = [], overrides = [])
6363
unlock ||= {}
6464

6565
if unlock == true
@@ -89,7 +89,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
8989
@specs = nil
9090
@ruby_version = ruby_version
9191
@gemfiles = gemfiles
92-
@overrides = []
92+
@overrides = overrides
9393

9494
@lockfile = lockfile
9595
@lockfile_contents = String.new
@@ -1044,7 +1044,7 @@ def converge_dependencies
10441044
@locked_specs.delete(locked_specs.select {|s| s.source != dep.source })
10451045
end
10461046

1047-
unless dep.matches_spec?(locked_specs.first)
1047+
unless apply_override_to(dep).matches_spec?(locked_specs.first)
10481048
@gems_to_unlock << name
10491049
dep_changed = true
10501050
end

bundler/lib/bundler/dsl.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ def override(target, **operations)
209209
def to_definition(lockfile, unlock)
210210
check_primary_source_safety
211211
lockfile = @lockfile unless @lockfile.nil?
212-
definition = Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles)
213-
definition.overrides = @overrides
214-
definition
212+
Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles, @overrides)
215213
end
216214

217215
def group(*args, &blk)

spec/install/gemfile/override_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,24 @@
3131

3232
expect(the_bundle).to include_gems "myrack 0.9.1"
3333
end
34+
35+
it "applies the override against an existing lockfile" do
36+
install_gemfile <<-G
37+
source "https://gem.repo1"
38+
gem "myrack"
39+
G
40+
41+
expect(the_bundle).to include_gems "myrack 1.0.0"
42+
43+
gemfile <<-G
44+
source "https://gem.repo1"
45+
override "myrack", version: "= 0.9.1"
46+
gem "myrack"
47+
G
48+
49+
bundle :install
50+
51+
expect(the_bundle).to include_gems "myrack 0.9.1"
52+
end
3453
end
3554
end

0 commit comments

Comments
 (0)