summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-06-01 21:26:30 +0000
committerSamuel Giddins <segiddins@segiddins.me>2017-06-01 23:55:32 -0500
commitf3271845acd8b6d135d5957a70d539fe3a1f6635 (patch)
treeb07b812694f56aebd77c004b1ac01e89e78e37b4
parent388fde46c180c4e2b569329c9b962dea4ccc8671 (diff)
downloadbundler-f3271845acd8b6d135d5957a70d539fe3a1f6635.tar.gz
Auto merge of #5694 - bundler:seg-lock-update-missing, r=colby-swandale
[CLI::Lock] Fail gracefully when updating a missing gem Closes #5693 by behaving the same way `bundle update` handles gems that aren't in the lockfile (cherry picked from commit 2e46e6705770e5a4685b1f3d3fbbe60f957599ae)
-rw-r--r--lib/bundler/cli/common.rb7
-rw-r--r--lib/bundler/cli/lock.rb5
-rw-r--r--lib/bundler/cli/update.rb7
-rw-r--r--spec/commands/lock_spec.rb9
4 files changed, 21 insertions, 7 deletions
diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb
index c1e108d752..bacbb2edc5 100644
--- a/lib/bundler/cli/common.rb
+++ b/lib/bundler/cli/common.rb
@@ -70,6 +70,13 @@ module Bundler
message
end
+ def self.ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems)
+ locked_names = locked_gems.specs.map(&:name)
+ names.-(locked_names).each do |g|
+ raise GemNotFound, gem_not_found_message(g, locked_names)
+ end
+ end
+
def self.configure_gem_version_promoter(definition, options)
patch_level = patch_level_options(options)
raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1
diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb
index beeb2e4633..223db9419f 100644
--- a/lib/bundler/cli/lock.rb
+++ b/lib/bundler/cli/lock.rb
@@ -22,7 +22,10 @@ module Bundler
Bundler::Fetcher.disable_endpoint = options["full-index"]
update = options[:update]
- update = { :gems => update, :lock_shared_dependencies => options[:conservative] } if update.is_a?(Array)
+ if update.is_a?(Array) # unlocking specific gems
+ Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update)
+ update = { :gems => update, :lock_shared_dependencies => options[:conservative] }
+ end
definition = Bundler.definition(update)
Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) if options[:update]
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb
index 8a7541c259..df7524f004 100644
--- a/lib/bundler/cli/update.rb
+++ b/lib/bundler/cli/update.rb
@@ -25,12 +25,7 @@ module Bundler
raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
"Run `bundle install` to update and install the bundled gems."
end
- # cycle through the requested gems, to make sure they exist
- names = Bundler.locked_gems.specs.map(&:name)
- gems.each do |g|
- next if names.include?(g)
- raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(g, names)
- end
+ Bundler::CLI::Common.ensure_all_gems_in_lockfile!(gems)
if groups.any?
specs = Bundler.definition.specs_for groups
diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb
index 52c281a6ae..5c15b6a7f6 100644
--- a/spec/commands/lock_spec.rb
+++ b/spec/commands/lock_spec.rb
@@ -106,6 +106,15 @@ RSpec.describe "bundle lock" do
expect(read_lockfile).to eq(@lockfile)
end
+ it "errors when updating a missing specific gems using --update" do
+ lockfile @lockfile
+
+ bundle "lock --update blahblah"
+ expect(out).to eq("Could not find gem 'blahblah'.")
+
+ expect(read_lockfile).to eq(@lockfile)
+ end
+
# see update_spec for more coverage on same options. logic is shared so it's not necessary
# to repeat coverage here.
context "conservative updates" do