Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

Deploy The Right Code

Every once in a while I used to forget to push my code to GitHub before deploying. It was harmless but annoying.

These days I prevent it with the following Capistrano snippet:

namespace :deploy do
  desc 'Check we are deploying the latest code'
  task :check_revision, :roles => :app do
    sha = lambda { |branch|  `git rev-parse #{branch}` }
    branch = fetch :branch, 'master'
    unless sha[branch] == sha["origin/#{branch}"]
      srsly = Capistrano::CLI.ui.ask("#{branch} does not match origin/#{branch}.  Deploy anyway? [y/n]")
      exit(1) unless srsly == 'y'
  before 'deploy', 'deploy:check_revision'

Problem solved.

Andrew Stewart • 13 April 2012 • Deployment
You can reach me by email or on Twitter.