summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-01-14 18:48:21 -0600
committerSamuel Giddins <segiddins@segiddins.me>2017-01-14 18:48:21 -0600
commit1e05d24050b4177e9a8001b7c1083d713b474faf (patch)
treef63296b3fc9bfb10006aa14cf7d066739b6de38a
parent3f0075896a60ba1771913fc1118ecc9b91db98bb (diff)
downloadbundler-1e05d24050b4177e9a8001b7c1083d713b474faf.tar.gz
[CLI] Warn when running an outdated bundler version
-rw-r--r--lib/bundler/cli.rb22
-rw-r--r--lib/bundler/settings.rb3
-rw-r--r--man/bundle-config.ronn3
-rw-r--r--spec/bundler/cli_spec.rb63
4 files changed, 90 insertions, 1 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index eb9362a500..a70d66f200 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -13,6 +13,7 @@ module Bundler
Bundler.ui = UI::Shell.new
raise e
ensure
+ warn_on_outdated_bundler
Bundler::SharedHelpers.print_major_deprecations!
end
@@ -579,5 +580,26 @@ module Bundler
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 35ad17ae43..b2136384ca 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -11,6 +11,8 @@ module Bundler
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 @@ module Bundler
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 fd15a24288..85fe3dd27b 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 ac704fb41d..4960d78e48 100644
--- a/spec/bundler/cli_spec.rb
+++ b/spec/bundler/cli_spec.rb
@@ -61,6 +61,69 @@ describe "bundle executable" do
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