Skip to content

Instantly share code, notes, and snippets.

@bluefuton
Created May 20, 2011 10:31
Show Gist options
  • Save bluefuton/982691 to your computer and use it in GitHub Desktop.
Save bluefuton/982691 to your computer and use it in GitHub Desktop.
Capistrano task to remove the cached-copy folder when the SVN URL of the cached-copy is different to the SVN URL of the deployed code
# When you switch SVN branches for deployment, Capistrano doesn't detect the change and
# simply does an 'svn up' on whatever branch you had previously deployed.
# This task checks if the cached copy's SVN URL matches the SVN URL you're deploying,
# and removes the cached copy if it doesn't match
namespace :cached_copy do
task :check do
cached_copy_path = "#{shared_path}/cached-copy"
# Does the cached copy exist?
cached_copy_exists = capture("if [ -d '#{cached_copy_path}' ]; then echo '1'; fi")
if cached_copy_exists.to_i == 1
# Get the SVN URL of the cached copy
cached_copy_svn_url = capture("svn info #{cached_copy_path} | grep URL | cut -c6-")
# Are the cached copy and deployment SVN URLs different?
if cached_copy_svn_url.chomp! != repository
puts "Cached copy SVN URL is " + cached_copy_svn_url
puts "Repository URL is " + repository
puts "Removing cached copy"
run "rm -fR #{cached_copy_path}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment