# File lib/r10k/git/stateful_repository.rb, line 32
  def sync
    @cache.sync if sync_cache?

    sha = @cache.resolve(@ref)

    if sha.nil?
      raise R10K::Git::UnresolvableRefError.new("Unable to sync repo to unresolvable ref '#{@ref}'", :git_dir => @repo.git_dir)
    end

    case status
    when :absent
      logger.debug { "Cloning #{@repo.path} and checking out #{@ref}" }
      @repo.clone(@remote, {:ref => sha})
    when :mismatched
      logger.debug { "Replacing #{@repo.path} and checking out #{@ref}" }
      @repo.path.rmtree
      @repo.clone(@remote, {:ref => sha})
    when :outdated
      logger.debug { "Updating #{@repo.path} to #{@ref}" }
      @repo.checkout(sha)
    else
      logger.debug { "#{@repo.path} is already at Git ref #{@ref}" }
    end
  end