Merge pull request #70 from Gee-Bee/git-user-details

Respect user details of git repo.
This commit is contained in:
Karl Freeman 2014-11-21 17:08:03 +00:00
commit bd5e214614
2 changed files with 9 additions and 1 deletions

View file

@ -3,13 +3,15 @@ module Middleman
module Strategies module Strategies
module Git module Git
class Base class Base
attr_accessor :branch, :build_dir, :remote, :commit_message attr_accessor :branch, :build_dir, :remote, :commit_message, :user_name, :user_email
def initialize(build_dir, remote, branch, commit_message) def initialize(build_dir, remote, branch, commit_message)
self.branch = branch self.branch = branch
self.build_dir = build_dir self.build_dir = build_dir
self.remote = remote self.remote = remote
self.commit_message = commit_message self.commit_message = commit_message
self.user_name = `git config --get user.name`
self.user_email = `git config --get user.email`
end end
def process def process

View file

@ -19,12 +19,18 @@ module Middleman
unless File.exist?('.git') unless File.exist?('.git')
`git init` `git init`
`git remote add origin #{url}` `git remote add origin #{url}`
`git config user.name "#{self.user_name}"`
`git config user.name "#{self.user_email}"`
else else
# check if the remote repo has changed # check if the remote repo has changed
unless url == `git config --get remote.origin.url`.chop unless url == `git config --get remote.origin.url`.chop
`git remote rm origin` `git remote rm origin`
`git remote add origin #{url}` `git remote add origin #{url}`
end end
# check if the user name has changed
`git config user.name "#{self.user_name}"` unless self.user_name == `git config --get user.name`
# check if the user email has changed
`git config user.email "#{self.user_email}"` unless self.user_email == `git config --get user.email`
end end
end end