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

Commit

Permalink
Merge #6996
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Apr 27, 2019
2 parents 29d856f + 7ca4364 commit 12a7da4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 147 deletions.
16 changes: 5 additions & 11 deletions lib/bundler/lockfile_parser.rb
Expand Up @@ -101,17 +101,11 @@ def warn_for_outdated_bundler_version
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
Expand Down
177 changes: 42 additions & 135 deletions spec/lock/lockfile_spec.rb
Expand Up @@ -154,35 +154,37 @@
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}/
specs:
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
Expand All @@ -192,18 +194,20 @@
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}/
Expand All @@ -217,7 +221,7 @@
rack
BUNDLED WITH
9999999.0.0
#{older_major}
L

install_gemfile <<-G
Expand All @@ -226,76 +230,9 @@
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
Expand All @@ -304,63 +241,15 @@
specs:
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
Expand Down Expand Up @@ -1582,4 +1471,22 @@ def set_lockfile_mtime_to_known_value
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
2 changes: 1 addition & 1 deletion spec/support/platforms.rb
Expand Up @@ -105,7 +105,7 @@ def lockfile_platforms
end

def local_platforms
if Bundler::VERSION.split(".").first.to_i > 2
if Bundler.feature_flag.specific_platform?
[local, specific_local_platform]
else
[local]
Expand Down

0 comments on commit 12a7da4

Please sign in to comment.