diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 3bdd2c5e201..bc29f17b51d 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -103,7 +103,7 @@ def warn_for_outdated_bundler_version current_version = Gem::Version.create(Bundler::VERSION) current_major_version = current_version.segments.first major_bundler_version = bundler_version.segments.first - if current_major_version < major_bundler_version + if current_major_version < major_bundler_version && current_major_version > 2 raise LockfileError, "You must use Bundler #{major_bundler_version} or greater with this lockfile." end return unless current_version < bundler_version diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index af47502227f..0721f83077f 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -204,7 +204,57 @@ G end - it "errors if the current major version is older than lockfile's major version" do + it "warns if the current major version is older than lockfile's major version", :bundler => "< 3" do + current_version = Bundler::VERSION + newer_major = bump_major(current_version) + + lockfile <<-L + GEM + remote: file://localhost#{gem_repo1}/ + specs: + rack (1.0.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + #{newer_major} + L + + install_gemfile <<-G + source "file://localhost#{gem_repo1}" + + gem "rack" + G + + pre_flag = prerelease?(newer_major) ? " --pre" : "" + warning_message = "the running version of Bundler (#{current_version}) is older " \ + "than the version that created the lockfile (#{newer_major}). " \ + "We suggest you to upgrade to the version that created the " \ + "lockfile by running `gem install bundler:#{newer_major}#{pre_flag}`." + expect(last_command.stderr).to include warning_message + + lockfile_should_be <<-G + GEM + remote: file://localhost#{gem_repo1}/ + specs: + rack (1.0.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + #{newer_major} + G + end + + it "errors if the current major version is older than lockfile's bundler version", :bundler => "3" do current_version = Bundler::VERSION newer_major = bump_major(current_version)