Sha256: 8cbb81227e4266fe8892dc4e4de870d7b1d9cc2d5654f7c32c657967bce90820

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Rip
  class GitPackage < Package
    include Sh::Git

    handles "file://", "git://", '.git'

    memoize :name
    def name
      source.split('/').last.chomp('.git')
    end

    def version
      return @version if @version

      fetch!
      Dir.chdir cache_path do
        @version = git_revparse('origin/master')[0,7]
      end
    end

    def exists?
      case source
      when /^file:/
        file_exists?
      when /^git:/
        remote_exists?
      when /\.git$/
        file_exists? || remote_exists?
      else
        false
      end
    end

    def fetch!
      if File.exists? cache_path
        Dir.chdir cache_path do
          git_fetch('origin')
        end
      else
        git_clone(source, cache_name)
      end
    end

    def unpack!
      Dir.chdir cache_path do
        git_reset_hard(version)
        git_submodule_init
        git_submodule_update
      end
    end

  private
    def file_exists?
      File.exists? File.join(source.sub('file://', ''), '.git')
    end

    def remote_exists?
      out = git_ls_remote(source, @version)
      out.include? @version || 'HEAD'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rip-0.0.1 lib/rip/packages/git_package.rb