Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.
51 changes: 34 additions & 17 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def initialize(*args)
end
end

def self.deprecated_option(*args, &blk)
return if Bundler.feature_flag.forget_cli_options?
method_option(*args, &blk)
end

check_unknown_options!(:except => [:config, :exec])
stop_on_unknown_option! :exec

Expand Down Expand Up @@ -142,7 +137,7 @@ def self.handle_no_command_error(command, has_namespace = $thor_runner)
Gemfile to a gem with a gemspec, the --gemspec option will automatically add each
dependency listed in the gemspec file to the newly created Gemfile.
D
deprecated_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
def init
require "bundler/cli/init"
Init.new(options.dup).run
Expand Down Expand Up @@ -188,13 +183,13 @@ def remove(*gems)

If the bundle has already been installed, bundler will tell you so and then exit.
D
deprecated_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
method_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
"Generate bin stubs for bundled gems to ./bin"
deprecated_option "clean", :type => :boolean, :banner =>
method_option "clean", :type => :boolean, :banner =>
"Run bundle clean automatically after install"
deprecated_option "deployment", :type => :boolean, :banner =>
method_option "deployment", :type => :boolean, :banner =>
"Install using defaults tuned for deployment environments"
deprecated_option "frozen", :type => :boolean, :banner =>
method_option "frozen", :type => :boolean, :banner =>
"Do not allow the Gemfile.lock to be updated after this install"
method_option "full-index", :type => :boolean, :banner =>
"Fall back to using the single-file index of all gems"
Expand All @@ -204,32 +199,37 @@ def remove(*gems)
"Specify the number of jobs to run in parallel"
method_option "local", :type => :boolean, :banner =>
"Do not attempt to fetch gems remotely and use the gem cache instead"
deprecated_option "no-cache", :type => :boolean, :banner =>
method_option "no-cache", :type => :boolean, :banner =>
"Don't update the existing gem cache."
method_option "redownload", :type => :boolean, :aliases => "--force", :banner =>
"Force downloading every gem."
deprecated_option "no-prune", :type => :boolean, :banner =>
method_option "no-prune", :type => :boolean, :banner =>
"Don't remove stale gems from the cache."
deprecated_option "path", :type => :string, :banner =>
method_option "path", :type => :string, :banner =>
"Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine"
method_option "quiet", :type => :boolean, :banner =>
"Only output warnings and errors."
deprecated_option "shebang", :type => :string, :banner =>
method_option "shebang", :type => :string, :banner =>
"Specify a different shebang executable name than the default (usually 'ruby')"
method_option "standalone", :type => :array, :lazy_default => [], :banner =>
"Make a bundle that can work without the Bundler runtime"
deprecated_option "system", :type => :boolean, :banner =>
method_option "system", :type => :boolean, :banner =>
"Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application"
method_option "trust-policy", :alias => "P", :type => :string, :banner =>
"Gem trust policy (like gem install -P). Must be one of " +
Bundler.rubygems.security_policy_keys.join("|")
deprecated_option "without", :type => :array, :banner =>
method_option "without", :type => :array, :banner =>
"Exclude gems that are part of the specified named group."
deprecated_option "with", :type => :array, :banner =>
method_option "with", :type => :array, :banner =>
"Include gems that are part of the specified named group."
map "i" => "install"
def install
SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force")

%w[clean deployment frozen no-cache no-prune path shebang system without with].each do |option|
remembered_flag_deprecation(option)
end

require "bundler/cli/install"
Bundler.settings.temporary(:no_install => false) do
Install.new(options.dup).run
Expand Down Expand Up @@ -786,5 +786,22 @@ def warn_on_outdated_bundler
rescue RuntimeError
nil
end

def remembered_flag_deprecation(name)
option = current_command.options[name]
flag_name = option.switch_name

name_index = ARGV.find {|arg| flag_name == arg }
return unless name_index

value = options[name]
value = "#{value.join(" ")}" if option.type == :array

Bundler::SharedHelpers.major_deprecation 2,\
"The `#{flag_name}` flag is deprecated because it relied on being " \
"remembered accross bundler invokations, which bundler will no longer " \
"do in future versions. Instead please use `bundle config #{name} " \
"'#{value}'`, and stop using this flag"
end
end
end
23 changes: 3 additions & 20 deletions lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,37 +290,21 @@ def add_git_sources
warn_deprecated_git_source(:github, <<-'RUBY'.strip, 'Change any "reponame" :github sources to "username/reponame".')
"https://github.com/#{repo_name}.git"
RUBY
# It would be better to use https instead of the git protocol, but this
# can break deployment of existing locked bundles when switching between
# different versions of Bundler. The change will be made in 2.0, which
# does not guarantee compatibility with the 1.x series.
#
# See https://github.com/bundler/bundler/pull/2569 for discussion
#
# This can be overridden by adding this code to your Gemfiles:
#
# git_source(:github) do |repo_name|
# repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
# "https://github.com/#{repo_name}.git"
# end
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
# TODO: 2.0 upgrade this setting to the default
if Bundler.feature_flag.github_https?
Bundler::SharedHelpers.major_deprecation 2, "The `github.https` setting will be removed"
"https://github.com/#{repo_name}.git"
else
Bundler::SharedHelpers.major_deprecation 2, "Setting `github.https` to false is deprecated and won't be supported in the future."
"git://github.com/#{repo_name}.git"
end
end

# TODO: 2.0 remove this deprecated git source
git_source(:gist) do |repo_name|
warn_deprecated_git_source(:gist, '"https://gist.github.com/#{repo_name}.git"')

"https://gist.github.com/#{repo_name}.git"
end

# TODO: 2.0 remove this deprecated git source
git_source(:bitbucket) do |repo_name|
warn_deprecated_git_source(:bitbucket, <<-'RUBY'.strip)
user_name, repo_name = repo_name.split("/")
Expand Down Expand Up @@ -488,16 +472,15 @@ def check_primary_source_safety(source_list)
end

def warn_deprecated_git_source(name, replacement, additional_message = nil)
# TODO: 2.0 remove deprecation
additional_message &&= " #{additional_message}"
replacement = if replacement.count("\n").zero?
"{|repo_name| #{replacement} }"
else
"do |repo_name|\n#{replacement.to_s.gsub(/^/, " ")}\n end"
end

Bundler::SharedHelpers.major_deprecation 2, <<-EOS
The :#{name} git source is deprecated, and will be removed in Bundler 2.0.#{additional_message} Add this code to the top of your Gemfile to ensure it continues to work:
Bundler::SharedHelpers.major_deprecation 3, <<-EOS
The :#{name} git source is deprecated, and will be removed in Bundler 3.0.#{additional_message} Add this code to the top of your Gemfile to ensure it continues to work:

git_source(:#{name}) #{replacement}

Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/feature_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.settings_method(name, key, &default)
settings_flag(:deployment_means_frozen) { bundler_2_mode? }
settings_flag(:disable_multisource) { bundler_2_mode? }
settings_flag(:error_on_stderr) { bundler_2_mode? }
settings_flag(:forget_cli_options) { bundler_2_mode? }
settings_flag(:forget_cli_options) { bundler_3_mode? }
settings_flag(:global_path_appends_ruby_scope) { bundler_2_mode? }
settings_flag(:global_gem_cache) { bundler_2_mode? }
settings_flag(:init_gems_rb) { bundler_2_mode? }
Expand All @@ -50,11 +50,11 @@ def self.settings_method(name, key, &default)
settings_flag(:prefer_gems_rb) { bundler_2_mode? }
settings_flag(:print_only_version_number) { bundler_2_mode? }
settings_flag(:setup_makes_kernel_gem_public) { !bundler_2_mode? }
settings_flag(:skip_default_git_sources) { bundler_2_mode? }
settings_flag(:skip_default_git_sources) { bundler_3_mode? }
settings_flag(:specific_platform) { bundler_2_mode? }
settings_flag(:suppress_install_using_messages) { bundler_2_mode? }
settings_flag(:unlock_source_unlocks_spec) { !bundler_2_mode? }
settings_flag(:update_requires_all_flag) { bundler_2_mode? }
settings_flag(:update_requires_all_flag) { bundler_3_mode? }
settings_flag(:use_gem_version_promoter_for_major_updates) { bundler_2_mode? }
settings_flag(:viz_command) { !bundler_2_mode? }

Expand Down
19 changes: 14 additions & 5 deletions lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Settings
frozen
gem.coc
gem.mit
github.https
global_path_appends_ruby_scope
global_gem_cache
ignore_messages
Expand Down Expand Up @@ -115,11 +116,19 @@ def set_command_option(key, value)
"bundle config set #{key} #{Array(value).join(":")}"
end

Bundler::SharedHelpers.major_deprecation 2,\
"flags passed to commands " \
"will no longer be automatically remembered. Instead please set flags " \
"you want remembered between commands using `bundle config set " \
"<setting name> <setting value>`, i.e. `#{command}`"
unless Bundler.settings[:forget_cli_options] == false
Bundler::SharedHelpers.major_deprecation 3,\
"flags passed to commands " \
"will no longer be automatically remembered. Instead please set flags " \
"you want remembered between commands using `bundle config set " \
"<setting name> <setting value>`, i.e. `#{command}`. Once you are " \
"ready for the new behavior, use `bundle config set forget_cli_options " \
"true` to get rid of this message. Or if you want to get rid of " \
"this message and stick with the old behavior for now, run " \
"`bundle config set forget_cli_options false`, but keep in mind " \
"that this behavior will be fully removed in future versions of " \
"bundler."
end

set_local(key, value)
end
Expand Down
10 changes: 6 additions & 4 deletions lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ def print_major_deprecations!
multiple_gemfiles = search_up(".") do |dir|
gemfiles = gemfile_names.select {|gf| File.file? File.expand_path(gf, dir) }
next if gemfiles.empty?
break false if gemfiles.size == 1
break gemfiles.size != 1
end
return unless multiple_gemfiles && Bundler.bundler_major_version == 1
Bundler::SharedHelpers.major_deprecation 2, \
"gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock."

return unless multiple_gemfiles

Bundler.ui.warn \
"Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler will ignore them."
end

def trap(signal, override = false, &block)
Expand Down
14 changes: 7 additions & 7 deletions spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
context "github_https feature flag" do
it "is true when github.https is true" do
bundle "config set github.https true"
expect(Bundler.feature_flag.github_https?).to eq "true"
expect(Bundler.feature_flag.github_https?).to eq true
end
end

Expand All @@ -44,7 +44,7 @@

it "converts :github to :git" do
subject.gem("sparks", :github => "indirect/sparks")
github_uri = "git://github.com/indirect/sparks.git"
github_uri = "https://github.com/indirect/sparks.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end

Expand All @@ -62,7 +62,7 @@

it "converts 'rails' to 'rails/rails'" do
subject.gem("rails", :github => "rails")
github_uri = "git://github.com/rails/rails.git"
github_uri = "https://github.com/rails/rails.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end

Expand All @@ -79,7 +79,7 @@
end
end

context "default git sources", :bundler => "2" do
context "default git sources", :bundler => "3" do
it "has none" do
expect(subject.instance_variable_get(:@git_sources)).to eq({})
end
Expand Down Expand Up @@ -245,20 +245,20 @@
# gem 'spree_api'
# gem 'spree_backend'
# end
describe "#github", :bundler => "< 2" do
describe "#github", :bundler => "< 3" do
it "from github" do
spree_gems = %w[spree_core spree_api spree_backend]
subject.github "spree" do
spree_gems.each {|spree_gem| subject.send :gem, spree_gem }
end

subject.dependencies.each do |d|
expect(d.source.uri).to eq("git://github.com/spree/spree.git")
expect(d.source.uri).to eq("https://github.com/spree/spree.git")
end
end
end

describe "#github", :bundler => "2" do
describe "#github", :bundler => "3" do
it "from github" do
expect do
spree_gems = %w[spree_core spree_api spree_backend]
Expand Down
Loading