From cd693cc4c0e8d95eac1f69db5b8709eb98f21071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 11 Feb 2019 17:45:25 +0100 Subject: [PATCH 1/7] Remove case so it's easier to understand --- lib/bundler/lockfile_parser.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 50dc1381fec..8706b881c1a 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -101,17 +101,14 @@ 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 + if current_version.segments.first < bundler_version.segments.first 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 From f0ae5ebb1572177f76dbb751b241890e0e00b9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 10:23:47 +0200 Subject: [PATCH 2/7] Remove duplicated spec This is essentially the same as "errors if the current is a major version older than lockfile's bundler version". --- spec/lock/lockfile_spec.rb | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 0842a94fc5e..41c4f7d6e56 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -230,44 +230,6 @@ 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 From 1113640bcc4e6c8849e5d124015d4d9c69b1a3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 12:50:21 +0200 Subject: [PATCH 3/7] Merge unnecessarily split specs --- spec/lock/lockfile_spec.rb | 50 +------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 41c4f7d6e56..ed310c48a54 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -230,7 +230,7 @@ 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 + it "warns when updating bundler major version" do lockfile <<-L GEM remote: file://localhost#{gem_repo1}/ @@ -247,54 +247,6 @@ 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." - ) - - lockfile_should_be <<-G - GEM - remote: file://localhost#{gem_repo1}/ - 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}/" From e1d534ae6f749d2ef976ea77d787914681be2b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 26 Apr 2019 20:00:45 +0200 Subject: [PATCH 4/7] Remove hard errors on version mismatches This is already short-circuit by rubygems' bundler version finder. --- lib/bundler/lockfile_parser.rb | 3 --- spec/lock/lockfile_spec.rb | 27 --------------------------- 2 files changed, 30 deletions(-) diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 8706b881c1a..5658ec12050 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -101,9 +101,6 @@ def warn_for_outdated_bundler_version return unless bundler_version prerelease_text = bundler_version.prerelease? ? " --pre" : "" current_version = Gem::Version.create(Bundler::VERSION) - if current_version.segments.first < bundler_version.segments.first - raise LockfileError, "You must use Bundler #{bundler_version.segments.first} or greater with this lockfile." - 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 " \ diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index ed310c48a54..e71050ec0c9 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -203,33 +203,6 @@ G end - it "errors if the current is a major version older than lockfile's bundler version", :bundler => "3" do - lockfile <<-L - GEM - remote: file://localhost#{gem_repo1}/ - specs: - rack (1.0.0) - - PLATFORMS - #{lockfile_platforms} - - DEPENDENCIES - rack - - BUNDLED WITH - 9999999.0.0 - L - - install_gemfile <<-G - source "file://localhost#{gem_repo1}/" - - 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 "warns when updating bundler major version" do lockfile <<-L GEM From 6cd8bc381d483d84fc879f8a469b7a8b03d05acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 12:49:45 +0200 Subject: [PATCH 5/7] Remove `simulate_bundler_version` from lockfile specs The simulation is not very friendly because it needs to happen before `hax.rb` is loaded so, for example, it won't be applied to the lockfile platforms. --- spec/lock/lockfile_spec.rb | 96 +++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index e71050ec0c9..b2f3336871f 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -155,6 +155,9 @@ end it "outputs a warning 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 @@ 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 @@ 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 "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}/ @@ -211,43 +215,41 @@ rack (1.0.0) PLATFORMS - #{generic_local_platform} + #{lockfile_platforms} DEPENDENCIES rack BUNDLED WITH - 1.10.0 + #{older_major} 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 + 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." - ) + expect(err).to include( + "Warning: the lockfile is being updated to Bundler " \ + "#{current_version.split(".").first}, after which you will be unable to return to Bundler #{older_major.split(".").first}." + ) - lockfile_should_be <<-G - GEM - remote: file://localhost#{gem_repo1}/ - specs: - rack (1.0.0) + lockfile_should_be <<-G + GEM + remote: file://localhost#{gem_repo1}/ + specs: + rack (1.0.0) - PLATFORMS - #{lockfile_platforms} + PLATFORMS + #{lockfile_platforms} - DEPENDENCIES - rack + DEPENDENCIES + rack - BUNDLED WITH - 9999999.0.0 - G - end + BUNDLED WITH + #{current_version} + G end it "generates a simple lockfile for a single source, gem with dependencies" do @@ -1469,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 From 0138db17453ab599a00eda9e73b4cc9ea9768d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 14:00:50 +0200 Subject: [PATCH 6/7] Check for feature flag instead of hard version --- spec/support/platforms.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/platforms.rb b/spec/support/platforms.rb index 0a9e4a8cb65..caac7734bf0 100644 --- a/spec/support/platforms.rb +++ b/spec/support/platforms.rb @@ -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] From 7ca436404ca129d7c57cf2427f66a7ae0f7b90e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 12:42:33 +0200 Subject: [PATCH 7/7] Slight rewording for consistency with other specs --- spec/lock/lockfile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index b2f3336871f..c2d44e5cf1d 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -154,7 +154,7 @@ 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)