diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-12-27 09:41:55 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-12-27 10:45:36 +0900 |
commit | d6311cb1ca5860a6e0cbf6f87c1e0ae9e099f61e (patch) | |
tree | d9bd1de350a80822894e49b48f9d70d764bf7700 /lib/bundler/self_manager.rb | |
parent | b7e5ce08ff0196c1a9ed885670495cf09a02bbc3 (diff) |
Track RubyGems 3.4.0dev and Bundler 2.4.0dev
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5350
Diffstat (limited to 'lib/bundler/self_manager.rb')
-rw-r--r-- | lib/bundler/self_manager.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index d62ef6ca12..2169d814e5 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -15,10 +15,6 @@ module Bundler def install_locked_bundler_and_restart_with_it_if_needed return unless needs_switching? - Bundler.ui.info \ - "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ - "Installing Bundler #{lockfile_version} and restarting using that version." - install_and_restart_with_locked_bundler end @@ -26,8 +22,14 @@ module Bundler def install_and_restart_with_locked_bundler bundler_dep = Gem::Dependency.new("bundler", lockfile_version) + spec = fetch_spec_for(bundler_dep) + return if spec.nil? - Gem.install(bundler_dep) + Bundler.ui.info \ + "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ + "Installing Bundler #{lockfile_version} and restarting using that version." + + spec.source.install(spec) rescue StandardError => e Bundler.ui.trace e Bundler.ui.warn "There was an error installing the locked bundler version (#{lockfile_version}), rerun with the `--verbose` flag for more details. Going on using bundler #{current_version}." @@ -35,6 +37,17 @@ module Bundler restart_with_locked_bundler end + def fetch_spec_for(bundler_dep) + source = Bundler::Source::Rubygems.new("remotes" => "https://rubygems.org") + source.remote! + source.add_dependency_names("bundler") + spec = source.specs.search(bundler_dep).first + if spec.nil? + Bundler.ui.warn "Your lockfile is locked to a version of bundler (#{lockfile_version}) that doesn't exist at https://rubygems.org/. Going on using #{current_version}" + end + spec + end + def restart_with_locked_bundler configured_gem_home = ENV["GEM_HOME"] configured_gem_path = ENV["GEM_PATH"] |