2014-01-16 15:25:40 +01:00
|
|
|
module Middleman
|
|
|
|
module Deploy
|
|
|
|
module Strategies
|
|
|
|
module Git
|
|
|
|
class Base
|
2014-07-16 10:56:58 +02:00
|
|
|
attr_accessor :branch, :build_dir, :remote, :commit_message, :user_name, :user_email
|
2014-01-16 15:25:40 +01:00
|
|
|
|
2014-05-24 20:35:14 +02:00
|
|
|
def initialize(build_dir, remote, branch, commit_message)
|
|
|
|
self.branch = branch
|
|
|
|
self.build_dir = build_dir
|
|
|
|
self.remote = remote
|
|
|
|
self.commit_message = commit_message
|
2014-07-16 10:56:58 +02:00
|
|
|
self.user_name = `git config --get user.name`
|
|
|
|
self.user_email = `git config --get user.email`
|
2014-01-16 15:25:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def process
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def commit_branch(options='')
|
2014-05-24 20:35:14 +02:00
|
|
|
message = self.commit_message ? self.commit_message : add_signature_to_commit_message('Automated commit')
|
2014-01-16 15:25:40 +01:00
|
|
|
|
|
|
|
`git add -A`
|
|
|
|
`git commit --allow-empty -am "#{message}"`
|
|
|
|
`git push #{options} origin #{self.branch}`
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|