diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index eb9362a5004..a70d66f2009 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -13,6 +13,7 @@ def self.start(*) Bundler.ui = UI::Shell.new raise e ensure + warn_on_outdated_bundler Bundler::SharedHelpers.print_major_deprecations! end @@ -579,5 +580,26 @@ def print_command command.reject!(&:empty?) Bundler.ui.info "Running `#{command * " "}` with bundler #{Bundler::VERSION}" end + + def self.warn_on_outdated_bundler + return if Bundler.settings[:disable_version_check] + + latest = Fetcher::CompactIndex. + new(nil, Source::Rubygems::Remote.new(URI("https://rubygems.org")), nil). + send(:compact_index_client). + instance_variable_get(:@cache). + dependencies("bundler"). + map {|d| Gem::Version.new(d.first) }. + max + return unless latest + + current = Gem::Version.new(VERSION) + return if current >= latest + + Bundler.ui.warn "The latest bundler is #{latest}, but you are currently running #{current}.\nTo update, run `gem install bundler#{" --pre" if latest.prerelease?}`" + rescue + nil + end + private_class_method :warn_on_outdated_bundler end end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 35ad17ae435..b2136384ca3 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -11,6 +11,8 @@ class Settings disable_exec_load disable_local_branch_check disable_shared_gems + disable_version_check + force_ruby_platform frozen gem.coc gem.mit @@ -18,7 +20,6 @@ class Settings major_deprecations no_install no_prune - force_ruby_platform only_update_to_newer_versions plugins silence_root_warning diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index fd15a24288a..85fe3dd27b2 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -169,6 +169,9 @@ learn more about their operation in [bundle install(1)][bundle-install]. * `disable_checksum_validation` (`BUNDLE_DISABLE_CHECKSUM_VALIDATION`): Allow installing gems even if they do not match the checksum provided by RubyGems. +* `disable_version_check` (`BUNDLE_DISABLE_VERSION_CHECK`): + Stop Bundler from checking if a newer Bundler version is available on + rubygems.org. In general, you should set these settings per-application by using the applicable flag to the [bundle install(1)][bundle-install] or [bundle package(1)][bundle-package] command. diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index ac704fb41d2..4960d78e484 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -61,6 +61,69 @@ expect(out).to start_with("Running `bundle config --verbose` with bundler #{Bundler::VERSION}") end end + + describe "printing the outdated warning" do + shared_examples_for "no warning" do + it "prints no warning" do + bundle "fail" + expect(err + out).to eq("Could not find command \"fail\".") + end + end + + let(:bundler_version) { "1.1" } + let(:latest_version) { nil } + before do + simulate_bundler_version(bundler_version) + if latest_version + info_path = home(".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/bundler") + info_path.parent.mkpath + info_path.open("w") {|f| f.write "#{latest_version}\n" } + end + end + + context "when there is no latest version" do + include_examples "no warning" + end + + context "when the latest version is equal to the current version" do + let(:latest_version) { bundler_version } + include_examples "no warning" + end + + context "when the latest version is less than the current version" do + let(:latest_version) { "0.9" } + include_examples "no warning" + end + + context "when the latest version is greater than the current version" do + let(:latest_version) { "2.0" } + it "prints the version warning" do + bundle "fail" + expect(err + out).to eq(<<-EOS.strip) +The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. +To update, run `gem install bundler` +Could not find command "fail". + EOS + end + + context "and disable_version_check is set" do + before { bundle! "config disable_version_check true" } + include_examples "no warning" + end + + context "and is a pre-release" do + let(:latest_version) { "2.0.0.pre.4" } + it "prints the version warning" do + bundle "fail" + expect(err + out).to eq(<<-EOS.strip) +The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. +To update, run `gem install bundler --pre` +Could not find command "fail". + EOS + end + end + end + end end describe "bundler executable" do