diff options
author | Allen Zhao <cnallenzhao@gmail.com> | 2016-05-23 19:21:23 +0800 |
---|---|---|
committer | Allen Zhao <cnallenzhao@gmail.com> | 2016-05-24 09:31:53 +0800 |
commit | 5f1ec1113108428427c513299d610b844195578e (patch) | |
tree | e0b31a08063bc35f4f74d5963f871fa001a718e8 /lib | |
parent | 8268b7ca58eb868afa4bffdcc62f0a1ec72d2478 (diff) | |
download | bundler-5f1ec1113108428427c513299d610b844195578e.tar.gz |
Handle yanked gems
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/definition.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 294d6567c6..a46f805378 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -137,8 +137,17 @@ module Bundler # @return [Bundler::SpecSet] def specs @specs ||= begin - specs = resolve.materialize(Bundler.settings[:cache_all_platforms] ? dependencies : requested_dependencies) - + begin + specs = resolve.materialize(Bundler.settings[:cache_all_platforms] ? dependencies : requested_dependencies) + rescue GemNotFound => e # Handle yanked gem + gem_name, gem_version = extract_gem_info(e) + locked_gem = @locked_specs[gem_name].last + raise if locked_gem.nil? || locked_gem.version.to_s != gem_version + raise GemNotFound, "Your bundle is locked to #{locked_gem}, but that version could not " \ + "be found in any of the sources listed in your Gemfile. If you haven't changed sources, " \ + "that means the author of #{locked_gem} has removed it. You'll need to update your bundle " \ + "to a different version of foo that hasn't been removed in order to install." + end unless specs["bundler"].any? local = Bundler.settings[:frozen] ? rubygems_index : index bundler = local.search(Gem::Dependency.new("bundler", VERSION)).last @@ -690,5 +699,11 @@ module Bundler end current == proposed end + + def extract_gem_info(error) + # This method will extract the error message like "Could not find foo-1.2.3 in any of the sources" + # to an array. The first element will be the gem name (e.g. foo), the second will be the version number. + error.message.scan(/Could not find (\w+)-(\d+(?:\.\d+)+)/).flatten + end end end |