Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit d07da81

Browse files
committed
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.
1 parent e0ee155 commit d07da81

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bugfixes:
1111
- prioritise explicitly requested gems in dependency resolution sort order (@segiddins)
1212
- reduce memory usage during dependency resolution ([#6114](https://github.com/bundler/bundler/issues/6114), @greysteil)
1313
- ensure that the default bundler gem is not accidentally activated on ruby 2.5 when using local git overrides (@segiddins)
14+
- fix `NoMethodError` when using the `--group` option with `bundle update` ([#6156](https://github.com/bundler/bundler/issues/6156), @mattbrictson)
1415

1516
## 1.16.0.pre.3 (2017-10-04)
1617

lib/bundler/cli/update.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def run
6868

6969
if locked_gems = Bundler.definition.locked_gems
7070
gems.each do |name|
71-
locked_version = locked_gems.specs.find {|s| s.name == name }.version
71+
locked_version = locked_gems.specs.find {|s| s.name == name }
72+
locked_version &&= locked_version.version
73+
next unless locked_version
7274
new_version = Bundler.definition.specs[name].first
7375
new_version &&= new_version.version
7476
if !new_version

spec/commands/update_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@
195195
expect(the_bundle).not_to include_gems "foo 2.0"
196196
end
197197
end
198+
199+
context "when bundler itself is a transitive dependency" do
200+
it "executes without error" do
201+
install_gemfile <<-G
202+
source "file://#{gem_repo1}"
203+
gem "activesupport", :group => :development
204+
gem "rack"
205+
G
206+
update_repo2 do
207+
build_gem "activesupport", "3.0"
208+
end
209+
bundle "update --group development"
210+
expect(the_bundle).to include_gems "activesupport 2.3.5"
211+
expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}"
212+
expect(the_bundle).not_to include_gems "rack 1.2"
213+
end
214+
end
198215
end
199216

200217
describe "in a frozen bundle" do

0 commit comments

Comments
 (0)