Subversion, Rails and Litespeed primer

You are probably using version control for you projects. Even for a lone developer, subversion makes life much easier.

As some point you will test your application in Litespeed. Any commits to subversion after that will include compressed files ending with .lsz and logs full of outdated files. Let's set up the application to ignore certain files when committing changes.

The base for this article came from Ryan Bates' excellent Railscasts series and extends episode 36 for Litespeed use.

I'll assume you have subversion set up on your server. If not, refer to the subversion articles for an introduction and explanation.

let's start by creating a base Ruby on Rails application and moving into the directory:

rails rails_app
cd rails_app

Next move database.yml and remove the log and tmp files:

mv config/database.yml config/database_example.yml
rm -r log/*
rm -r tmp/*

Import

That's the first part done so now import the application to subversion:

svn import /home/paul/rails_app/ file:///home/paul/repository/rails_app/trunk -m "Initial import of rails_app"

Now delete the original rails_app folder as we no longer need it:

cd ..
rm -rf rails_app

Check Out

Now we're free to check out rails_app from the repository and configure it to ignore certain files and directories in any future commit:

svn co file:////home/paul/repository/rails_app/trunk rails_app
cd rails_app

Now copy the database_example.yml file back to database.yml:

cp config/database_example.yml config/database.yml

Now comes the meat of the subversion/rails primer. We're going to set the 'ignore' function on a few files so subversion will literally ignore them on any future commit.

Ignore

These files include log files, files in the rails tmp directory and files ending in .lsz in the public directory:

svn propset svn:ignore database.yml config/
svn propset svn:ignore "schema.rb" config/
svn propset svn:ignore "*.xml" config/
svn propset svn:ignore "*" log/
svn propset svn:ignore "*" tmp/
svn propset svn:ignore "*doc" doc/
svn propset svn:ignore "*.lsz" public/
svn propset svn:ignore "*.lsz" public/javascripts/
svn propset svn:ignore "*.lsz" public/stylesheets/

If you are swapping between Windows and Linux workstations when you develop your application, you will also need to set the subversion 'executable' flag on some files:

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

Commit

Finally you need to commit your changes to the subversion repository:

svn commit -m "ignoring certain files in rails_app"

Tips

There should be no need to 'add' files using 'svn add xxxxx' if you use the -c flag with script/generate.

The -c (or --svn) flag informs subversion of any new files so all you have to do is commit the changes.

An example (with output):

script/generate model user -c

      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/user.rb
A    app/models/user.rb
      create  test/unit/user_test.rb
A    test/unit/user_test.rb
      create  test/fixtures/users.yml
A    test/fixtures/users.yml
      create  db/migrate
A    db/migrate
      create  db/migrate/001_create_users.rb
A    db/migrate/001_create_users.rb

Pretty cool. Rails has automatically let subversion know about the new files. Saves us time as all we have to do is commit the changes.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Comments are closed for this article.