class Gem::Source::Git
def <=>(other)
def <=>(other) case other when Gem::Source::Git then 0 when Gem::Source::Vendor, Gem::Source::Lock then -1 when Gem::Source then 1 end end
def ==(other) # :nodoc:
def ==(other) # :nodoc: super && @name == other.name && @repository == other.repository && @reference == other.reference && @need_submodules == other.need_submodules end
def base_dir # :nodoc:
def base_dir # :nodoc: File.join @root_dir, "bundler" end
def cache # :nodoc:
def cache # :nodoc: return unless @remote if File.exist? repo_cache_dir Dir.chdir repo_cache_dir do system git_command, "fetch", "--quiet", "--force", "--tags", @repository, "refs/heads/*:refs/heads/*" end else system git_command, "clone", "--quiet", "--bare", "--no-hardlinks", @repository, repo_cache_dir end end
def checkout # :nodoc:
def checkout # :nodoc: cache return false unless File.exist? repo_cache_dir 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_command, "fetch", "--quiet", "--force", "--tags", install_dir success = system git_command, "reset", "--quiet", "--hard", rev_parse if @need_submodules require "open3" _, status = Open3.capture2e(git_command, "submodule", "update", "--quiet", "--init", "--recursive") success &&= status.success? end success end end
def dir_shortref # :nodoc:
def dir_shortref # :nodoc: rev_parse[0..11] end
def download(full_spec, path) # :nodoc:
def download(full_spec, path) # :nodoc: end
def git_command
def git_command ENV.fetch("git", "git") end
def initialize(name, repository, reference, submodules = false)
def initialize(name, repository, reference, submodules = false) require_relative "../uri" @uri = Gem::Uri.parse(repository) @name = name @repository = repository @reference = reference || "HEAD" @need_submodules = submodules @remote = true @root_dir = Gem.dir end
def install_dir # :nodoc:
def install_dir # :nodoc: return unless File.exist? repo_cache_dir File.join base_dir, "gems", "#{@name}-#{dir_shortref}" end
def pretty_print(q) # :nodoc:
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 end end end
def repo_cache_dir # :nodoc:
def repo_cache_dir # :nodoc: File.join @root_dir, "cache", "bundler", "git", "#{@name}-#{uri_hash}" end
def rev_parse # :nodoc:
def rev_parse # :nodoc: hash = nil Dir.chdir repo_cache_dir do hash = Gem::Util.popen(git_command, "rev-parse", @reference).strip end raise Gem::Exception, "unable to find reference #{@reference} in #{@repository}" unless $?.success? hash end
def specs
def specs checkout return [] unless install_dir Dir.chdir install_dir do 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 spec.base_dir = base_dir spec.extension_dir = 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 end end
def uri_hash # :nodoc:
def uri_hash # :nodoc: require_relative "../openssl" normalized = if @repository.match?(%r{^\w+://(\w+@)?}) uri = Gem::URI(@repository).normalize.to_s.sub %r{/$},"" uri.sub(/\A(\w+)/) { $1.downcase } else @repository end OpenSSL::Digest::SHA1.hexdigest normalized end