class R10K::Git::Rugged::ThinRepository

Public Class Methods

new(basedir, dirname, cache_repo) click to toggle source
# File lib/r10k/git/rugged/thin_repository.rb, line 6
def initialize(basedir, dirname, cache_repo)
  @cache_repo = cache_repo

  super(basedir, dirname)
end

Public Instance Methods

cache() click to toggle source

@return [String] The cache remote URL

# File lib/r10k/git/rugged/thin_repository.rb, line 60
def cache
  with_repo { |repo| repo.config['remote.cache.url'] }
end
checkout(ref, opts = {}) click to toggle source
# File lib/r10k/git/rugged/thin_repository.rb, line 47
def checkout(ref, opts = {})
  super(@cache_repo.resolve(ref), opts)
end
clone(remote, opts = {}) click to toggle source

Clone this git repository

@param remote [String] The Git remote to clone @param opts [Hash]

@options opts [String] :ref The git ref to check out on clone

@return [void]

# File lib/r10k/git/rugged/thin_repository.rb, line 20
def clone(remote, opts = {})
  logger.debug1 { "Cloning '#{remote}' into #{@path}" }
  @cache_repo.sync

  cache_objects_dir = @cache_repo.objects_dir.to_s

  # {Rugged::Repository.clone_at} doesn't support :alternates, which
  # completely breaks how thin repositories need to work. To circumvent
  # this we manually create a Git repository, set up git remotes, and
  # update 'objects/info/alternates' with the path. We don't actually
  # fetch any objects because we don't need them, and we don't actually
  # use any refs in this repository so we skip all those steps.
  ::Rugged::Repository.init_at(@path.to_s, false)
  @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => [cache_objects_dir])
  alternates << cache_objects_dir

  with_repo do |repo|
    config = repo.config
    config['remote.origin.url']    = remote
    config['remote.origin.fetch']  = '+refs/heads/*:refs/remotes/origin/*'
    config['remote.cache.url']     = @cache_repo.git_dir.to_s
    config['remote.cache.fetch']   = '+refs/heads/*:refs/remotes/cache/*'
  end

  checkout(opts.fetch(:ref, 'HEAD'))
end
fetch(remote = 'cache') click to toggle source

Fetch refs and objects from one of the Git remotes

@param remote [String] The remote to fetch, defaults to 'cache' @return [void]

# File lib/r10k/git/rugged/thin_repository.rb, line 55
def fetch(remote = 'cache')
  super(remote)
end
tracked_paths(ref="HEAD") click to toggle source
# File lib/r10k/git/rugged/thin_repository.rb, line 64
def tracked_paths(ref="HEAD")
  with_repo do |repo|
    commit = repo.rev_parse(ref)

    unless commit && commit.tree
      raise R10K::Error.new("Unable to resolve '#{ref}' to a valid commit in repo #{@path}")
    end

    commit.tree.walk(:postorder).collect do |root, entry|
      root.empty? ? entry[:name] : File.join(root, entry[:name])
    end
  end
end

Private Instance Methods

setup_rugged_repo() click to toggle source

Override the parent class repo setup so that we can make sure the alternates file is up to date before we create the Rugged::Repository object, which reads from the alternates file.

# File lib/r10k/git/rugged/thin_repository.rb, line 82
def setup_rugged_repo
  entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
  if entry_added
    logger.debug2 { _("Updated repo %{path} to include alternate object db path %{objects_dir}") % {path: @path, objects_dir: @cache_repo.objects_dir} }
  end
  super
end