Sha256: 254ee2047d892dd0e40251b6ee7c2392b3d267951a8b803a9a2f2e660de747ad

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

require 'librarian/source/git'
require 'librarian/puppet/source/local'

module Librarian
  module Source
    class Git
      class Repository
        def hash_from(remote, reference)
          branch_names = remote_branch_names[remote]
          if branch_names.include?(reference)
            reference = "#{remote}/#{reference}"
          end

          command = %W(rev-parse #{reference}^{commit} --quiet)
          run!(command, :chdir => true).strip
        end
      end
    end
  end

  module Puppet
    module Source
      class Git < Librarian::Source::Git
        include Local
        include Librarian::Puppet::Util

        def cache!
          return vendor_checkout! if vendor_cached?

          if environment.local?
            raise Error, "Could not find a local copy of #{uri} at #{sha}."
          end

          super

          cache_in_vendor(repository.path) if environment.vendor?
        end

        def vendor_tgz
          environment.vendor_source + "#{sha}.tar.gz"
        end

        def vendor_cached?
          vendor_tgz.exist?
        end

        def vendor_checkout!
          repository.path.rmtree if repository.path.exist?
          repository.path.mkpath

          run!(%W{tar xzf #{vendor_tgz}}, :chdir => repository.path.to_s)

          repository_cached!
        end

        def cache_in_vendor(tmp_path)
          run!(%W{git archive #{sha} | gzip > #{vendor_tgz}}, :chdir => tmp_path.to_s)
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
librarian-puppet-1.0.1 lib/librarian/puppet/source/git.rb
librarian-puppet-1.0.0 lib/librarian/puppet/source/git.rb
librarian-puppet-0.9.17 lib/librarian/puppet/source/git.rb
librarian-puppet-0.9.16 lib/librarian/puppet/source/git.rb