summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-04-27 18:12:57 +0000
committerBundlerbot <bot@bundler.io>2019-04-27 18:12:57 +0000
commit12a7da4ab73992a975493d47154b1bff9a3d287d (patch)
treea31bfe59ce7c1ccc7a5a033d93e843cffc97e91e
parent29d856f40b6b5cdbac7ef060dd0a0137e35ba0ac (diff)
parent7ca436404ca129d7c57cf2427f66a7ae0f7b90e5 (diff)
downloadbundler-12a7da4ab73992a975493d47154b1bff9a3d287d.tar.gz
Merge #6996
6996: Downgrade version mismatches to warnings r=indirect a=deivid-rodriguez Closes #6993. Complements rubygems/rubygems#2621. ### What was the end-user problem that led to this PR? The problem was that bundler 2 has become too unfriendly because it errors out when the running version does not match the version in the BUNDLED WITH section in the lockfile. ### What was your diagnosis of the problem? My diagnosis is that we still believe that making sure the exact same bundler version is always run for a specific application is a good thing, because it ensures resolution is always the same because it's resolved by the exact same code that generated the lockfile. BUT, we need to ensure this in a more user friendly way, for example by auto-switching and auto-installing the right bundler version without any user intervention. ### What is your fix for the problem, implemented in this PR? My fix is to downgrade this hard error to a warning that does not prevent bundler from running. ### Why did you choose this fix out of the possible options? I chose this fix because it still shows the mismatch but allows bundler to run, thus being a bit friendlier. Hopefully this won't be needed once bundler is smart enough to autoswitch and autoinstall. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--lib/bundler/lockfile_parser.rb16
-rw-r--r--spec/lock/lockfile_spec.rb177
-rw-r--r--spec/support/platforms.rb2
3 files changed, 48 insertions, 147 deletions
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index 50dc1381fe..5658ec1205 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -101,17 +101,11 @@ module Bundler
return unless bundler_version
prerelease_text = bundler_version.prerelease? ? " --pre" : ""
current_version = Gem::Version.create(Bundler::VERSION)
- case current_version.segments.first <=> bundler_version.segments.first
- when -1
- raise LockfileError, "You must use Bundler #{bundler_version.segments.first} or greater with this lockfile."
- when 0
- if current_version < bundler_version
- Bundler.ui.warn "Warning: the running version of Bundler (#{current_version}) is older " \
- "than the version that created the lockfile (#{bundler_version}). We suggest you to " \
- "upgrade to the version that created the lockfile by running `gem install " \
- "bundler:#{bundler_version}#{prerelease_text}`.\n"
- end
- end
+ return unless current_version < bundler_version
+ Bundler.ui.warn "Warning: the running version of Bundler (#{current_version}) is older " \
+ "than the version that created the lockfile (#{bundler_version}). We suggest you to " \
+ "upgrade to the version that created the lockfile by running `gem install " \
+ "bundler:#{bundler_version}#{prerelease_text}`.\n"
end
private
diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb
index 0842a94fc5..c2d44e5cf1 100644
--- a/spec/lock/lockfile_spec.rb
+++ b/spec/lock/lockfile_spec.rb
@@ -154,7 +154,10 @@ RSpec.describe "the lockfile format" do
G
end
- it "outputs a warning if the current is older than lockfile's bundler version" do
+ it "warns if the current is older than lockfile's bundler version" do
+ current_version = Bundler::VERSION
+ newer_minor = bump_minor(current_version)
+
lockfile <<-L
GEM
remote: file://localhost#{gem_repo1}/
@@ -162,27 +165,26 @@ RSpec.describe "the lockfile format" do
rack (1.0.0)
PLATFORMS
- #{generic_local_platform}
+ #{lockfile_platforms}
DEPENDENCIES
rack
BUNDLED WITH
- 9999999.1.0
+ #{newer_minor}
L
- simulate_bundler_version "9999999.0.0" do
- install_gemfile <<-G
- source "file://localhost#{gem_repo1}"
+ install_gemfile <<-G
+ source "file://localhost#{gem_repo1}"
- gem "rack"
- G
- end
+ gem "rack"
+ G
- warning_message = "the running version of Bundler (9999999.0.0) is older " \
- "than the version that created the lockfile (9999999.1.0). " \
+ pre_flag = prerelease?(newer_minor) ? " --pre" : ""
+ warning_message = "the running version of Bundler (#{current_version}) is older " \
+ "than the version that created the lockfile (#{newer_minor}). " \
"We suggest you to upgrade to the version that created the " \
- "lockfile by running `gem install bundler:9999999.1.0`."
+ "lockfile by running `gem install bundler:#{newer_minor}#{pre_flag}`."
expect(err).to include warning_message
lockfile_should_be <<-G
@@ -192,18 +194,20 @@ RSpec.describe "the lockfile format" do
rack (1.0.0)
PLATFORMS
- #{generic_local_platform}
- #{specific_local_platform}
+ #{lockfile_platforms}
DEPENDENCIES
rack
BUNDLED WITH
- 9999999.1.0
+ #{newer_minor}
G
end
- it "errors if the current is a major version older than lockfile's bundler version", :bundler => "3" do
+ it "warns when updating bundler major version" do
+ current_version = Bundler::VERSION
+ older_major = previous_major(current_version)
+
lockfile <<-L
GEM
remote: file://localhost#{gem_repo1}/
@@ -217,7 +221,7 @@ RSpec.describe "the lockfile format" do
rack
BUNDLED WITH
- 9999999.0.0
+ #{older_major}
L
install_gemfile <<-G
@@ -226,76 +230,9 @@ RSpec.describe "the lockfile format" do
gem "rack"
G
- expect(last_command).to be_failure
- expect(err).to include("You must use Bundler 9999999 or greater with this lockfile.")
- end
-
- it "shows a friendly error when running with a new bundler 2 lockfile" do
- lockfile <<-L
- GEM
- remote: https://rails-assets.org/
- specs:
- rails-assets-bootstrap (3.3.4)
- rails-assets-jquery (>= 1.9.1)
- rails-assets-jquery (2.1.4)
-
- GEM
- remote: https://rubygems.org/
- specs:
- rake (10.4.2)
-
- PLATFORMS
- ruby
-
- DEPENDENCIES
- rails-assets-bootstrap!
- rake
-
- BUNDLED WITH
- 9999999.0.0
- L
-
- install_gemfile <<-G
- source 'https://rubygems.org'
- gem 'rake'
-
- source 'https://rails-assets.org' do
- gem 'rails-assets-bootstrap'
- end
- G
-
- expect(last_command).to be_failure
- expect(err).to include("You must use Bundler 9999999 or greater with this lockfile.")
- end
-
- it "warns when updating bundler major version", :bundler => "< 3" do
- lockfile <<-L
- GEM
- remote: file://localhost#{gem_repo1}/
- specs:
- rack (1.0.0)
-
- PLATFORMS
- #{generic_local_platform}
-
- DEPENDENCIES
- rack
-
- BUNDLED WITH
- 1.10.0
- L
-
- simulate_bundler_version "9999999.0.0" do
- install_gemfile <<-G
- source "file://localhost#{gem_repo1}/"
-
- gem "rack"
- G
- end
-
expect(err).to include(
"Warning: the lockfile is being updated to Bundler " \
- "9999999, after which you will be unable to return to Bundler 1."
+ "#{current_version.split(".").first}, after which you will be unable to return to Bundler #{older_major.split(".").first}."
)
lockfile_should_be <<-G
@@ -305,62 +242,14 @@ RSpec.describe "the lockfile format" do
rack (1.0.0)
PLATFORMS
- #{generic_local_platform}
- #{specific_local_platform}
-
- DEPENDENCIES
- rack
-
- BUNDLED WITH
- 9999999.0.0
- G
- end
-
- it "warns when updating bundler major version", :bundler => "3" do
- lockfile <<-L
- GEM
- remote: file://localhost#{gem_repo1}/
- specs:
- rack (1.0.0)
-
- PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
rack
BUNDLED WITH
- 1.10.0
- L
-
- simulate_bundler_version "9999999.0.0" do
- install_gemfile <<-G
- source "file://localhost#{gem_repo1}/"
-
- gem "rack"
- G
-
- expect(err).to include(
- "Warning: the lockfile is being updated to Bundler " \
- "9999999, after which you will be unable to return to Bundler 1."
- )
-
- lockfile_should_be <<-G
- GEM
- remote: file://localhost#{gem_repo1}/
- specs:
- rack (1.0.0)
-
- PLATFORMS
- #{lockfile_platforms}
-
- DEPENDENCIES
- rack
-
- BUNDLED WITH
- 9999999.0.0
- G
- end
+ #{current_version}
+ G
end
it "generates a simple lockfile for a single source, gem with dependencies" do
@@ -1582,4 +1471,22 @@ RSpec.describe "the lockfile format" do
expect(err).to match(/your Gemfile.lock contains merge conflicts/i)
expect(err).to match(/git checkout HEAD -- Gemfile.lock/i)
end
+
+private
+
+ def prerelease?(version)
+ Gem::Version.new(version).prerelease?
+ end
+
+ def previous_major(version)
+ version.split(".").map.with_index {|v, i| i == 0 ? v.to_i - 1 : v }.join(".")
+ end
+
+ def bump_minor(version)
+ bump(version, 1)
+ end
+
+ def bump(version, segment)
+ version.split(".").map.with_index {|v, i| i == segment ? v.to_i + 1 : v }.join(".")
+ end
end
diff --git a/spec/support/platforms.rb b/spec/support/platforms.rb
index 0a9e4a8cb6..caac7734bf 100644
--- a/spec/support/platforms.rb
+++ b/spec/support/platforms.rb
@@ -105,7 +105,7 @@ module Spec
end
def local_platforms
- if Bundler::VERSION.split(".").first.to_i > 2
+ if Bundler.feature_flag.specific_platform?
[local, specific_local_platform]
else
[local]