diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2021-02-01 16:17:16 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-03-08 13:47:35 +0900 |
commit | 53468cc11147b0d285fc376fc546b677dad600ca (patch) | |
tree | eb9c97f544d089be2d324126b025b11f41a22c90 /lib/bundler/source | |
parent | 2ab6b7a7516e1b2c48a66ce513afabb62d101461 (diff) |
Sync latest development version of bundler & rubygems
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4143
Diffstat (limited to 'lib/bundler/source')
-rw-r--r-- | lib/bundler/source/git.rb | 36 | ||||
-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 | 3 |
4 files changed, 58 insertions, 35 deletions
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 0157995cb0..fb13ca0578 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 @@ -146,7 +148,7 @@ module Bundler changed = cached_revision && cached_revision != git_proxy.revision - if changed && !@unlocked && !git_proxy.contains?(cached_revision) + if !Bundler.settings[:disable_local_revision_check] && changed && !@unlocked && !git_proxy.contains?(cached_revision) raise GitError, "The Gemfile lock is pointing to revision #{shortref_for_display(cached_revision)} " \ "but the current branch in your local override for #{name} does not contain such commit. " \ "Please make sure your branch is up to date." 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 79ad278da3..5b89b1645d 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, @@ -351,7 +353,6 @@ module Bundler def installed_specs @installed_specs ||= Index.build do |idx| Bundler.rubygems.all_specs.reverse_each do |spec| - next if spec.name == "bundler" spec.source = self if Bundler.rubygems.spec_missing_extensions?(spec, false) Bundler.ui.debug "Source #{self} is ignoring #{spec} because it is missing extensions" |