Skip to content

Commit e2f5525

Browse files
Merge pull request #4639 from rubygems/fix_bundle_check_with_scoped_rubygems_sources
Fix `bundle check` with scoped rubygems sources (cherry picked from commit 270f8f9)
1 parent f2b3eb1 commit e2f5525

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

bundler/lib/bundler/cli/check.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def initialize(options)
1111
def run
1212
Bundler.settings.set_command_option_if_given :path, options[:path]
1313

14+
definition = Bundler.definition
15+
definition.validate_runtime!
16+
1417
begin
15-
definition = Bundler.definition
16-
definition.validate_runtime!
18+
definition.resolve_only_locally!
1719
not_installed = definition.missing_specs
1820
rescue GemNotFound, VersionConflict
1921
Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies."

bundler/lib/bundler/definition.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def disable_multisource?
160160
@disable_multisource
161161
end
162162

163+
def resolve_only_locally!
164+
@remote = false
165+
sources.local_only!
166+
resolve
167+
end
168+
163169
def resolve_with_cache!
164170
sources.cached!
165171
resolve

bundler/lib/bundler/source.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def can_lock?(spec)
3636

3737
def local!; end
3838

39+
def local_only!; end
40+
3941
def cached!; end
4042

4143
def remote!; end

bundler/lib/bundler/source/rubygems.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def initialize(options = {})
2626
Array(options["remotes"]).reverse_each {|r| add_remote(r) }
2727
end
2828

29+
def local_only!
30+
@specs = nil
31+
@allow_local = true
32+
@allow_remote = false
33+
end
34+
2935
def local!
3036
return if @allow_local
3137

bundler/lib/bundler/source_list.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def replace_sources!(replacement_sources)
132132
false
133133
end
134134

135+
def local_only!
136+
all_sources.each(&:local_only!)
137+
end
138+
135139
def cached!
136140
all_sources.each(&:cached!)
137141
end

bundler/spec/commands/check_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,66 @@
288288
end
289289
end
290290

291+
describe "when using only scoped rubygems sources" do
292+
before do
293+
gemfile <<~G
294+
source "#{file_uri_for(gem_repo1)}" do
295+
gem "rack"
296+
end
297+
G
298+
end
299+
300+
it "returns success when the Gemfile is satisfied" do
301+
system_gems "rack-1.0.0", :path => default_bundle_path
302+
bundle :check
303+
expect(out).to include("The Gemfile's dependencies are satisfied")
304+
end
305+
end
306+
307+
describe "when using only scoped rubygems sources with indirect dependencies" do
308+
before do
309+
build_repo4 do
310+
build_gem "depends_on_rack" do |s|
311+
s.add_dependency "rack"
312+
end
313+
314+
build_gem "rack"
315+
end
316+
317+
gemfile <<~G
318+
source "#{file_uri_for(gem_repo4)}" do
319+
gem "depends_on_rack"
320+
end
321+
G
322+
end
323+
324+
it "returns success when the Gemfile is satisfied and generates a correct lockfile" do
325+
system_gems "depends_on_rack-1.0", "rack-1.0", :gem_repo => gem_repo4, :path => default_bundle_path
326+
bundle :check
327+
expect(out).to include("The Gemfile's dependencies are satisfied")
328+
expect(lockfile).to eq <<~L
329+
GEM
330+
specs:
331+
332+
GEM
333+
remote: #{file_uri_for(gem_repo4)}/
334+
specs:
335+
depends_on_rack (1.0)
336+
rack
337+
rack (1.0)
338+
339+
PLATFORMS
340+
#{lockfile_platforms}
341+
342+
DEPENDENCIES
343+
depends_on_rack!
344+
345+
BUNDLED WITH
346+
#{Bundler::VERSION}
347+
L
348+
end
349+
end
350+
291351
describe "BUNDLED WITH" do
292352
def lock_with(bundler_version = nil)
293353
lock = <<-L

0 commit comments

Comments
 (0)