diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-01-14 13:38:17 +0900 |
---|---|---|
committer | NARUSE, Yui <nurse@users.noreply.github.com> | 2021-01-14 16:44:42 +0900 |
commit | 93dcf0828dc8e627e0c24497795d927911a9d993 (patch) | |
tree | 391f87ebf731d82c74fc44322a012024c3bd62f7 /lib | |
parent | c721e36ceca587d823a765cbbad90911a20cffce (diff) |
Merge Bundler-2.2.5
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/gem.rb | 2 | ||||
-rw-r--r-- | lib/bundler/compact_index_client/updater.rb | 8 | ||||
-rw-r--r-- | lib/bundler/gem_helper.rb | 6 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 7 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 34 | ||||
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 52 | ||||
-rw-r--r-- | lib/bundler/source/path/installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 11 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/Gemfile.tt | 2 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/newgem.gemspec.tt | 2 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/rubocop.yml.tt | 3 | ||||
-rw-r--r-- | lib/bundler/version.rb | 2 |
13 files changed, 82 insertions, 50 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index c72ad27c40..b299cc8a28 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -63,7 +63,6 @@ module Bundler autoload :Resolver, File.expand_path("bundler/resolver", __dir__) autoload :Retry, File.expand_path("bundler/retry", __dir__) autoload :RubyDsl, File.expand_path("bundler/ruby_dsl", __dir__) - autoload :RubyGemsGemInstaller, File.expand_path("bundler/rubygems_gem_installer", __dir__) autoload :RubyVersion, File.expand_path("bundler/ruby_version", __dir__) autoload :Runtime, File.expand_path("bundler/runtime", __dir__) autoload :Settings, File.expand_path("bundler/settings", __dir__) diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 8d26e4c1f4..17b4956fa0 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -59,6 +59,7 @@ module Bundler :exe => options[:exe], :bundler_version => bundler_dependency_version, :github_username => github_username.empty? ? "[USERNAME]" : github_username, + :required_ruby_version => Gem.ruby_version < Gem::Version.new("2.4.a") ? "2.3.0" : "2.4.0", } ensure_safe_gem_name(name, constant_array) @@ -147,6 +148,7 @@ module Bundler "For more information, see the RuboCop docs (https://docs.rubocop.org/en/stable/) " \ "and the Ruby Style Guides (https://github.com/rubocop-hq/ruby-style-guide).") config[:rubocop] = true + config[:rubocop_version] = Gem.ruby_version < Gem::Version.new("2.4.a") ? "0.81.0" : "1.7" Bundler.ui.info "RuboCop enabled in config" templates.merge!("rubocop.yml.tt" => ".rubocop.yml") end diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 66d1735583..7959e5c089 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true require_relative "../vendored_fileutils" -require "stringio" -require "zlib" module Bundler class CompactIndexClient @@ -45,18 +43,12 @@ module Bundler else "bytes=#{local_temp_path.size}-" end - else - # Fastly ignores Range when Accept-Encoding: gzip is set - headers["Accept-Encoding"] = "gzip" end response = @fetcher.call(remote_path, headers) return nil if response.is_a?(Net::HTTPNotModified) content = response.body - if response["Content-Encoding"] == "gzip" - content = Zlib::GzipReader.new(StringIO.new(content)).read - end SharedHelpers.filesystem_access(local_temp_path) do if response.is_a?(Net::HTTPPartialContent) && local_temp_path.size.nonzero? diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 4ada36aef4..0acaa69f25 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -117,13 +117,13 @@ module Bundler def git_push(remote = nil) remote ||= default_remote perform_git_push remote - perform_git_push "#{remote} #{version_tag}" + perform_git_push "#{remote} refs/tags/#{version_tag}" Bundler.ui.confirm "Pushed git commits and release tag." end def default_remote - current_branch = sh(%w[git rev-parse --abbrev-ref HEAD]).strip - return "origin" if current_branch.empty? + # We can replace this with `git branch --show-current` once we drop support for git < 2.22.0 + current_branch = sh(%w[git rev-parse --abbrev-ref HEAD]).gsub(%r{\Aheads/}, "").strip remote_for_branch = sh(%W[git config --get branch.#{current_branch}.remote]).strip return "origin" if remote_for_branch.empty? diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 636dc8af46..4972d85e08 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -163,7 +163,12 @@ module Bundler # Add a spec group for "non platform specific spec" as the fallback # spec group. sg_ruby = sg.copy_for([Gem::Platform::RUBY]) - selected_sgs.insert(-2, sg_ruby) if sg_ruby + next unless sg_ruby + + sg_ruby_deps = sg_ruby.dependencies_for_activated_platforms.map(&:dep) + sg_all_platforms_deps = sg_all_platforms.dependencies_for_activated_platforms.map(&:dep) + + selected_sgs.insert(-2, sg_ruby) if sg_ruby_deps != sg_all_platforms_deps end selected_sgs end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 0157995cb0..a3e6439d5d 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -22,7 +22,7 @@ module Bundler @uri = options["uri"] || "" @safe_uri = URICredentialsFilter.credential_filtered_uri(@uri) @branch = options["branch"] - @ref = options["ref"] || options["branch"] || options["tag"] || "master" + @ref = options["ref"] || options["branch"] || options["tag"] @submodules = options["submodules"] @name = options["name"] @version = options["version"].to_s.strip.gsub("-", ".pre.") @@ -60,25 +60,27 @@ module Bundler alias_method :==, :eql? def to_s - at = if local? - path - elsif user_ref = options["ref"] - if ref =~ /\A[a-z0-9]{4,}\z/i - shortref_for_display(user_ref) + begin + at = if local? + path + elsif user_ref = options["ref"] + if ref =~ /\A[a-z0-9]{4,}\z/i + shortref_for_display(user_ref) + else + user_ref + end + elsif ref + ref else - user_ref + git_proxy.branch end - else - ref - end - rev = begin - "@#{shortref_for_display(revision)}" - rescue GitError - nil - end + rev = " (at #{at}@#{shortref_for_display(revision)})" + rescue GitError + "" + end - "#{@safe_uri} (at #{at}#{rev})" + "#{@safe_uri}#{rev}" end def name diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index dd65c674d8..ae21770306 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -17,7 +17,7 @@ module Bundler class GitNotAllowedError < GitError def initialize(command) msg = String.new - msg << "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, " + msg << "Bundler is trying to run `#{command}` at runtime. You probably need to run `bundle install`. However, " msg << "this error message could probably be more useful. Please submit a ticket at https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md " msg << "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}" super msg @@ -27,11 +27,11 @@ module Bundler class GitCommandError < GitError attr_reader :command - def initialize(command, path, destination_path, extra_info = nil) + def initialize(command, path, extra_info = nil) @command = command msg = String.new - msg << "Git error: command `git #{command}` in directory #{destination_path} has failed." + msg << "Git error: command `#{command}` in directory #{path} has failed." msg << "\n#{extra_info}" if extra_info msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if path.exist? super msg @@ -39,9 +39,9 @@ module Bundler end class MissingGitRevisionError < GitCommandError - def initialize(command, path, destination_path, ref, repo) + def initialize(command, destination_path, ref, repo) msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?" - super command, path, destination_path, msg + super command, destination_path, msg end end @@ -132,7 +132,7 @@ module Bundler begin git "reset", "--hard", @revision, :dir => destination rescue GitCommandError => e - raise MissingGitRevisionError.new(e.command, path, destination, @revision, URICredentialsFilter.credential_filtered_uri(uri)) + raise MissingGitRevisionError.new(e.command, destination, @revision, URICredentialsFilter.credential_filtered_uri(uri)) end if submodules @@ -145,32 +145,36 @@ module Bundler private - def git_null(*command, dir: SharedHelpers.pwd) + def git_null(*command, dir: nil) check_allowed(command) out, status = SharedHelpers.with_clean_git_env do - capture_and_ignore_stderr("git", "-C", dir.to_s, *command) + capture_and_ignore_stderr(*capture3_args_for(command, dir)) end [URICredentialsFilter.credential_filtered_string(out, uri), status] end - def git_retry(*command, dir: SharedHelpers.pwd) - Bundler::Retry.new("`git -C #{dir} #{URICredentialsFilter.credential_filtered_string(command.shelljoin, uri)}`", GitNotAllowedError).attempts do + def git_retry(*command, dir: nil) + command_with_no_credentials = check_allowed(command) + + Bundler::Retry.new("`#{command_with_no_credentials}` at #{dir || SharedHelpers.pwd}").attempts do git(*command, :dir => dir) end end - def git(*command, dir: SharedHelpers.pwd) + def git(*command, dir: nil) command_with_no_credentials = check_allowed(command) out, status = SharedHelpers.with_clean_git_env do - capture_and_filter_stderr("git", "-C", dir.to_s, *command) + capture_and_filter_stderr(*capture3_args_for(command, dir)) end - raise GitCommandError.new(command_with_no_credentials, path, dir) unless status.success? + filtered_out = URICredentialsFilter.credential_filtered_string(out, uri) + + raise GitCommandError.new(command_with_no_credentials, dir || SharedHelpers.pwd, filtered_out) unless status.success? - URICredentialsFilter.credential_filtered_string(out, uri) + filtered_out end def has_revision_cached? @@ -187,10 +191,10 @@ module Bundler def find_local_revision allowed_with_path do - git("rev-parse", "--verify", ref, :dir => path).strip + git("rev-parse", "--verify", ref || "HEAD", :dir => path).strip end rescue GitCommandError => e - raise MissingGitRevisionError.new(e.command, path, path, ref, URICredentialsFilter.credential_filtered_uri(uri)) + raise MissingGitRevisionError.new(e.command, path, ref, URICredentialsFilter.credential_filtered_uri(uri)) end # Adds credentials to the URI as Fetcher#configured_uri_for does @@ -220,7 +224,7 @@ module Bundler end def check_allowed(command) - command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command.shelljoin, uri) + command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri) raise GitNotAllowedError.new(command_with_no_credentials) unless allow? command_with_no_credentials end @@ -237,6 +241,20 @@ module Bundler return_value, _, status = Open3.capture3(*cmd) [return_value, status] end + + def capture3_args_for(cmd, dir) + return ["git", *cmd] unless dir + + if Bundler.feature_flag.bundler_3_mode? || supports_minus_c? + ["git", "-C", dir.to_s, *cmd] + else + ["git", *cmd, { :chdir => dir.to_s }] + end + end + + def supports_minus_c? + @supports_minus_c ||= Gem::Version.new(version) >= Gem::Version.new("1.8.5") + end end end end diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb index 6be58e2087..72bfbb4836 100644 --- a/lib/bundler/source/path/installer.rb +++ b/lib/bundler/source/path/installer.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../../rubygems_gem_installer" + module Bundler class Source class Path diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 97f9808578..a6ac5613d0 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -145,6 +145,8 @@ module Bundler Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5") + require_relative "../rubygems_gem_installer" + installed_spec = Bundler::RubyGemsGemInstaller.at( path, :install_dir => install_path.to_s, @@ -487,8 +489,15 @@ module Bundler uri = spec.remote.uri Bundler.ui.confirm("Fetching #{version_message(spec)}") rubygems_local_path = Bundler.rubygems.download_gem(spec, uri, download_path) + + # older rubygems return varying file:// variants depending on version + rubygems_local_path = rubygems_local_path.gsub(/\Afile:/, "") unless Bundler.rubygems.provides?(">= 3.2.0.rc.2") + rubygems_local_path = rubygems_local_path.gsub(%r{\A//}, "") if Bundler.rubygems.provides?("< 3.1.0") + if rubygems_local_path != local_path - FileUtils.mv(rubygems_local_path, local_path) + SharedHelpers.filesystem_access(local_path) do + FileUtils.mv(rubygems_local_path, local_path) + end end cache_globally(spec, local_path) end diff --git a/lib/bundler/templates/newgem/Gemfile.tt b/lib/bundler/templates/newgem/Gemfile.tt index 1d55fd7a90..b09ccfff15 100644 --- a/lib/bundler/templates/newgem/Gemfile.tt +++ b/lib/bundler/templates/newgem/Gemfile.tt @@ -16,5 +16,5 @@ gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" <%- end -%> <%- if config[:rubocop] -%> -gem "rubocop", "~> 0.80" +gem "rubocop", "~> <%= config[:rubocop_version] %>" <%- end -%> diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 97c3b6c5ab..632b24dda9 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| <%- if config[:mit] -%> spec.license = "MIT" <%- end -%> - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.required_ruby_version = Gem::Requirement.new(">= <%= config[:required_ruby_version] %>") spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" diff --git a/lib/bundler/templates/newgem/rubocop.yml.tt b/lib/bundler/templates/newgem/rubocop.yml.tt index 00a72e3006..9ecec78807 100644 --- a/lib/bundler/templates/newgem/rubocop.yml.tt +++ b/lib/bundler/templates/newgem/rubocop.yml.tt @@ -1,3 +1,6 @@ +AllCops: + TargetRubyVersion: <%= ::Gem::Version.new(config[:required_ruby_version]).segments[0..1].join(".") %> + Style/StringLiterals: Enabled: true EnforcedStyle: double_quotes diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 531a21988a..5a49ea546e 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.2.4".freeze + VERSION = "2.2.5".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i |