diff options
author | chrismo <chrismo@clabs.org> | 2016-10-04 00:41:07 -0500 |
---|---|---|
committer | chrismo <chrismo@clabs.org> | 2016-10-04 00:41:07 -0500 |
commit | 565d5ad1c4ad449138ee9f7de92b19ffdf90a843 (patch) | |
tree | a01373482b02b252448e3ec160cfa7601c13bbfd | |
parent | e499c51567df8ced0bad655bdf969453a3362032 (diff) | |
download | bundler-565d5ad1c4ad449138ee9f7de92b19ffdf90a843.tar.gz |
Add conservative update options to bundle lock
Fix #4912.
The bundle lock command produces a lockfile same as bundle update but
won't install all the gems. If the `--update` option is fed to `bundle
lock` you can also specify the `--patch`, `--minor`, `--major` and
`--strict` options added to `bundle update` in 1.13.
-rw-r--r-- | lib/bundler/cli.rb | 8 | ||||
-rw-r--r-- | lib/bundler/cli/common.rb | 9 | ||||
-rw-r--r-- | lib/bundler/cli/lock.rb | 4 | ||||
-rw-r--r-- | lib/bundler/cli/update.rb | 10 | ||||
-rw-r--r-- | spec/commands/lock_spec.rb | 48 |
5 files changed, 72 insertions, 7 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 8aa4a0e576..e27f498f94 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -457,6 +457,14 @@ module Bundler "add a new platform to the lockfile" method_option "remove-platform", :type => :array, :default => [], :banner => "remove a platform from the lockfile" + method_option "patch", :type => :boolean, :hide => true, :banner => + "Prefer updating only to next patch version" + method_option "minor", :type => :boolean, :hide => true, :banner => + "Prefer updating only to next minor version" + method_option "major", :type => :boolean, :hide => true, :banner => + "Prefer updating to next major version (default)" + method_option "strict", :type => :boolean, :hide => true, :banner => + "Do not allow any gem to be updated past latest --patch/--minor/--major" def lock require "bundler/cli/lock" Lock.new(options).run diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 491ea04a11..6f45322db8 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -52,5 +52,14 @@ module Bundler message += "\nDid you mean #{suggestions}?" if suggestions message end + + def self.config_gem_version_promoter(definition, opts) + patch_level = [:major, :minor, :patch].select {|v| opts.keys.include?(v.to_s) } + 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] + end + end end end diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb index d4256ad4b9..eb47c9efb0 100644 --- a/lib/bundler/cli/lock.rb +++ b/lib/bundler/cli/lock.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +require "bundler/cli/common" + module Bundler class CLI::Lock attr_reader :options @@ -23,6 +25,8 @@ 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] + options["remove-platform"].each do |platform| definition.remove_platform(platform) end diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index a8724f6a13..51de98bf34 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +require "bundler/cli/common" + module Bundler class CLI::Update attr_reader :options, :gems @@ -27,7 +29,6 @@ module Bundler names = Bundler.locked_gems.specs.map(&:name) gems.each do |g| next if names.include?(g) - require "bundler/cli/common" raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(g, names) end @@ -39,12 +40,7 @@ module Bundler Bundler.definition(:gems => gems, :sources => sources, :ruby => options[:ruby]) end - patch_level = [:major, :minor, :patch].select {|v| options.keys.include?(v.to_s) } - raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1 - Bundler.definition.gem_version_promoter.tap do |gvp| - gvp.level = patch_level.first || :major - gvp.strict = options[:strict] - end + Bundler::CLI::Common.config_gem_version_promoter(Bundler.definition, options) Bundler::Fetcher.disable_endpoint = options["full-index"] diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb index 590d421ba0..1c00aa3c1f 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -106,6 +106,54 @@ describe "bundle lock" do expect(read_lockfile).to eq(@lockfile) end + # see update_spec for more coverage on same options. logic is shared so it's not necessary + # to repeat coverage here. + context "conservative updates" do + before do + build_repo4 do + build_gem "foo", %w(1.4.3 1.4.4) do |s| + s.add_dependency "bar", "~> 2.0" + end + build_gem "foo", %w(1.4.5 1.5.0) do |s| + s.add_dependency "bar", "~> 2.1" + end + build_gem "foo", %w(1.5.1) do |s| + s.add_dependency "bar", "~> 3.0" + end + build_gem "bar", %w(2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 3.0.0) + build_gem "qux", %w(1.0.0 1.0.1 1.1.0 2.0.0) + end + + # establish a lockfile set to 1.4.3 + install_gemfile <<-G + source "file://#{gem_repo4}" + gem 'foo', '1.4.3' + gem 'bar', '2.0.3' + gem 'qux', '1.0.0' + G + + # remove 1.4.3 requirement and bar altogether + # to setup update specs below + gemfile <<-G + source "file://#{gem_repo4}" + gem 'foo' + gem 'qux' + G + end + + it "single gem updates dependent gem to minor" do + bundle "lock --update foo --patch" + + expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w(foo-1.4.5 bar-2.1.1 qux-1.0.0).sort) + end + + it "minor preferred with strict" do + bundle "lock --update --minor --strict" + + expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w(foo-1.5.0 bar-2.1.1 qux-1.1.0).sort) + end + end + it "supports adding new platforms" do bundle! "lock --add-platform java x86-mingw32" |