diff options
author | chrismo <chrismo@clabs.org> | 2016-10-06 09:39:07 -0500 |
---|---|---|
committer | chrismo <chrismo@clabs.org> | 2016-10-12 17:49:00 -0500 |
commit | b8c23f39399d8a6296ea268e7fcd57d3ac712467 (patch) | |
tree | 35ca18e4d7f9ad936bff9c60d66d041d79620f6f /lib | |
parent | c0f7f128a55ef3165da52b44f1b82fca80de3238 (diff) | |
download | bundler-b8c23f39399d8a6296ea268e7fcd57d3ac712467.tar.gz |
Enable cons updates in outdated and other fixes.
Fixes #4772 - Changes previous `--patch` / `--minor` / `--major` options
to `--filter-patch` / `--filter-minor` / `--filter-major` and adds back
`--patch` / `--minor` / `--major` as conservative the patch level update
options to match the behavior of these options in `bundle update` in
1.13.
This is a breaking change for the previous filtering options added in
1.12, but we're allowing it because there was some confusion as to what
those options did in 1.12, some thinking that it would perform the
resolution constraints that these options _now_ actually do.
A problem with merging in conservative bundle update options was the
pre-existing `--strict` `outdated` option, which has been in `outdated`
since 1.5. `--strict` for `outdated` means to only report on newer gem
versions that still satisfy declared requirements in the Gemfile.
Without `--strict`, `outdated` reports the most recent available
regardless of declared requirements in the Gemfile.
`--strict` in `update` in 1.13 means to not allow _any_ dependency to
update past the patch level option.
Rather than break the longer standing `--strict` option, the new
`--update-strict` option has been added which maps to the conservative
bundle update `--strict` option. We can revisit this in 2.0.
This also fixes #5065, where the new filtering options were ignored if
the `--strict` option was used.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 14 | ||||
-rw-r--r-- | lib/bundler/cli/common.rb | 10 | ||||
-rw-r--r-- | lib/bundler/cli/lock.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 22 | ||||
-rw-r--r-- | lib/bundler/cli/update.rb | 2 |
5 files changed, 33 insertions, 17 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index f92ecb1c33..8ecad5e6ba 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -268,6 +268,9 @@ module Bundler in the given source. Calling outdated with [GEM [GEM]] will only check for newer versions of the given gems. Prerelease gems are ignored by default. If your gems are up to date, Bundler will exit with a status of 0. Otherwise, it will exit 1. + + For more information on conservative resolution options (--major, --minor, + --patch, --strict) see documentation on the same options on the update command. D method_option "group", :aliases => "--group", :type => :string, :banner => "List gems from a specific group" method_option "groups", :aliases => "--groups", :type => :boolean, :banner => "List gems organized by groups" @@ -277,9 +280,14 @@ module Bundler method_option "source", :type => :array, :banner => "Check against a specific source" method_option "strict", :type => :boolean, :banner => "Only list newer versions allowed by your Gemfile requirements" - method_option "major", :type => :boolean, :banner => "Only list major newer versions" - method_option "minor", :type => :boolean, :banner => "Only list minor newer versions" - method_option "patch", :type => :boolean, :banner => "Only list patch newer versions" + method_option "update-strict", :type => :boolean, :banner => + "Strict conservative resolution, do not allow any gem to be updated past latest --patch/--minor/--major" + method_option "minor", :type => :boolean, :banner => "Prefer updating only to next minor version" + method_option "major", :type => :boolean, :banner => "Prefer updating to next major version (default)" + method_option "patch", :type => :boolean, :banner => "Prefer updating only to next patch version" + method_option "filter-major", :type => :boolean, :banner => "Only list major newer versions" + method_option "filter-minor", :type => :boolean, :banner => "Only list minor newer versions" + method_option "filter-patch", :type => :boolean, :banner => "Only list patch newer versions" method_option "parseable", :aliases => "--porcelain", :type => :boolean, :banner => "Use minimal formatting for more parseable output" def outdated(*gems) diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 6f45322db8..40a429bac4 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -53,13 +53,17 @@ module Bundler message end - def self.config_gem_version_promoter(definition, opts) - patch_level = [:major, :minor, :patch].select {|v| opts.keys.include?(v.to_s) } + def self.configure_gem_version_promoter(definition, options) + patch_level = patch_level_options(options) raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1 definition.gem_version_promoter.tap do |gvp| gvp.level = patch_level.first || :major - gvp.strict = opts[:strict] + gvp.strict = options[:strict] || options["update-strict"] end end + + def self.patch_level_options(options) + [:major, :minor, :patch].select {|v| options.keys.include?(v.to_s) } + end end end diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb index eb47c9efb0..d11c809fa2 100644 --- a/lib/bundler/cli/lock.rb +++ b/lib/bundler/cli/lock.rb @@ -25,7 +25,7 @@ module Bundler update = { :gems => update } if update.is_a?(Array) definition = Bundler.definition(update) - Bundler::CLI::Common.config_gem_version_promoter(Bundler.definition, options) if options[:update] + Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) if options[:update] options["remove-platform"].each do |platform| definition.remove_platform(platform) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 5729c07ffe..60ac869637 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -31,6 +31,10 @@ module Bundler Bundler.definition(:gems => gems, :sources => sources) end + Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) + # the patch level options don't work without strict also being true + strict = options[:strict] || Bundler::CLI::Common.patch_level_options(options).any? + definition_resolution = proc { options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely! } if options[:parseable] Bundler.ui.silence(&definition_resolution) @@ -49,7 +53,7 @@ module Bundler dependency = current_dependencies[current_spec.name] - if options[:strict] + if strict active_spec = definition.specs.detect {|spec| spec.name == current_spec.name && spec.platform == current_spec.platform } else active_specs = definition.index[current_spec.name].select {|spec| spec.platform == current_spec.platform }.sort_by(&:version) @@ -57,11 +61,11 @@ module Bundler active_spec = active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? } end active_spec = active_specs.last + end - if options[:major] || options[:minor] || options[:patch] - update_present = update_present_via_semver_portions(current_spec, active_spec, options) - active_spec = nil unless update_present - end + if options["filter-major"] || options["filter-minor"] || options["filter-patch"] + update_present = update_present_via_semver_portions(current_spec, active_spec, options) + active_spec = nil unless update_present end next if active_spec.nil? @@ -167,15 +171,15 @@ module Bundler active_major = active_spec.version.segments.first update_present = false - update_present = active_major > current_major if options[:major] + update_present = active_major > current_major if options["filter-major"] - if !update_present && (options[:minor] || options[:patch]) && current_major == active_major + if !update_present && (options["filter-minor"] || options["filter-patch"]) && current_major == active_major current_minor = get_version_semver_portion_value(current_spec, 1) active_minor = get_version_semver_portion_value(active_spec, 1) - update_present = active_minor > current_minor if options[:minor] + update_present = active_minor > current_minor if options["filter-minor"] - if !update_present && options[:patch] && current_minor == active_minor + if !update_present && options["filter-patch"] && current_minor == active_minor current_patch = get_version_semver_portion_value(current_spec, 2) active_patch = get_version_semver_portion_value(active_spec, 2) diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index 51de98bf34..68d065a932 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -40,7 +40,7 @@ module Bundler Bundler.definition(:gems => gems, :sources => sources, :ruby => options[:ruby]) end - Bundler::CLI::Common.config_gem_version_promoter(Bundler.definition, options) + Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) Bundler::Fetcher.disable_endpoint = options["full-index"] |