Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
[CLI] Warn when running an outdated bundler version
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 15, 2017
1 parent 3f00758 commit 1e05d24
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ class Settings
disable_exec_load
disable_local_branch_check
disable_shared_gems
disable_version_check
force_ruby_platform
frozen
gem.coc
gem.mit
ignore_messages
major_deprecations
no_install
no_prune
force_ruby_platform
only_update_to_newer_versions
plugins
silence_root_warning
Expand Down
3 changes: 3 additions & 0 deletions man/bundle-config.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
63 changes: 63 additions & 0 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e05d24

Please sign in to comment.