class R10K::Git::Cache
Cache Git repository mirrors for object database reuse.
This implements most of the behavior needed for Git repo caching, but needs to have a specific Git bare repository provided. Subclasses should implement the {bare_repository} method.
@abstract @see man git-clone(1)
Attributes
repo[R]
@!attribute [r] repo
@api private
Public Class Methods
bare_repository()
click to toggle source
@abstract @return [Object] The concrete bare repository implementation to use for
interacting with the cached Git repository.
# File lib/r10k/git/cache.rb, line 43 def self.bare_repository raise NotImplementedError end
generate(remote)
click to toggle source
Generate a new instance with the given remote or return an existing object with the given remote. This should be used over R10K::Git::Cache.new.
@api public @param remote [String] The git remote to cache @return [R10K::Git::Cache] The requested cache object.
# File lib/r10k/git/cache.rb, line 36 def self.generate(remote) instance_cache.generate(remote) end
instance_cache()
click to toggle source
@api private
# File lib/r10k/git/cache.rb, line 26 def self.instance_cache @instance_cache end
new(remote)
click to toggle source
@param remote [String] The URL of the Git remote URL to cache.
# File lib/r10k/git/cache.rb, line 66 def initialize(remote) @remote = remote @repo = self.class.bare_repository.new(settings[:cache_root], sanitized_dirname) end
Public Instance Methods
path()
click to toggle source
@!attribute [r] path
@deprecated @return [String] The path to the git cache repository
# File lib/r10k/git/cache.rb, line 56 def path logger.warn _("%{class}#path is deprecated; use #git_dir") % {class: self.class} git_dir end
reset!()
click to toggle source
@api private
# File lib/r10k/git/cache.rb, line 98 def reset! @synced = false end
sanitized_dirname()
click to toggle source
Calls superclass method
R10K::Util::Cacheable#sanitized_dirname
# File lib/r10k/git/cache.rb, line 104 def sanitized_dirname @sanitized_dirname ||= super(@remote) end
sync()
click to toggle source
# File lib/r10k/git/cache.rb, line 71 def sync if !@synced sync! @synced = true end end
sync!()
click to toggle source
# File lib/r10k/git/cache.rb, line 82 def sync! if cached? @repo.fetch else logger.debug1 _("Creating new git cache for %{remote}") % {remote: @remote.inspect} # TODO extract this to an initialization step if !File.exist?(settings[:cache_root]) FileUtils.mkdir_p settings[:cache_root] end @repo.clone(@remote) end end
synced?()
click to toggle source
# File lib/r10k/git/cache.rb, line 78 def synced? @synced end