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

    # libgit2/rugged doesn't support cloning a repository and providing an
    # alternate object database, making the handling of :alternates a noop.
    # Unfortunately this means that this method can't really use alternates
    # and running the clone will duplicate all objects in the specified
    # repository. However alternate databases can be handled when an existing
    # repository is loaded, so loading a cloned repo will correctly use
    # alternate object database.
    options = {:credentials => credentials}
    options.merge!(:alternates => [File.join(opts[:reference], 'objects')]) if opts[:reference]
    @_rugged_repo = ::Rugged::Repository.clone_at(remote, @path.to_s, options)

    if opts[:reference]
      alternates << File.join(opts[:reference], 'objects')
    end

    if opts[:ref]
      # todo:  always check out something; since we're fetching a repository we
      # won't populate the working directory.
      checkout(opts[:ref])
    end
  rescue Rugged::SshError, Rugged::NetworkError => e
    raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
  end