Deploying branches with Capistrano
Posted Friday, May 30, 2008This morning I had occasion to deploy a branch of a git repository to a staging server but hadn’t the foggiest idea how. A quick search through the capistrano source code revealed that I could use set :branch "branch_name" in my deploy script. I tried it and it worked. I then figured I would need to make a similar change across all my branches. Of course, I’m a lazy sod and wondered if there wasn’t a better way.
If you’re not familiar with git, the output of the git branch command is a list of branches with an asterisk marking the one currently checked out on your local machine. For example:
> git branch
* drupal_authentication
fragment_caching
master
So, I figured, what if I just parsed the output and searched for the branch marked as current:
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
Now I’m able to deploy whatever branch is current on my local machine from a single, shared, deploy script.
- Later: Quickly Migrate all database times to UTC
- Earlier: JavaScript Date Helpers
About Simon
Husband, Father, One-time Entrepreneur.
Aka Haruki Zaemon. Aka Sampy.
In my younger years I wanted to save the world; now I'm happy solving bigger problems than I create.
If I didn't need to work I'd be teaching Aikido and spending all my free time with my amazing wife and two children in Woodend, Victoria, Australia.
Books
Beginning Algorithms
with James Ross

COMMENTS
blog comments powered by Disqus