Managing Git Submodules in Rails

I’ve started work on a new project called Travel & Gather, where I am a co-founder partnering with two other great guys, Jake Stutzman and John Moorhead. We’ll be releasing a beta in a few months and if you follow the link, you can sign up to be notified when it releases and be part of our beta testing.

While setting up the base of this project, which is going to be written in Ruby on Rails, I needed a way to manage git submodules easier than cd-ing into the directory and doing a git remote update and then merging with the master branch. Writing a rake task was the first thing I thought of, but if I wanted to add another plugin, or remove a plugin, then I have some tasks to edit – because I have task :all in there as well.

Each task, for the plugins, shares the same functionality, so to DRY things up, I’ve added a hash stored in @plugins. This hash defines the name and directory filename for the plugin. I then iterate through the hash to define each task on the fly and for the all task I setup a normal rake task that iterates through the hash installing each plugin. Each rake task uses a method to do the cd-ing, update, and merging. Pretty simple and DRY’s up the code pretty nicely while still being readable.

Here’s the code, which hosted over at Github using their gist pastie system.