summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-06-15 20:09:05 +0000
committerThe Bundler Bot <bot@bundler.io>2017-06-15 20:09:05 +0000
commit08d1fa6ce9a2f4317b0754525a42abecd89e4321 (patch)
treeff4b5700d6129c4f7ed7256658918e241e8c5f69
parent955ad13d8e21117418342348c62a9c7c24a95d03 (diff)
parent237f03566013309760445af3c9c0cb76d0f99635 (diff)
downloadbundler-08d1fa6ce9a2f4317b0754525a42abecd89e4321.tar.gz
Auto merge of #5722 - bundler:seg-update-all-flag, r=indirect
Add `—all` flag to `bundle update` ### What was the end-user problem that led to this PR? The problem was that some users would think they needed to run `bundle update` instead of `bundle install`, and we want such a (potentially) destructive action to require more explicit user approval. ### Was was your diagnosis of the problem? My diagnosis was that `bundle update` shouldn't implicitly update _everything_ without an acknowledgement that it will do so. ### What is your fix for the problem, implemented in this PR? My fix, based on https://github.com/bundler/bundler/pull/2646, it to require `bundle update --all` for the current `bundle update` behavior. ### Why did you choose this fix out of the possible options? I chose this fix because it was already on 2-0-dev, courtesy of https://github.com/bundler/bundler-features/issues/18.
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/install.rb7
-rw-r--r--lib/bundler/cli/update.rb13
-rw-r--r--lib/bundler/feature_flag.rb5
-rw-r--r--lib/bundler/settings.rb5
-rw-r--r--man/bundle-config.ronn3
-rw-r--r--spec/commands/update_spec.rb22
-rw-r--r--spec/other/major_deprecation_spec.rb28
-rw-r--r--spec/support/matchers.rb7
9 files changed, 79 insertions, 13 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index c9ddec93f4..e93fc9529d 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -221,6 +221,8 @@ module Bundler
"Do not allow any gem to be updated past latest --patch | --minor | --major"
method_option "conservative", :type => :boolean, :banner =>
"Use bundle install conservative update behavior and do not allow shared dependencies to be updated."
+ method_option "all", :type => :boolean, :banner =>
+ "Update everything."
def update(*gems)
require "bundler/cli/update"
Update.new(options, gems).run
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index d57cad1e3f..f36ca94821 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -208,10 +208,11 @@ module Bundler
Bundler.settings[:clean] = options["clean"] if options["clean"]
- Bundler.settings.without = options[:without]
- Bundler.settings.with = options[:with]
+ Bundler.settings.without = options[:without] unless Bundler.settings.without == options[:without]
+ Bundler.settings.with = options[:with] unless Bundler.settings.with == options[:with]
- Bundler.settings[:disable_shared_gems] = Bundler.settings[:path] ? true : nil
+ disable_shared_gems = Bundler.settings[:path] ? true : nil
+ Bundler.settings[:disable_shared_gems] = disable_shared_gems unless Bundler.settings[:disable_shared_gems] == disable_shared_gems
end
def warn_ambiguous_gems
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb
index df7524f004..9e4543668e 100644
--- a/lib/bundler/cli/update.rb
+++ b/lib/bundler/cli/update.rb
@@ -17,7 +17,18 @@ module Bundler
sources = Array(options[:source])
groups = Array(options[:group]).map(&:to_sym)
- if gems.empty? && sources.empty? && groups.empty? && !options[:ruby] && !options[:bundler]
+ full_update = gems.empty? && sources.empty? && groups.empty? && !options[:ruby] && !options[:bundler]
+
+ if full_update && !options[:all]
+ if Bundler.feature_flag.update_requires_all_flag?
+ raise InvalidOption, "To update everything, pass the `--all` flag."
+ end
+ SharedHelpers.major_deprecation "Pass --all to `bundle update` to update everything"
+ elsif !full_update && options[:all]
+ raise InvalidOption, "Cannot specify --all along with specific options."
+ end
+
+ if full_update
# We're doing a full update
Bundler.definition(true)
else
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 3a4353f2af..f472ba2b7b 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -15,10 +15,11 @@ module Bundler
(1..10).each {|v| define_method("bundler_#{v}_mode?") { major_version >= v } }
settings_flag(:allow_offline_install) { bundler_2_mode? }
- settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
- settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:error_on_stderr) { bundler_2_mode? }
settings_flag(:init_gems_rb) { bundler_2_mode? }
+ settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
+ settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
+ settings_flag(:update_requires_all_flag) { bundler_2_mode? }
def initialize(bundler_version)
@bundler_version = Gem::Version.create(bundler_version)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 7857e00ea0..34747cbed7 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -29,6 +29,7 @@ module Bundler
only_update_to_newer_versions
plugins
silence_root_warning
+ update_requires_all_flag
].freeze
NUMBER_KEYS = %w[
@@ -76,6 +77,8 @@ module Bundler
end
def []=(key, value)
+ local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
+
if cli_flags_given
command = if value.nil?
"bundle config --delete #{key}"
@@ -89,7 +92,7 @@ module Bundler
"you want remembered between commands using `bundle config " \
"<setting name> <setting value>`, i.e. `#{command}`"
end
- local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
+
set_key(key, value, @local_config, local_config_file)
end
alias_method :set_local, :[]=
diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn
index 18773017f8..d387350f8b 100644
--- a/man/bundle-config.ronn
+++ b/man/bundle-config.ronn
@@ -226,6 +226,9 @@ learn more about their operation in [bundle install(1)][bundle-install].
Print Bundler errors to stderr
* `init_gems_rb` (`BUNDLE_NEW_GEMFILE_NAME`)
generate a new gems.rb on `bundle init` instead of the `Gemfile`
+* `update_requires_all_flag` (`BUNDLE_UPDATE_REQUIRES_ALL_FLAG`)
+ Require passing `--all` to `bundle update` when everything should be updated,
+ and disallow passing no options to `bundle update`.
In general, you should set these settings per-application by using the applicable
flag to the [bundle install(1)][bundle-install] or [bundle package(1)][bundle-package] command.
diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb
index b278036a12..b0a55ab930 100644
--- a/spec/commands/update_spec.rb
+++ b/spec/commands/update_spec.rb
@@ -34,6 +34,28 @@ RSpec.describe "bundle update" do
end
end
+ context "when update_requires_all_flag is set" do
+ before { bundle! "config update_requires_all_flag true" }
+
+ it "errors when passed nothing" do
+ install_gemfile! ""
+ bundle :update
+ expect(out).to eq("To update everything, pass the `--all` flag.")
+ end
+
+ it "errors when passed --all and another option" do
+ install_gemfile! ""
+ bundle "update --all foo"
+ expect(out).to eq("Cannot specify --all along with specific options.")
+ end
+
+ it "updates everything when passed --all" do
+ install_gemfile! ""
+ bundle "update --all"
+ expect(out).to include("Bundle updated!")
+ end
+ end
+
describe "--quiet argument" do
it "hides UI messages" do
bundle "update --quiet"
diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb
index 03c2acba69..59dd50bac9 100644
--- a/spec/other/major_deprecation_spec.rb
+++ b/spec/other/major_deprecation_spec.rb
@@ -2,6 +2,7 @@
RSpec.describe "major deprecations" do
let(:warnings) { out } # change to err in 2.0
+ let(:warnings_without_version_messages) { warnings.gsub(/#{Spec::Matchers::MAJOR_DEPRECATION}Bundler will only support ruby(gems)? >= .*/, "") }
context "in a .99 version" do
before do
@@ -22,11 +23,12 @@ RSpec.describe "major deprecations" do
before do
bundle "config major_deprecations true"
- install_gemfile <<-G
+ create_file "gems.rb", <<-G
source "file:#{gem_repo1}"
ruby #{RUBY_VERSION.dump}
gem "rack"
G
+ bundle! "install"
end
describe "bundle_ruby" do
@@ -85,7 +87,24 @@ RSpec.describe "major deprecations" do
describe "bundle update --quiet" do
it "does not print any deprecations" do
bundle :update, :quiet => true
- expect(warnings).not_to have_major_deprecation
+ expect(warnings_without_version_messages).not_to have_major_deprecation
+ end
+ end
+
+ describe "bundle update" do
+ before do
+ create_file("gems.rb", "")
+ bundle! "install"
+ end
+
+ it "warns when no options are given" do
+ bundle! "update"
+ expect(warnings).to have_major_deprecation a_string_including("Pass --all to `bundle update` to update everything")
+ end
+
+ it "does not warn when --all is passed" do
+ bundle! "update --all"
+ expect(warnings_without_version_messages).not_to have_major_deprecation
end
end
@@ -109,8 +128,7 @@ RSpec.describe "major deprecations" do
G
bundle :install
- expect(err).not_to have_major_deprecation
- expect(out).not_to have_major_deprecation
+ expect(warnings_without_version_messages).not_to have_major_deprecation
end
it "should print a Gemfile deprecation warning" do
@@ -255,7 +273,7 @@ The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add
bundle "console"
expect(warnings).to have_major_deprecation \
- "bundle console will be replaced by `bin/console` generated by `bundle gem <name>`"
+ a_string_including("bundle console will be replaced by `bin/console` generated by `bundle gem <name>`")
end
end
end
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index 9248360639..4fbf44a4e0 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -78,7 +78,12 @@ module Spec
RSpec::Matchers.define :have_major_deprecation do |expected|
diffable
match do |actual|
- actual.split(MAJOR_DEPRECATION).any? do |d|
+ deprecations = actual.split(MAJOR_DEPRECATION)
+
+ return !expected.nil? if deprecations.size <= 1
+ return true if expected.nil?
+
+ deprecations.any? do |d|
!d.empty? && values_match?(expected, d.strip)
end
end