From d979b8bbb00281e62c0c089c65d4f9de98537652 Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Sat, 2 May 2015 01:42:35 -0700 Subject: Warn when upgrading lockfile major version & error when major version is too low --- lib/bundler/definition.rb | 8 ++++++++ lib/bundler/lockfile_parser.rb | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index d8aab4fbb4..edaf54a6bf 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -249,6 +249,14 @@ module Bundler return end + locked_major = @locked_bundler_version.segments.first + current_major = Gem::Version.create(Bundler::VERSION).segments.first + + if locked_major < current_major + Bundler.ui.warn "Warning: the lockfile is being updated to Bundler #{Bundler::VERSION.split('.').first}, " \ + "after which you will be unable to return to Bundler #{@locked_bundler_version.segments.first}." + end + File.open(file, 'wb'){|f| f.puts(contents) } rescue Errno::EACCES raise Bundler::InstallError, diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index dcd966b9d8..1c241b7a5a 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -60,11 +60,18 @@ module Bundler def warn_for_outdated_bundler_version return unless bundler_version prerelease_text = bundler_version.prerelease? ? " --pre" : "" - if Gem::Version.new(Bundler::VERSION) < Gem::Version.new(bundler_version) - Bundler.ui.warn "Warning: the running version of Bundler is older " \ - "than the version that created the lockfile. We suggest you " \ - "upgrade to the latest version of Bundler by running `gem " \ - "install bundler#{prerelease_text}`.\n" + locked_version = Gem::Version.create(bundler_version) + current_version = Gem::Version.create(Bundler::VERSION) + case current_version.segments.first <=> locked_version.segments.first + when -1 + raise LockfileError, "You must use Bundler #{locked_version.segments.first} or greater with this lockfile." + when 0 + if current_version < locked_version + Bundler.ui.warn "Warning: the running version of Bundler is older " \ + "than the version that created the lockfile. We suggest you " \ + "upgrade to the latest version of Bundler by running `gem " \ + "install bundler#{prerelease_text}`.\n" + end end end -- cgit v1.2.1