Archive for June, 2008

CSV templating made easy in Rails

Friday, June 27th, 2008

CSV Builder is a simple little Rails (v2.1) plugin that makes it easy to write templates to generate CSV formatted output from your Rails application.

It does this by providing a little bit of plumbing gubbins to make a custom template handler from the FasterCSV gem.

So if you want to export data in CSV format from your rails app then install it like this

sudo gem install fastercsv
./script/plugin install git://github.com/econsultancy/csv_builder.git

This plugin was developed as part of project that I have been working on with Econsultancy.com.

Using Git with subversion: Part II (Practice)

Friday, June 27th, 2008

More tips on how to use Git with a Subversion repository to get some of the Git goodness, local branches, stashes and much more, without having to persuade everyone else on your project to migrate to Git

If you don’t already have git installed then see part I (Installation).

Clone you Subversion repository

Make a local clone of your subversion repository to work with.

Warning: Git does not support svn:externals but luckily you vendor everything with piston, don’t you? If not then various people have written up hacks for managing svn:externals none of which are ideal but they will get you started.

Assuming you use a standard Subversion repository layout (with /trunk, /branches etc.) then this is as easy as

git-svn clone http://svn.foo.org/project/trunk

Tweak your local Git repository

There are a couple more things that you should do to the repository before beginning work

Firstly, tell Git about the files that Subversion ignores, using:

git svn show-ignore >> .git/info/exclude

This appears to work for some projects/Subversion installations and not others. If it doesn’t work you’ll need to create .git/info/exclude file in the project and add file patterns to exclude by hand.

Secondly, recreate any empty folders which are required by the project e.g. /log. You need to do this because Git does not track empty directories.

Now you are ready to go.

Get to work

  1. Make your changes

    Make changes to the code base in just the same way as you would with Subversion

  2. Commit your changes to your local master branch

    Unless you have been working with local branches this is easy as.

    git commit -a

    Which will commit all your changes to your local Git repository.

    If you have added or removed files you will also need to use git add or git rm to ensure all your changes are committed.

  3. Update your local repository from Subversion

    git svn rebase

    This brings your local Git repository up to date with the central Subversion repository

    It works just like git rebase in that it rewinds your local commits, applies the latest changes from subversion, and then replays your local commits over the top. If there are merge issues you will be warned about them here.

  4. Push your local commits back into subversion

    git svn dcommit

    This applies each of your local commits in turn to the subversion repository.

  5. Repeat (go back to step 1.)

Further reading

Now you’ve got started here are a couple of good resources for when you get stuck

Best of luck.