Since mina uses local deployment code, it would be useful if before deployments a check would run ensuring both local branch and origin branch (on github) are in sync.
So far I have solved this by defining a checker method in deploy.rb
def heads_match?
`git fetch`
if `git diff #{branch} origin/#{branch}`.size < 1
puts "Yay, HEADs match"
return true
else
puts "Noo, Branches are not in sync"
return false
end
end
And calling in the deploy task
task :deploy => :environment do
if heads_match?
deploy do
# Rest of deployment code here
end
end
end
The problem is that git fetch
takes several seconds and is probably overhead if I could get by with checking whether last commits of local branch and remote branch are the same.
How to check local and remote branch last commit equality quickly?