class Begin::GitTemplate
Encapsulates the logic for templates that are installed as cloned git repositories on the user's machine.
Public Class Methods
format_git_error_message(e)
click to toggle source
# File lib/begin/template.rb, line 153 def self.format_git_error_message(e) partition = e.message.partition('2>&1:') partition[2] end
install(source_uri, path)
click to toggle source
# File lib/begin/template.rb, line 158 def self.install(source_uri, path) Git.clone(source_uri, path.to_s) Output.success 'Template source was successfully git cloned' GitTemplate.new path rescue Git::GitExecuteError => e raise format_git_error_message(e) end
new(path)
click to toggle source
Calls superclass method
Begin::Template::new
# File lib/begin/template.rb, line 148 def initialize(path) super path @repository = Git.open(path.to_s) end
Public Instance Methods
check_pending_changes()
click to toggle source
# File lib/begin/template.rb, line 194 def check_pending_changes not_added = @repository.status.added.empty? not_deleted = @repository.status.deleted.empty? not_changed = @repository.status.changed.empty? message = 'Local repository contains modified / staged files. ' \ "Please fix: #{@path}" raise message unless not_added && not_deleted && not_changed end
check_repository()
click to toggle source
# File lib/begin/template.rb, line 170 def check_repository @repository.revparse('HEAD') if @repository.current_branch.include? 'detached' raise "HEAD is detached in local repository. Please fix: #{@path}" end rescue Git::GitExecuteError => e error = "HEAD is not valid in local repository. Please fix: #{@path}\n" error += format_git_error_message(e) raise error end
check_tracking_branch()
click to toggle source
# File lib/begin/template.rb, line 181 def check_tracking_branch @repository.revparse('@{u}') rescue raise "Local branch '#{@repository.current_branch}' does not track " \ "an upstream branch in local repository: #{@path}" end
check_untracked_changes()
click to toggle source
# File lib/begin/template.rb, line 188 def check_untracked_changes message = 'Local repository contains untracked changes. ' \ "Please fix: #{@path}" raise message unless @repository.status.untracked.empty? end
uninstall()
click to toggle source
# File lib/begin/template.rb, line 166 def uninstall FileUtils.rm_rf @path end
update()
click to toggle source
# File lib/begin/template.rb, line 203 def update check_repository check_tracking_branch check_untracked_changes check_pending_changes begin @repository.pull rescue Git::GitExecuteError => e raise format_git_error_message(e) end end