The right way to get a Rails project into Subversion

Creating a new Rails project and importing it into Subversion isn’t completely straight forward, but thanks to Noel Rappin’s great book “Professional Ruby on Rails” we have an industry “best practice.” Here it is (note that I’ve stripped out the command response in most cases for brevity):

Firstly, create your new Rails application. We’ll use “aurora2″ as the name in this case. If you’ve already got a Rails application created you can skip this step, and replace “aurora2″ where appropriate.

$ rails aurora2

Now create the base directory on the remote Subversion server. This needs to exist before we can create the trunk, tags and branches subdirectories.

$ svn mkdir https://prime.thefrontiergroup.com.au/svn/client/tfg/aurora2 \
             -m "Initial project structure"

With the base directory created, add the trunk, tags and branches directory.

$ svn mkdir https://prime.thefrontiergroup.com.au/svn/client/tfg/aurora2/trunk \
             https://prime.thefrontiergroup.com.au/svn/client/tfg/aurora2/tags \
             https://prime.thefrontiergroup.com.au/svn/client/tfg/aurora2/branches \
             -m "Initial project structure"

Change to the project’s local directory on your development machine, checkout the trunk and add all of the files and directories to the repository. Don’t worry - checking out the trunk won’t “overwrite” any files you’ve edited locally!

$ cd aurora2
/aurora2$ svn co prime.thefrontiergroup.com.au/svn/client/tfg/aurora2/trunk .
/aurora2$ svn add --force .

We don’t want the log to be stored in the repository, so remove them and tell Subversion to ignore any files in the log directory.

/aurora2$ svn revert log/*
/aurora2$ svn propset svn:ignore "*" log

Do the same for the documentation and temporary directories. The files created in here during the development process do not need to be stored in the repository.

/aurora2$ svn propset svn:ignore "*" doc
/aurora2$ svn propset svn:ignore "*" tmp

We need to consider two things about the development database. Firstly, different developers might use different systems (MySQL, SQLite, Oracle, etc) and secondly we don’t want their individual authentication credentials to be stored in the configuration file for security reasons.

Therefore each developer will have their own local database configuration file and it won’t be stored in the repository. When a new developer checks out the source tree they’ll have to copy the template file to database.yml and alter the database connection details as necessary.

/aurora2$ cp config/database.yml config/database.yml.template
/aurora2$ svn add config/database.yml.template
/aurora2$ svn revert config/database.yml
/aurora2$ svn propset svn:ignore "database.yml" config

Some of the files need to remain executable, namely the dispatch files and script files. The second command uses find to locate all files in the script directory and then grep cancels out anything in the hidden .svn directories so we’re left with all the things we want.

/aurora2$ svn propset svn:executable "*" public/dispatch.*
/aurora2$ svn propset svn:executable "*" `find script -type f | grep -v '.svn'`

Make your final check in and you’re ready to start actual development!

/aurora2$ svn ci -m "Finished project setup - time to get to work"

2 Comments so far

  1. mlambie on June 10th, 2008

    Thanks to Hale for pointing out that I’d missed out the “checkout your trunk” step. It’s now been added to the recipe.

  2. mlambie on November 25th, 2008

    I have altered the log svn:ignore to exclude everything because later we use logrotate to rotate the logs and we want them ignored too.

Leave a Reply