ruby-changes:66813
From: David <ko1@a...>
Date: Fri, 16 Jul 2021 15:40:27 +0900 (JST)
Subject: [ruby-changes:66813] 227c2deff4 (master): [rubygems/rubygems] Fix development gem unintentionally removed on an edge case
https://git.ruby-lang.org/ruby.git/commit/?id=227c2deff4 From 227c2deff4c4bc7e937020e6d9998f89fa6fdd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Mon, 12 Jul 2021 10:30:16 +0200 Subject: [rubygems/rubygems] Fix development gem unintentionally removed on an edge case When a development dependency was duplicated inside the gemspec and Gemfile with the same requirements, we went from printing a warning to removing the gem altogether. This change makes it not print a warning, but don't remove the gem either. https://github.com/rubygems/rubygems/commit/8bb2488131 --- lib/bundler/dsl.rb | 51 ++++++++++++++++++----------------- spec/bundler/commands/install_spec.rb | 1 + 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 1605210..ac95589 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -102,38 +102,39 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dsl.rb#L102 # if there's already a dependency with this name we try to prefer one if current = @dependencies.find {|d| d.name == dep.name } deleted_dep = @dependencies.delete(current) if current.type == :development - return if deleted_dep - if current.requirement != dep.requirement - return if dep.type == :development + unless deleted_dep + if current.requirement != dep.requirement + return if dep.type == :development - update_prompt = "" + update_prompt = "" - if File.basename(@gemfile) == Injector::INJECTED_GEMS - if dep.requirements_list.include?(">= 0") && !current.requirements_list.include?(">= 0") - update_prompt = ". Gem already added" - else - update_prompt = ". If you want to update the gem version, run `bundle update #{current.name}`" + if File.basename(@gemfile) == Injector::INJECTED_GEMS + if dep.requirements_list.include?(">= 0") && !current.requirements_list.include?(">= 0") + update_prompt = ". Gem already added" + else + update_prompt = ". If you want to update the gem version, run `bundle update #{current.name}`" - update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current.requirements_list.include?(">= 0") + update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current.requirements_list.include?(">= 0") + end end - end - raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \ - "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ - "#{update_prompt}" - else - Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \ - "You should probably keep only one of them.\n" \ - "Remove any duplicate entries and specify the gem only once.\n" \ - "While it's not a problem now, it could cause errors if you change the version of one of them later." - end + raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \ + "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ + "#{update_prompt}" + else + Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \ + "You should probably keep only one of them.\n" \ + "Remove any duplicate entries and specify the gem only once.\n" \ + "While it's not a problem now, it could cause errors if you change the version of one of them later." + end - if current.source != dep.source - return if dep.type == :development - raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \ - "You specified that #{dep.name} (#{dep.requirement}) should come from " \ - "#{current.source || "an unspecified source"} and #{dep.source}\n" + if current.source != dep.source + return if dep.type == :development + raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \ + "You specified that #{dep.name} (#{dep.requirement}) should come from " \ + "#{current.source || "an unspecified source"} and #{dep.source}\n" + end end end diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 3c0c35d..00a277a 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -388,6 +388,7 @@ RSpec.describe "bundle install with gem sources" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/install_spec.rb#L388 bundle :install expect(err).to be_empty + expect(the_bundle).to include_gems("my-private-gem 1.0") end it "throws an error if a gem is added twice in Gemfile when version of one dependency is not specified" do -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/