summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/resolver.rb17
-rw-r--r--spec/bundler/commands/lock_spec.rb39
2 files changed, 49 insertions, 7 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 82cf66cc6d..b654cb819d 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -118,13 +118,13 @@ module Bundler
name = package.name
constraint = unsatisfied_term.constraint
constraint_string = constraint.constraint_string
- requirement = Gem::Requirement.new(constraint_string.split(","))
+ requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) }
if name == "bundler"
custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}"
- extended_explanation = bundler_not_found_message(requirement)
+ extended_explanation = bundler_not_found_message(requirements)
else
- specs_matching_other_platforms = filter_matching_specs(@all_specs[name], requirement)
+ specs_matching_other_platforms = filter_matching_specs(@all_specs[name], requirements)
platforms_explanation = specs_matching_other_platforms.any? ? " for any resolution platforms (#{package.platforms.join(", ")})" : ""
custom_explanation = "#{constraint} could not be found in #{repository_for(package)}#{platforms_explanation}"
@@ -265,8 +265,10 @@ module Bundler
private
- def filter_matching_specs(specs, requirement)
- specs.select {| spec| requirement_satisfied_by?(requirement, spec) }
+ def filter_matching_specs(specs, requirements)
+ Array(requirements).flat_map do |requirement|
+ specs.select {| spec| requirement_satisfied_by?(requirement, spec) }
+ end
end
def requirement_satisfied_by?(requirement, spec)
@@ -357,8 +359,9 @@ module Bundler
end
end
- def bundler_not_found_message(conflict_dependency)
- candidate_specs = filter_matching_specs(source_for(:default_bundler).specs.search("bundler"), conflict_dependency)
+ def bundler_not_found_message(conflict_dependencies)
+ candidate_specs = filter_matching_specs(source_for(:default_bundler).specs.search("bundler"), conflict_dependencies)
+
if candidate_specs.any?
target_version = candidate_specs.last.version
new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ")
diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb
index 431e0c2260..ed0c3dfadf 100644
--- a/spec/bundler/commands/lock_spec.rb
+++ b/spec/bundler/commands/lock_spec.rb
@@ -713,5 +713,44 @@ RSpec.describe "bundle lock" do
#{Bundler::VERSION}
L
end
+
+ it "properly shows resolution errors including OR requirements" do
+ build_repo4 do
+ build_gem "activeadmin", "2.13.1" do |s|
+ s.add_dependency "railties", ">= 6.1", "< 7.1"
+ end
+ build_gem "actionpack", "6.1.4"
+ build_gem "actionpack", "7.0.3.1"
+ build_gem "actionpack", "7.0.4"
+ build_gem "railties", "6.1.4" do |s|
+ s.add_dependency "actionpack", "6.1.4"
+ end
+ build_gem "rails", "7.0.3.1" do |s|
+ s.add_dependency "railties", "7.0.3.1"
+ end
+ build_gem "rails", "7.0.4" do |s|
+ s.add_dependency "railties", "7.0.4"
+ end
+ end
+
+ gemfile <<~G
+ source "#{file_uri_for(gem_repo4)}"
+
+ gem "rails", ">= 7.0.3.1"
+ gem "activeadmin", "2.13.1"
+ G
+
+ bundle "lock", :raise_on_error => false
+
+ expect(err).to eq <<~ERR.strip
+ Could not find compatible versions
+
+ Because rails >= 7.0.4 depends on railties = 7.0.4
+ and rails < 7.0.4 depends on railties = 7.0.3.1,
+ railties = 7.0.3.1 OR = 7.0.4 is required.
+ So, because railties = 7.0.3.1 OR = 7.0.4 could not be found in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally,
+ version solving has failed.
+ ERR
+ end
end
end