summaryrefslogtreecommitdiff
path: root/lib/rubygems/source/git.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/source/git.rb')
-rw-r--r--lib/rubygems/source/git.rb98
1 files changed, 50 insertions, 48 deletions
diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb
index 23f8928a4e..baf2f9dd4c 100644
--- a/lib/rubygems/source/git.rb
+++ b/lib/rubygems/source/git.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-require 'rubygems/util'
##
# A git gem for use in a gem dependencies file.
@@ -12,7 +11,6 @@ require 'rubygems/util'
# source.specs
class Gem::Source::Git < Gem::Source
-
##
# The name of the gem created by this git gem.
@@ -50,20 +48,19 @@ class Gem::Source::Git < Gem::Source
# repository may contain multiple gems. If +submodules+ is true, submodules
# will be checked out when the gem is installed.
- def initialize name, repository, reference, submodules = false
- super repository
-
+ def initialize(name, repository, reference, submodules = false)
+ require_relative "../uri"
+ @uri = Gem::Uri.parse(repository)
@name = name
@repository = repository
- @reference = reference
+ @reference = reference || "HEAD"
@need_submodules = submodules
@remote = true
@root_dir = Gem.dir
- @git = ENV['git'] || 'git'
end
- def <=> other
+ def <=>(other)
case other
when Gem::Source::Git then
0
@@ -72,19 +69,21 @@ class Gem::Source::Git < Gem::Source
-1
when Gem::Source then
1
- else
- nil
end
end
- def == other # :nodoc:
- super and
- @name == other.name and
- @repository == other.repository and
- @reference == other.reference and
+ def ==(other) # :nodoc:
+ super &&
+ @name == other.name &&
+ @repository == other.repository &&
+ @reference == other.reference &&
@need_submodules == other.need_submodules
end
+ def git_command
+ ENV.fetch("git", "git")
+ end
+
##
# Checks out the files for the repository into the install_dir.
@@ -93,19 +92,22 @@ class Gem::Source::Git < Gem::Source
return false unless File.exist? repo_cache_dir
- unless File.exist? install_dir then
- system @git, 'clone', '--quiet', '--no-checkout',
+ unless File.exist? install_dir
+ system git_command, "clone", "--quiet", "--no-checkout",
repo_cache_dir, install_dir
end
Dir.chdir install_dir do
- system @git, 'fetch', '--quiet', '--force', '--tags', install_dir
+ system git_command, "fetch", "--quiet", "--force", "--tags", install_dir
- success = system @git, 'reset', '--quiet', '--hard', rev_parse
+ success = system git_command, "reset", "--quiet", "--hard", rev_parse
- success &&=
- Gem::Util.silent_system @git, 'submodule', 'update',
- '--quiet', '--init', '--recursive' if @need_submodules
+ if @need_submodules
+ require "open3"
+ _, status = Open3.capture2e(git_command, "submodule", "update", "--quiet", "--init", "--recursive")
+
+ success &&= status.success?
+ end
success
end
@@ -117,13 +119,13 @@ class Gem::Source::Git < Gem::Source
def cache # :nodoc:
return unless @remote
- if File.exist? repo_cache_dir then
+ if File.exist? repo_cache_dir
Dir.chdir repo_cache_dir do
- system @git, 'fetch', '--quiet', '--force', '--tags',
- @repository, 'refs/heads/*:refs/heads/*'
+ system git_command, "fetch", "--quiet", "--force", "--tags",
+ @repository, "refs/heads/*:refs/heads/*"
end
else
- system @git, 'clone', '--quiet', '--bare', '--no-hardlinks',
+ system git_command, "clone", "--quiet", "--bare", "--no-hardlinks",
@repository, repo_cache_dir
end
end
@@ -132,7 +134,7 @@ class Gem::Source::Git < Gem::Source
# Directory where git gems get unpacked and so-forth.
def base_dir # :nodoc:
- File.join @root_dir, 'bundler'
+ File.join @root_dir, "bundler"
end
##
@@ -145,7 +147,7 @@ class Gem::Source::Git < Gem::Source
##
# Nothing to download for git gems
- def download full_spec, path # :nodoc:
+ def download(full_spec, path) # :nodoc:
end
##
@@ -154,16 +156,18 @@ class Gem::Source::Git < Gem::Source
def install_dir # :nodoc:
return unless File.exist? repo_cache_dir
- File.join base_dir, 'gems', "#{@name}-#{dir_shortref}"
+ File.join base_dir, "gems", "#{@name}-#{dir_shortref}"
end
- def pretty_print q # :nodoc:
- q.group 2, '[Git: ', ']' do
- q.breakable
- q.text @repository
+ def pretty_print(q) # :nodoc:
+ q.object_group(self) do
+ q.group 2, "[Git: ", "]" do
+ q.breakable
+ q.text @repository
- q.breakable
- q.text @reference
+ q.breakable
+ q.text @reference
+ end
end
end
@@ -171,7 +175,7 @@ class Gem::Source::Git < Gem::Source
# The directory where the git gem's repository will be cached.
def repo_cache_dir # :nodoc:
- File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}"
+ File.join @root_dir, "cache", "bundler", "git", "#{@name}-#{uri_hash}"
end
##
@@ -181,7 +185,7 @@ class Gem::Source::Git < Gem::Source
hash = nil
Dir.chdir repo_cache_dir do
- hash = Gem::Util.popen(@git, 'rev-parse', @reference).strip
+ hash = Gem::Util.popen(git_command, "rev-parse", @reference).strip
end
raise Gem::Exception,
@@ -200,43 +204,41 @@ class Gem::Source::Git < Gem::Source
return [] unless install_dir
Dir.chdir install_dir do
- Dir['{,*,*/*}.gemspec'].map do |spec_file|
+ Dir["{,*,*/*}.gemspec"].filter_map do |spec_file|
directory = File.dirname spec_file
file = File.basename spec_file
Dir.chdir directory do
spec = Gem::Specification.load file
- if spec then
+ if spec
spec.base_dir = base_dir
spec.extension_dir =
- File.join base_dir, 'extensions', Gem::Platform.local.to_s,
+ File.join base_dir, "extensions", Gem::Platform.local.to_s,
Gem.extension_api_version, "#{name}-#{dir_shortref}"
spec.full_gem_path = File.dirname spec.loaded_from if spec
end
spec
end
- end.compact
+ end
end
end
##
- # A hash for the git gem based on the git repository URI.
+ # A hash for the git gem based on the git repository Gem::URI.
def uri_hash # :nodoc:
- require 'digest' # required here to avoid deadlocking in Gem.activate_bin_path (because digest is a gem on 2.5+)
+ require_relative "../openssl"
normalized =
- if @repository =~ %r%^\w+://(\w+@)?% then
- uri = URI(@repository).normalize.to_s.sub %r%/$%,''
+ if @repository.match?(%r{^\w+://(\w+@)?})
+ uri = Gem::URI(@repository).normalize.to_s.sub %r{/$},""
uri.sub(/\A(\w+)/) { $1.downcase }
else
@repository
end
- Digest::SHA1.hexdigest normalized
+ OpenSSL::Digest::SHA1.hexdigest normalized
end
-
end
-