Skip to content

Commit eec6830

Browse files
Fix locked source not getting respected when bundle update <specific_gem> is run
1 parent d8cf4aa commit eec6830

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

bundler/lib/bundler/definition.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def missing_specs?
214214
@resolve = nil
215215
@resolver = nil
216216
@resolution_packages = nil
217+
@source_requirements = nil
217218
@specs = nil
218219

219220
Bundler.ui.debug "The definition is missing dependencies, failed to resolve & materialize locally (#{e})"
@@ -499,6 +500,8 @@ def unlocking?
499500
@unlocking
500501
end
501502

503+
attr_writer :source_requirements
504+
502505
private
503506

504507
attr_reader :sources
@@ -971,6 +974,10 @@ def metadata_dependencies
971974
end
972975

973976
def source_requirements
977+
@source_requirements ||= find_source_requirements
978+
end
979+
980+
def find_source_requirements
974981
# Record the specs available in each gem's source, so that those
975982
# specs will be available later when the resolver knows where to
976983
# look for that gemspec (or its dependencies)
@@ -1052,6 +1059,7 @@ def additional_base_requirements_to_force_updates(resolution_packages)
10521059

10531060
def dup_for_full_unlock
10541061
unlocked_definition = self.class.new(@lockfile, @dependencies, @sources, true, @ruby_version, @optional_groups, @gemfiles)
1062+
unlocked_definition.source_requirements = source_requirements
10551063
unlocked_definition.gem_version_promoter.tap do |gvp|
10561064
gvp.level = gem_version_promoter.level
10571065
gvp.strict = gem_version_promoter.strict

bundler/spec/install/gemfile/sources_spec.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,4 +1921,70 @@
19211921
expect(err).to include("Could not find gem 'example' in rubygems repository https://gem.repo4/")
19221922
end
19231923
end
1924+
1925+
context "when a gem has versions in two sources, but only the locked one has updates" do
1926+
let(:original_lockfile) do
1927+
<<~L
1928+
GEM
1929+
remote: https://main.source/
1930+
specs:
1931+
activesupport (1.0)
1932+
bigdecimal
1933+
bigdecimal (1.0.0)
1934+
1935+
GEM
1936+
remote: https://main.source/extra/
1937+
specs:
1938+
foo (1.0)
1939+
bigdecimal
1940+
1941+
PLATFORMS
1942+
#{lockfile_platforms}
1943+
1944+
DEPENDENCIES
1945+
activesupport
1946+
foo!
1947+
1948+
BUNDLED WITH
1949+
#{Bundler::VERSION}
1950+
L
1951+
end
1952+
1953+
before do
1954+
build_repo3 do
1955+
build_gem "activesupport" do |s|
1956+
s.add_dependency "bigdecimal"
1957+
end
1958+
1959+
build_gem "bigdecimal", "1.0.0"
1960+
build_gem "bigdecimal", "3.3.1"
1961+
end
1962+
1963+
build_repo4 do
1964+
build_gem "foo" do |s|
1965+
s.add_dependency "bigdecimal"
1966+
end
1967+
1968+
build_gem "bigdecimal", "1.0.0"
1969+
end
1970+
1971+
gemfile <<~G
1972+
source "https://main.source"
1973+
1974+
gem "activesupport"
1975+
1976+
source "https://main.source/extra" do
1977+
gem "foo"
1978+
end
1979+
G
1980+
1981+
lockfile original_lockfile
1982+
end
1983+
1984+
it "properly upgrades the lockfile when updating that specific gem" do
1985+
bundle "update bigdecimal --conservative", artifice: "compact_index_extra_api", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo3.to_s }
1986+
1987+
expect(lockfile).to eq original_lockfile.gsub("bigdecimal (1.0.0)", "bigdecimal (3.3.1)")
1988+
end
1989+
end
19241990
end

0 commit comments

Comments
 (0)