Sha256: 949e0746d55ba345364371c8419c5027d5f2ef44915bb08b7fe8452bfa7b71b7

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

require 'git'

module Stevenson
  module Template
    class Git < Base
      attr_reader :template_url, :options

      def initialize(template_url, options)
        @template_url, @options = template_url, options
      end

      def local_directory
        @_local_directory ||= Dir.mktmpdir.tap do |dir|
          # Clone the repo to a temporary directory for later use
          ::Git.clone(template_url, dir).tap do |repo|
            # Switch_branch if set
            repo.checkout(options[:branch]) if options.has_key?(:branch)
          end
        end
      rescue ::Git::GitExecuteError
        # If the given repo URL is not valid, raise an exception
        raise InvalidTemplateException.new('Failed to clone the repository')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stevenson-2.1.0 lib/stevenson/templates/git.rb
stevenson-2.0.0 lib/stevenson/templates/git.rb