1 before 'deploy:update_code' do
2 local_branch = `git branch | egrep '^\\*' | cut -d' ' -f2`.strip
3 remote_commit = `git ls-remote '#{fetch(:repository)}' '#{local_branch}'`.strip.split.first
4 local_commit = `git show -s --format=format:%H`.strip
5 if !local_branch.match(/^(master$|production)/)
6 abort 'You cannot deploy unless your branch is called "master" or "production*"'
8 if local_commit != remote_commit
9 puts "Current branch is #{local_branch}"
10 puts "Last commit is #{local_commit} here"
11 puts "Last commit is #{remote_commit} on #{local_branch} at #{fetch(:repository)}"
12 abort "You cannot deploy unless HEAD = a branch = head of remote branch with same name."
14 puts "Setting deploy branch to #{local_branch}"
15 set :branch, local_branch