Class: Gem::Source::Git
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Gem::Source
|
|
Instance Chain:
self,
::Gem::Source ,
Comparable
|
|
Inherits: |
Gem::Source
|
Defined in: | lib/rubygems/source/git.rb |
Overview
Constant Summary
::Gem::Source
- Inherited
Class Method Summary
-
.new(name, repository, reference, submodules = false) ⇒ Git
constructor
Creates a new git gem source for a gems from loaded from #repository at the given #reference.
::Gem::Source
- Inherited
.new | Creates a new |
Instance Attribute Summary
-
#name
readonly
The name of the gem created by this git gem.
-
#need_submodules
readonly
Does this repository need submodules checked out too?
-
#reference
readonly
The commit reference used for checking out this git gem.
-
#remote
rw
When false the cache for this repository will not be updated.
-
#repository
readonly
The git repository this gem is sourced from.
-
#root_dir
rw
The directory for cache and git gem installation.
::Gem::Source
- Inherited
#update_cache? | Returns true when it is possible and safe to update the cache directory. |
#uri | The URI this source will fetch gems from. |
Instance Method Summary
- #<=>(other)
-
#specs
Loads all gemspecs in the repository.
- #==(other) Internal use only
-
#base_dir
Internal use only
Directory where git gems get unpacked and so-forth.
-
#cache
Internal use only
Creates a local cache repository for the git gem.
-
#checkout
Internal use only
Checks out the files for the repository into the install_dir.
-
#dir_shortref
Internal use only
A short reference for use in git gem directories.
-
#download(full_spec, path)
Internal use only
Nothing to download for git gems.
-
#install_dir
Internal use only
The directory where the git gem will be installed.
- #pretty_print(q) Internal use only
-
#repo_cache_dir
Internal use only
The directory where the git gem’s repository will be cached.
-
#rev_parse
Internal use only
Converts the git reference for the repository into a commit hash.
-
#uri_hash
Internal use only
A hash for the git gem based on the git repository URI.
::Gem::Source
- Inherited
#<=> | Sources are ordered by installation preference. |
#cache_dir | Returns the local directory to write #uri to. |
#download | Downloads |
#fetch_spec | Fetches a specification for the given |
#load_specs | Loads |
#==, | |
#dependency_resolver_set | Returns a Set that can fetch specifications from this source. |
#eql? | Alias for #==. |
#hash, #pretty_print |
Constructor Details
.new(name, repository, reference, submodules = false) ⇒ Git
Creates a new git gem source for a gems from loaded from #repository at the given #reference. The #name is only used to track the repository back to a gem dependencies file, it has no real significance as a git repository may contain multiple gems. If submodules
is true, submodules will be checked out when the gem is installed.
# File 'lib/rubygems/source/git.rb', line 53
def initialize(name, repository, reference, submodules = false) super repository @name = name @repository = repository @reference = reference @need_submodules = submodules @remote = true @root_dir = Gem.dir @git = ENV['git'] || 'git' end
Instance Attribute Details
#name (readonly)
The name of the gem created by this git gem.
# File 'lib/rubygems/source/git.rb', line 19
attr_reader :name
#need_submodules (readonly)
Does this repository need submodules checked out too?
# File 'lib/rubygems/source/git.rb', line 44
attr_reader :need_submodules
#reference (readonly)
The commit reference used for checking out this git gem.
# File 'lib/rubygems/source/git.rb', line 24
attr_reader :reference
#remote (rw)
When false the cache for this repository will not be updated.
# File 'lib/rubygems/source/git.rb', line 29
attr_accessor :remote
#repository (readonly)
The git repository this gem is sourced from.
# File 'lib/rubygems/source/git.rb', line 34
attr_reader :repository
#root_dir (rw)
The directory for cache and git gem installation
# File 'lib/rubygems/source/git.rb', line 39
attr_accessor :root_dir
Instance Method Details
#<=>(other)
[ GitHub ]#==(other)
# File 'lib/rubygems/source/git.rb', line 80
def ==(other) # :nodoc: super and @name == other.name and @repository == other.repository and @reference == other.reference and @need_submodules == other.need_submodules end
#base_dir
Directory where git gems get unpacked and so-forth.
# File 'lib/rubygems/source/git.rb', line 134
def base_dir # :nodoc: File.join @root_dir, 'bundler' end
#cache
Creates a local cache repository for the git gem.
# File 'lib/rubygems/source/git.rb', line 117
def cache # :nodoc: return unless @remote if File.exist? repo_cache_dir Dir.chdir repo_cache_dir do system @git, 'fetch', '--quiet', '--force', '--tags', @repository, 'refs/heads/*:refs/heads/*' end else system @git, 'clone', '--quiet', '--bare', '--no-hardlinks', @repository, repo_cache_dir end end
#checkout
Checks out the files for the repository into the install_dir.
# File 'lib/rubygems/source/git.rb', line 91
def checkout # :nodoc: cache return false unless File.exist? repo_cache_dir unless File.exist? install_dir system @git, 'clone', '--quiet', '--no-checkout', repo_cache_dir, install_dir end Dir.chdir install_dir do system @git, 'fetch', '--quiet', '--force', '--tags', install_dir success = system @git, 'reset', '--quiet', '--hard', rev_parse success &&= Gem::Util.silent_system @git, 'submodule', 'update', '--quiet', '--init', '--recursive' if @need_submodules success end end
#dir_shortref
A short reference for use in git gem directories
# File 'lib/rubygems/source/git.rb', line 141
def dir_shortref # :nodoc: rev_parse[0..11] end
#download(full_spec, path)
Nothing to download for git gems
# File 'lib/rubygems/source/git.rb', line 148
def download(full_spec, path) # :nodoc: end
#install_dir
The directory where the git gem will be installed.
# File 'lib/rubygems/source/git.rb', line 154
def install_dir # :nodoc: return unless File.exist? repo_cache_dir File.join base_dir, 'gems', "#{@name}-#{dir_shortref}" end
#pretty_print(q)
# File 'lib/rubygems/source/git.rb', line 160
def pretty_print(q) # :nodoc: q.group 2, '[Git: ', ']' do q.breakable q.text @repository q.breakable q.text @reference end end
#repo_cache_dir
The directory where the git gem’s repository will be cached.
# File 'lib/rubygems/source/git.rb', line 173
def repo_cache_dir # :nodoc: File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}" end
#rev_parse
Converts the git reference for the repository into a commit hash.
#specs
Loads all gemspecs in the repository
# File 'lib/rubygems/source/git.rb', line 197
def specs checkout return [] unless install_dir Dir.chdir install_dir do Dir['{,*,*/*}.gemspec'].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.compact end end
#uri_hash
A hash for the git gem based on the git repository URI.
# File 'lib/rubygems/source/git.rb', line 227
def uri_hash # :nodoc: require 'digest' # required here to avoid deadlocking in Gem.activate_bin_path (because digest is a gem on 2.5+) normalized = if @repository =~ %r%^\w://(\w@)?% uri = URI(@repository).normalize.to_s.sub %r%/$%,'' uri.sub(/\A(\w+)/) { $1.downcase } else @repository end Digest::SHA1.hexdigest normalized end