Refactoring
- Create a class per method - Create a class per git strategy - Extract USAGE into a file - Refactor git and ftp/sftp methods
This commit is contained in:
parent
064b17add2
commit
11860dd930
12 changed files with 483 additions and 263 deletions
54
lib/middleman-deploy/strategies/git/force_push.rb
Normal file
54
lib/middleman-deploy/strategies/git/force_push.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
module Middleman
|
||||
module Deploy
|
||||
module Strategies
|
||||
module Git
|
||||
class ForcePush < Base
|
||||
|
||||
def process
|
||||
Dir.chdir(self.build_dir) do
|
||||
add_remote_url
|
||||
checkout_branch
|
||||
commit_branch('-f')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_remote_url
|
||||
url = get_remote_url
|
||||
|
||||
unless File.exists?('.git')
|
||||
`git init`
|
||||
`git remote add origin #{url}`
|
||||
else
|
||||
# check if the remote repo has changed
|
||||
unless url == `git config --get remote.origin.url`.chop
|
||||
`git remote rm origin`
|
||||
`git remote add origin #{url}`
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_remote_url
|
||||
remote = self.remote
|
||||
url = remote
|
||||
|
||||
# check if remote is not a git url
|
||||
unless remote =~ /\.git$/
|
||||
url = `git config --get remote.#{url}.url`.chop
|
||||
end
|
||||
|
||||
# if the remote name doesn't exist in the main repo
|
||||
if url == ''
|
||||
puts "Can't deploy! Please add a remote with the name '#{remote}' to your repo."
|
||||
exit
|
||||
end
|
||||
|
||||
url
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue