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
@!attribute [r] repo
@api private
Public Class Methods
@abstract @return [Object] The concrete bare repository implementation to use for
interacting with the cached Git repository.
# File lib/r10k/git/cache.rb, line 41 def self.bare_repository raise NotImplementedError end
Generate a new instance with the given remote or return an existing object with the given remote. This should be used over ::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 34 def self.generate(remote) instance_cache.generate(remote) end
@api private
# File lib/r10k/git/cache.rb, line 24 def self.instance_cache @instance_cache end
@param remote [String] The URL of the Git remote URL to cache.
# File lib/r10k/git/cache.rb, line 64 def initialize(remote) @remote = remote @repo = self.class.bare_repository.new(settings[:cache_root], sanitized_dirname) end
Public Instance Methods
@!attribute [r] path
@deprecated @return [String] The path to the git cache repository
# File lib/r10k/git/cache.rb, line 54 def path logger.warn "#{self.class}#path is deprecated; use #git_dir" git_dir end
@api private
# File lib/r10k/git/cache.rb, line 96 def reset! @synced = false end
# File lib/r10k/git/cache.rb, line 69 def sync if !@synced sync! @synced = true end end
# File lib/r10k/git/cache.rb, line 80 def sync! if cached? @repo.fetch else logger.debug1 "Creating new git cache for #{@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
# File lib/r10k/git/cache.rb, line 76 def synced? @synced end
Private Instance Methods
Reformat the remote name into something that can be used as a directory
# File lib/r10k/git/cache.rb, line 105 def sanitized_dirname @remote.gsub(/[^@\w\.-]/, '-') end