Angelos Orfanakos

Abort Capistrano deploy with unpushed Git commits

To have Capistrano abort the deploy when there are unpushed commits in Git, add the following block in config/deploy.rb:

before :deploy, :abort_with_unpushed_changes do
  run_locally do
    if !test('git merge-base --is-ancestor @ @{u}')
      error 'Push changes first'
      raise 'Unpushed changes'
    end
  end
end