diff options
author | Matt Brictson <matt@mattbrictson.com> | 2017-11-07 12:09:11 -0800 |
---|---|---|
committer | Matt Brictson <matt@mattbrictson.com> | 2017-11-08 07:29:12 -0800 |
commit | d4037909f473cbe6d5b41ba6465b651e6c58a914 (patch) | |
tree | 3c0292e613721d36d56a10f51bb1280a3abf0b27 | |
parent | e0ee155508cc13500f0c3d4aafcd9ee5dd8a49c6 (diff) | |
download | bundler-d4037909f473cbe6d5b41ba6465b651e6c58a914.tar.gz |
Fix NoMethodError during `bundle update --group`
The `bundler` gem does not participate in the lockfile, but it can still
be included in the list of dependencies that are being updated by
`bundle update` if `--group` is specified.
For example, if a Gemfile contains `bundler-audit` (which depends on
`bundler`) in the `:development` group, then updating with the option
`--group=development` will naturally include `bundler` in the list of
gems to evaluate for updating.
The trouble is that since `bundler` is excluded from the lockfile,
searching the locked gems for a gemspec for bundler will return `nil`.
This caused the following error during `bundle update`:
NoMethodError: undefined method `version' for nil:NilClass
This commit solves this bug by skipping over gems (i.e `bundler`) that
are not in the lockfile when comparing gem versions at the conclusion of
the upgrade command.
-rw-r--r-- | lib/bundler/cli/update.rb | 4 | ||||
-rw-r--r-- | spec/commands/update_spec.rb | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index 5de11e84e4..3890ea307a 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -68,7 +68,9 @@ module Bundler if locked_gems = Bundler.definition.locked_gems gems.each do |name| - locked_version = locked_gems.specs.find {|s| s.name == name }.version + locked_version = locked_gems.specs.find {|s| s.name == name } + locked_version &&= locked_version.version + next unless locked_version new_version = Bundler.definition.specs[name].first new_version &&= new_version.version if !new_version diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb index a8283cf593..a2842f0998 100644 --- a/spec/commands/update_spec.rb +++ b/spec/commands/update_spec.rb @@ -195,6 +195,23 @@ RSpec.describe "bundle update" do expect(the_bundle).not_to include_gems "foo 2.0" end end + + context "when bundler itself is a transitive dependency" do + it "executes without error" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "activesupport", :group => :development + gem "rack" + G + update_repo2 do + build_gem "activesupport", "3.0" + end + bundle "update --group development" + expect(the_bundle).to include_gems "activesupport 2.3.5" + expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}" + expect(the_bundle).not_to include_gems "rack 1.2" + end + end end describe "in a frozen bundle" do |