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 41
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 ::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
instance_cache() click to toggle source

@api private

# File lib/r10k/git/cache.rb, line 24
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 64
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 54
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 96
def reset!
  @synced = false
end
sync() click to toggle source
# File lib/r10k/git/cache.rb, line 69
def sync
  if !@synced
    sync!
    @synced = true
  end
end
sync!() click to toggle source
# File lib/r10k/git/cache.rb, line 80
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 76
def synced?
  @synced
end

Private Instance Methods

sanitized_dirname() click to toggle source

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