lib/stevenson/templates/git.rb in stevenson-1.0.1 vs lib/stevenson/templates/git.rb in stevenson-2.0.0

- old
+ new

@@ -1,27 +1,26 @@ require 'git' -require 'stevenson/templates/base' module Stevenson - module Templates - class GitTemplate < Base - def initialize(template_url) - # Create a temporary directory to clone the repo at - Dir.mktmpdir do |dir| - # Clone the repo to a temporary directory for later use - Git.clone template_url, File.join(dir, 'repo') + module Template + class Git < Base + attr_reader :template_url, :options - # Call the super, thereby assigning the @path - super File.join(dir, 'repo') - end - rescue Git::GitExecuteError => e - # If the given URL is not valid, raise an exception and cleanup - raise InvalidTemplateException.new('Failed to clone the repository') + def initialize(template_url, options) + @template_url, @options = template_url, options end - def switch_branch(branch) - repo = Git::Base.open(path) - repo.checkout(branch) + 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