diff options
author | Homu <homu@barosl.com> | 2016-02-18 14:20:36 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-02-18 14:20:36 +0900 |
commit | e2603927cd248b9031b3bf255a827fc96ad081e5 (patch) | |
tree | a71dcddb1fd3f2551386b6682375987ad9a83697 | |
parent | ccd627b1f487252d07b9c930418d21c7136ebd59 (diff) | |
parent | b2c3ee86eb21f7f8030c4e4ef3cf5df24b8aef36 (diff) | |
download | bundler-e2603927cd248b9031b3bf255a827fc96ad081e5.tar.gz |
Auto merge of #4309 - RochesterinNYC:fix-bundle-outdated-minor-behavior, r=indirect
Fix `bundle outdated --minor` behavior
If a `Gemfile` is as follows:
```
source 'https://rubygems.org'
gem "activesupport", "2.3.5"
```
and the latest version of `activesupport` is `3.3.5`, running `bundle outdated --minor` should not report any potential updates, which it currently does/would. Users would be using the `--minor` flag potentially because they want to see what latest updates to their gems are available that aren't huge, possibly breaking version changes. With this PR, only if the latest version of `activesupport` is something like `2.5.5` would updates be reported for `activesupport` via `bundle outdated --minor`.
- Related to discussion at bundler/bundler-features#85
-rw-r--r-- | lib/bundler/cli/outdated.rb | 31 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 114 |
2 files changed, 91 insertions, 54 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 1535b2c4bf..d0ae0b46c5 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -56,18 +56,12 @@ module Bundler end active_spec = active_spec.last - if options[:major] - current_major = current_spec.version.segments.first - active_major = active_spec.version.segments.first - active_spec = nil unless active_major > current_major - end - - if options[:minor] - current_minor = current_spec.version.segments[0, 2].compact.join(".") - active_minor = active_spec.version.segments[0, 2].compact.join(".") - active_spec = nil unless active_minor > current_minor + if options[:major] || options[:minor] + update_present = update_present_via_semver_portions(current_spec, active_spec, options) + active_spec = nil unless update_present end end + next if active_spec.nil? gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version) @@ -123,5 +117,22 @@ module Bundler raise ProductionError, error_message end end + + def update_present_via_semver_portions(current_spec, active_spec, options) + current_major = current_spec.version.segments.first + active_major = active_spec.version.segments.first + + update_present = false + + update_present = active_major > current_major if options[:major] + + if options[:minor] && current_major == active_major + current_minor = current_spec.version.segments[1, 1].first + active_minor = active_spec.version.segments[1, 1].first + update_present = active_minor > current_minor + end + + update_present + end end end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index b4895659db..65da3f6ea1 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -219,80 +219,106 @@ describe "bundle outdated" do expect(out).to include("Installing foo 1.0") end - describe "with --major option" do - it "only reports gems that have a newer major version" do - update_repo2 do - build_gem "weakling", "0.2.0" - build_gem "activesupport", "3.0" - end + context "after bundle install --deployment" do + before do + install_gemfile <<-G, :deployment => true + source "file://#{gem_repo2}" - bundle "outdated --major" - expect(out).to_not include("weakling (newest") - expect(out).to include("activesupport (newest") + gem "rack" + gem "foo" + G + end + + it "outputs a helpful message about being in deployment mode" do + update_repo2 { build_gem "activesupport", "3.0" } + + bundle "outdated" + expect(exitstatus).to_not be_zero if exitstatus + expect(out).to include("You are trying to check outdated gems in deployment mode.") + expect(out).to include("Run `bundle outdated` elsewhere.") + expect(out).to include("If this is a development machine, remove the ") + expect(out).to include("Gemfile freeze\nby running `bundle install --no-deployment`.") end + end - it "ignore gems not in semantic version" do + shared_examples_for "major version is ignored" do + before do update_repo2 do - build_gem "weakling", "1" + build_gem "activesupport", "3.3.5" + build_gem "weakling", "1.0.1" end + end - bundle "outdated --major" - expect(out).to include("weakling (newest") + it "ignores gems that have updates in the major version" do + subject + expect(out).to_not include("activesupport (newest") + expect(out).to_not include("weakling (newest") end end - describe "with --minor option" do - it "only reports gems that have at least a newer minor version" do + shared_examples_for "minor version is ignored" do + before do update_repo2 do - build_gem "activesupport", "3.0.0" - build_gem "weakling", "0.2.0" + build_gem "activesupport", "2.4.5" + build_gem "weakling", "0.3.1" end + end - bundle "outdated --minor" - expect(out).to include("weakling (newest") - expect(out).to include("activesupport (newest") + it "ignores gems that have updates in the minor version" do + subject + expect(out).to_not include("activesupport (newest") + expect(out).to_not include("weakling (newest") end + end - it "ignore patch version" do + shared_examples_for "patch version is ignored" do + before do update_repo2 do build_gem "activesupport", "2.3.6" build_gem "weakling", "0.0.4" end + end - bundle "outdated --minor" - expect(out).to_not include("weakling (newest") + it "ignores gems that have updates in the patch version" do + subject expect(out).to_not include("activesupport (newest") + expect(out).to_not include("weakling (newest") end + end + + describe "with --major option" do + subject { bundle "outdated --major" } - it "ignore gems not in semantic version" do + it "only reports gems that have a newer major version" do update_repo2 do - build_gem "weakling", "1" + build_gem "activesupport", "3.3.5" + build_gem "weakling", "0.8.0" end - bundle "outdated --minor" - expect(out).to include("weakling (newest") + subject + expect(out).to include("activesupport (newest") + expect(out).to_not include("weakling (newest") end - end - context "after bundle install --deployment" do - before do - install_gemfile <<-G, :deployment => true - source "file://#{gem_repo2}" + it_behaves_like "minor version is ignored" + it_behaves_like "patch version is ignored" + end - gem "rack" - gem "foo" - G - end + describe "with --minor option" do + subject { bundle "outdated --minor" } - it "outputs a helpful message about being in deployment mode" do - update_repo2 { build_gem "activesupport", "3.0" } + it "only reports gems that have a newer minor version" do + update_repo2 do + build_gem "activesupport", "2.7.5" + build_gem "weakling", "2.0.1" + end - bundle "outdated" - expect(exitstatus).to_not be_zero if exitstatus - expect(out).to include("You are trying to check outdated gems in deployment mode.") - expect(out).to include("Run `bundle outdated` elsewhere.") - expect(out).to include("If this is a development machine, remove the ") - expect(out).to include("Gemfile freeze\nby running `bundle install --no-deployment`.") + subject + expect(out).to include("activesupport (newest") + expect(out).to_not include("weakling (newest") end + + it_behaves_like "major version is ignored" + it_behaves_like "patch version is ignored" end end |