diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-06-04 16:05:17 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-06-14 10:28:16 -0500 |
commit | 598ab4bef8fefd0a11d8b4b735a6c13b2cfb2e78 (patch) | |
tree | 0fbb14b9e2ce46facc0025ae37f7bf368ee501ea | |
parent | ddcca6254cc4e63cbb25b78f8ec93462fa56249c (diff) | |
download | bundler-598ab4bef8fefd0a11d8b4b735a6c13b2cfb2e78.tar.gz |
[DSL] Deprecate the github source for 2.0seg-deprecate-github-git-source
-rw-r--r-- | lib/bundler/dsl.rb | 39 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 42 |
2 files changed, 52 insertions, 29 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 2d219edcc7..665724f54d 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -252,6 +252,9 @@ module Bundler def add_git_sources git_source(:github) do |repo_name| + 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 @@ -268,23 +271,29 @@ module Bundler repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") # TODO: 2.0 upgrade this setting to the default if Bundler.settings["github.https"] + Bundler::SharedHelpers.major_deprecation "The `github.https` setting will be removed" "https://github.com/#{repo_name}.git" else - warn_github_source_change(repo_name) "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') + 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| - user_name, repo_name = repo_name.split "/" - warn_deprecated_git_source(:bitbucket, 'https://#{user_name}@bitbucket.org/#{user_name}/#{repo_name}.git') + warn_deprecated_git_source(:bitbucket, <<-'RUBY'.strip) +user_name, repo_name = repo_name.split("/") +repo_name ||= user_name +"https://#{user_name}@bitbucket.org/#{user_name}/#{repo_name}.git" + RUBY + + user_name, repo_name = repo_name.split("/") repo_name ||= user_name "https://#{user_name}@bitbucket.org/#{user_name}/#{repo_name}.git" end @@ -439,20 +448,20 @@ module Bundler end end - def warn_github_source_change(repo_name) + def warn_deprecated_git_source(name, replacement, additional_message = nil) # TODO: 2.0 remove deprecation - Bundler::SharedHelpers.major_deprecation "The :github option uses the git: protocol, which is not secure. " \ - "Bundler 2.0 will use the https: protocol, which is secure. Enable this change now by " \ - "running `bundle config github.https true`." - end + 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 - def warn_deprecated_git_source(name, repo_string) - # TODO: 2.0 remove deprecation Bundler::SharedHelpers.major_deprecation <<-EOS -The :#{name} git source is deprecated, and will be removed in Bundler 2.0. Add this code to your Gemfile to ensure it continues to work: - git_source(:#{name}) do |repo_name| - "#{repo_string}" - end +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: + + git_source(:#{name}) #{replacement} + EOS end diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index f7a632bdcf..03c2acba69 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -178,17 +178,27 @@ RSpec.describe "major deprecations" do context "with github gems" do it "warns about the https change" do - msg = "The :github option uses the git: protocol, which is not secure. " \ - "Bundler 2.0 will use the https: protocol, which is secure. Enable this change now by " \ - "running `bundle config 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: + + git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } + + EOS expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) subject.gem("sparks", :github => "indirect/sparks") end it "upgrades to https on request" do - Bundler.settings["github.https"] = true + 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: + + git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } + + EOS + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with("The `github.https` setting will be removed") subject.gem("sparks", :github => "indirect/sparks") - expect(Bundler::SharedHelpers).to receive(:major_deprecation).never github_uri = "https://github.com/indirect/sparks.git" expect(subject.dependencies.first.source.uri).to eq(github_uri) end @@ -197,11 +207,16 @@ RSpec.describe "major deprecations" do context "with bitbucket gems" do it "warns about removal" do allow(Bundler.ui).to receive(:deprecate) - msg = "The :bitbucket git source is deprecated, and will be removed " \ - "in Bundler 2.0. Add this code to your Gemfile to ensure it " \ - "continues to work:\n git_source(:bitbucket) do |repo_name|\n " \ - " \"https://\#{user_name}@bitbucket.org/\#{user_name}/\#{repo_name}" \ - ".git\"\n end\n" + 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: + + git_source(:bitbucket) do |repo_name| + user_name, repo_name = repo_name.split("/") + repo_name ||= user_name + "https://\#{user_name}@bitbucket.org/\#{user_name}/\#{repo_name}.git" + end + + EOS expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") end @@ -211,10 +226,9 @@ RSpec.describe "major deprecations" do 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 your Gemfile to ensure it " \ - "continues to work:\n git_source(:gist) do |repo_name|\n " \ - " \"https://gist.github.com/\#{repo_name}.git\"\n" \ - " end\n" + "in Bundler 2.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(msg) subject.gem("not-really-a-gem", :gist => "1234") end |