Report abuse


			
################################################################################# 
# CAPISTRANO TAG SUPPORT
# Provides the ability for capistrano to check out into a named tags directory
# Also makes sure that the releases array is properly ordered (not by name but by
# modification date). This enables proper rollbacks.
#
# Author: yan@planyp.us
#
# Requirements: 
#  set :tag_root,   "tags"          # where your tags are in relation to trunk/..
#
# Usage: TAG=v1.9 cap production deploy
#
#################################################################################

# Note: you must set :repo_root to the root of your repository (before /trunk)
# You may overwrite :tag_root to be 'branches' or 'tags', etc

set :tag_root,        "branches" #required for svn tag support

if ENV['TAG']
  # Redefine how capistrano sorts its releases, instead of by name
  # Sort by modification date, so that we know how to rollback
  set(:releases)  { capture("ls -xt #{releases_path}").split.reverse }    
  set :tag_root,  "/#{tag_root}" unless tag_root =~ %r{^/}
  set :repository, "#{repository.gsub('/trunk', tag_root)}/#{ENV['TAG']}"      
  set :release_name,  ENV['TAG']  

  # Make capistrano write the proper revision 
  # into the REVISION file.
  require 'capistrano/recipes/deploy/scm/subversion'    
  Capistrano::Deploy::SCM::Subversion.class_eval do
    def query_revision(revision)
      return revision if revision =~ /^\d+$/
      result = yield(scm(:info, repository, authentication, "-r#{revision}"))
      YAML.load(result)['Last Changed Rev']
    end
  end
end