diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 916ae9bf782..2d63072299a 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 6f0d3611605..a53fd7a26f8 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -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("/") @@ -488,7 +472,6 @@ 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} }" @@ -496,8 +479,8 @@ def warn_deprecated_git_source(name, replacement, additional_message = nil) "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} diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 0adbd9190f5..aafd37f7663 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -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? } @@ -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? } diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index ff9a5f57af2..284b9628336 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -35,6 +35,7 @@ class Settings frozen gem.coc gem.mit + github.https global_path_appends_ruby_scope global_gem_cache ignore_messages @@ -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 " \ - " `, 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 " \ + " `, 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 diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 996f7b3fd40..cf53c1acbcb 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -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) diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index ce0544a5732..8d61ef4540a 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -245,7 +245,7 @@ # 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 @@ -253,12 +253,12 @@ 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] diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index ef51112d720..463c907eeae 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -RSpec.describe "major deprecations", :bundler => "< 2" do +RSpec.describe "major deprecations" do let(:warnings) { last_command.bundler_err } # change to err in 2.0 - let(:warnings_without_version_messages) { warnings.gsub(/#{Spec::Matchers::MAJOR_DEPRECATION}Bundler will only support ruby >= .*/, "") } before do create_file "gems.rb", <<-G @@ -35,7 +34,7 @@ describe "bundle update --quiet" do it "does not print any deprecations" do bundle :update, :quiet => true - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end end @@ -52,7 +51,7 @@ it "does not warn when --all is passed" do bundle! "update --all" - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end end @@ -68,7 +67,7 @@ end end - context "when bundle is run" do + context "when bundle install is run" do it "should not warn about gems.rb" do create_file "gems.rb", <<-G source "file://#{gem_repo1}" @@ -76,22 +75,22 @@ G bundle :install - expect(warnings_without_version_messages).not_to have_major_deprecation + expect(warnings).not_to have_major_deprecation end - it "should print a Gemfile deprecation warning" do + it "should print a Gemfile deprecation warning when both types present" do create_file "gems.rb" install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G - expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gem "rack 1.0" - expect(warnings).to have_major_deprecation a_string_including("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + expect(warnings).to have_major_deprecation("Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler will ignore them.") end context "with flags" do - it "should print a deprecation warning about autoremembering flags" do + it "should print a deprecation warning about autoremembering flags", :bundler => "3" do install_gemfile <<-G, :path => "vendor/bundle" source "file://#{gem_repo1}" gem "rack" @@ -101,6 +100,34 @@ "flags passed to commands will no longer be automatically remembered." ) end + + { + :clean => true, + :deployment => true, + :frozen => true, + :"no-cache" => true, + :"no-prune" => true, + :path => "vendor/bundle", + :shebang => "ruby27", + :system => true, + :without => "development", + :with => "development", + }.each do |name, value| + flag_name = "--#{name}" + + context "with the #{flag_name} flag" do + it "should print a deprecation warning" do + bundle "install #{flag_name} #{value}" + + expect(warnings).to have_major_deprecation( + "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 end end @@ -122,7 +149,7 @@ Bundler.setup RUBY - expect(warnings_without_version_messages).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + expect(warnings).to include("Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler will ignore them.") end end @@ -146,27 +173,31 @@ end context "with github gems" do - it "warns about the https change" do - msg = <<-EOS -The :github git source is deprecated, and will be removed in Bundler 2.0. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work: + let(:msg) do + <<-EOS +The :github git source is deprecated, and will be removed in Bundler 3.0. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work: git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) - subject.gem("sparks", :github => "indirect/sparks") end - it "upgrades to https on request" do - Bundler.settings.temporary "github.https" => true - msg = <<-EOS -The :github git source is deprecated, and will be removed in Bundler 2.0. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work: + it "warns about future removal" do + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) + subject.gem("sparks", :github => "indirect/sparks") + end - git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } + it "downgrades to http on request" do + Bundler.settings.temporary "github.https" => false + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, "Setting `github.https` to false is deprecated and won't be supported in the future.") + subject.gem("sparks", :github => "indirect/sparks") + github_uri = "git://github.com/indirect/sparks.git" + expect(subject.dependencies.first.source.uri).to eq(github_uri) + end - EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, "The `github.https` setting will be removed") + it "uses https by default" do + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) subject.gem("sparks", :github => "indirect/sparks") github_uri = "https://github.com/indirect/sparks.git" expect(subject.dependencies.first.source.uri).to eq(github_uri) @@ -177,7 +208,7 @@ it "warns about removal" do allow(Bundler.ui).to receive(:deprecate) msg = <<-EOS -The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add this code to the top of your Gemfile to ensure it continues to work: +The :bitbucket git source is deprecated, and will be removed in Bundler 3.0. Add this code to the top of your Gemfile to ensure it continues to work: git_source(:bitbucket) do |repo_name| user_name, repo_name = repo_name.split("/") @@ -186,7 +217,7 @@ end EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") end end @@ -195,10 +226,10 @@ it "warns about removal" do allow(Bundler.ui).to receive(:deprecate) msg = "The :gist git source is deprecated, and will be removed " \ - "in Bundler 2.0. Add this code to the top of your Gemfile to ensure it " \ + "in Bundler 3.0. Add this code to the top of your Gemfile to ensure it " \ "continues to work:\n\n git_source(:gist) {|repo_name| " \ "\"https://gist.github.com/\#{repo_name}.git\" }\n\n" - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) subject.gem("not-really-a-gem", :gist => "1234") end end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index 8bdef33a79f..60de02d5c59 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -172,6 +172,7 @@ def check_for_specific_pronouns(filename) forget_cli_options gem.coc gem.mit + github.https inline lockfile_uses_separate_rubygems_sources use_gem_version_promoter_for_major_updates