Saturday, January 17, 2009

git project deployment with capistrano

I just sent a patch to the capistrano mailing list to update the git scm class to perform true exports using git archive rather than cloning the whole repository and then removing the git files after checkout. The main advantage of this is the elimination of the unnecessary transfer of all those git objects. However, an added feature is that git archive allows exporting specific paths from the repository, which appears to be a feature requested from time to time. With the above patch, one can configure capistrano like this:


set :scm, :git # of course
set :deploy_via, :export
set :project, [insert-your-repo-subdir-here]


Which will cause capistrano to execute something along the lines of


git archive --format=tar --remote=[your-repo-path] \
master:[your-subdir-path]


to deploy your application, cool huh? The catch, well, not all repositories (notably github) support the archive command via the git protocol, but if you're hosting your own repository or connecting by ssh, this will work just fine.