Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def install
"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
Expand Down
7 changes: 4 additions & 3 deletions lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ def normalize_settings

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
Expand Down
13 changes: 12 additions & 1 deletion lib/bundler/cli/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ def run
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
Expand Down
5 changes: 3 additions & 2 deletions lib/bundler/feature_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def self.settings_flag(flag, &default)
(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)
Expand Down
5 changes: 4 additions & 1 deletion lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Settings
only_update_to_newer_versions
plugins
silence_root_warning
update_requires_all_flag
].freeze

NUMBER_KEYS = %w[
Expand Down Expand Up @@ -76,6 +77,8 @@ def [](name)
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}"
Expand All @@ -89,7 +92,7 @@ def []=(key, value)
"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, :[]=
Expand Down
3 changes: 3 additions & 0 deletions man/bundle-config.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions spec/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@
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"
Expand Down
28 changes: 23 additions & 5 deletions spec/other/major_deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,11 +23,12 @@
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
Expand Down Expand Up @@ -85,7 +87,24 @@
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

Expand All @@ -109,8 +128,7 @@
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
Expand Down Expand Up @@ -241,7 +259,7 @@
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
7 changes: 6 additions & 1 deletion spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def self.define_compound_matcher(matcher, preconditions, &declarations)
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
Expand Down