module Batali::Git
Helper module for git interactions
Public Class Methods
included(klass)
click to toggle source
Load attributes into class
# File lib/batali/git.rb, line 48 def self.included(klass) klass.class_eval do attribute :url, String, :required => true, :equivalent => true attribute :ref, String, :required => true, :equivalent => true end end
Public Instance Methods
base_path()
click to toggle source
@return [String] path to repository clone
# File lib/batali/git.rb, line 10 def base_path Utility.join_path(cache_path, Base64.urlsafe_encode64(url)) end
clone_repository()
click to toggle source
Clone the repository to the local machine
@return [TrueClass]
# File lib/batali/git.rb, line 17 def clone_repository if File.directory?(base_path) repo = ::Git.open(base_path) repo.checkout("master") repo.pull repo.fetch else ::Git.clone(url, base_path) end true end
ref_dup()
click to toggle source
Duplicate reference and store
@return [String] commit SHA @note this will update ref to SHA
# File lib/batali/git.rb, line 33 def ref_dup git = ::Git.open(base_path) git.checkout(ref) git.pull("origin", ref) self.ref = git.log.first.sha self.path = Utility.join_path(cache_path, "git", ref) unless File.directory?(path) FileUtils.mkdir_p(path) FileUtils.cp_r(Utility.join_path(base_path, "."), path) FileUtils.rm_rf(Utility.join_path(path, ".git")) end path end