class Middleman::Deploy::Strategies::Git::Base

Attributes

branch[RW]
build_dir[RW]
commit_message[RW]
remote[RW]
user_email[RW]
user_name[RW]

Public Class Methods

new(build_dir, remote, branch, commit_message) click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 8
def initialize(build_dir, remote, branch, commit_message)
  self.branch         = branch
  self.build_dir      = build_dir
  self.remote         = remote
  self.commit_message = commit_message
  self.user_name      = `git config --get user.name`
  self.user_email     = `git config --get user.email`
end

Public Instance Methods

process() click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 17
def process
  raise NotImplementedError
end

Protected Instance Methods

add_signature_to_commit_message(base_message) click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 23
def add_signature_to_commit_message(base_message)
  signature = "#{Middleman::Deploy::PACKAGE} #{Middleman::Deploy::VERSION}"
  time      = "#{Time.now.utc}"

  "#{base_message} at #{time} by #{signature}"
end
checkout_branch() click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 30
def checkout_branch
  # if there is a branch with that name, switch to it, otherwise create a new one and switch to it
  if `git branch`.split("\n").any? { |b| b =~ /#{self.branch}/i }
    `git checkout #{self.branch}`
  else
    `git checkout -b #{self.branch}`
  end
end
commit_branch(options = '') click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 39
def commit_branch(options = '')
  message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit')

  run_or_fail("git add -A")
  run_or_fail("git commit --allow-empty -am \"#{message}\"")
  run_or_fail("git push #{options} origin #{self.branch}")
end

Private Instance Methods

run_or_fail(command) click to toggle source
# File lib/middleman-deploy/strategies/git/base.rb, line 48
def run_or_fail(command)
  system(command) || raise("ERROR running: #{command}")
end