3Spoken

Rails Subversion TNG – Setting up Subversion

First a short Subversion lesson

Before you can use Subversion properly with Rails, it needs a little setting up. Some of the files within a Rails application are volatile and don’t really need to be under version control. You can, of course, do this on a file by file basis using Subversion properties, e.g:

svn propset svn:ignore 'database.yml' config/db

and this is traditionally how things are done. But it’s a bit irritating having to do this with every Rails application you ever create – even with scripting.

So, is there a better way? Of course there is – by setting up Subversion correctly.

Subversion and the config file

A little known advanced feature of Subversion is that it will automatically set properties and ignore certain types of files during add and import if you ask it nicely. What you need is a configuration file (called config, unsurprisingly) in INI format stored in the correct place on your system.

On Unix systems there are two places the config file can be:

  • to have a system wide impact it goes in /etc/subversion
  • each user has a version in ~/.subversion which override the system defaults.

On Windows

  • you can store the configuration data directly in the Registry
  • or an INI file, called config, within the folder %APPDATA%\Subversion

Automatically ignoring Rails volatile files

The contents of the tmp and log directories in a Rails application are routinely excluded from version control, normally by setting the property settings on individual files. However you can get Subversion to do that for you by making an entry in your config file, e.g.

#this goes in .subversion/config on your computer
[miscellany]
global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store ._* \
*.log *.swp *.tmp database.yml schema.rb sessions sockets cache pids \
index.html apidoc appdoc

When scanning the working directory svn will ignore all files and directories that match these patterns. If you want, for example, database.yml to be under version control, simply remove it from this list.

Automatically setting file properties

As well as ignoring files, Subversion can automatically set the property type based on file patterns as well. Add the following to the [miscellany] section of your config file

enable-auto-props = yes

and then add the following section

[auto-props]
*.txt = svn:eol-style=native
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
*.jpeg = svn:mime-type=image/jpeg
*.gif = svn:mime-type=image/gif
*.tif = svn:mime-type=image/tiff
*.tiff = svn:mime-type=image/tiff
*.swf = svn:mime-type=application/x-shockwave-flash
*.pdf = svn:mime-type=application/pdf
*.doc = svn:mime-type=application/msword
*.rtf = svn:mime-type=text/rtf
*.html = svn:mime-type=text/html
*.php = svn:mime-type=text/plain
*.xml = svn:mime-type=text/xml
*.css = svn:mime-type=text/css
*.vcf = svn:mime-type=text/x-vcard
*.avi = svn:mime-type=video/x-msvideo
*.mov = svn:mime-type=video/quicktime
*.tex = svn:mime-type=text/x-tex
*.bmp = svn:mime-type=image/bmp
*.svg = svn:mime-type=image/svg+xml
*.svgz = svn:mime-type=image/svg+xml
*.mp3 = svn:mime-type=audio/mpeg
*.gtar = svn:mime-type=application/x-gtar
*.tgz = svn:mime-type=application/x-gtar
*.gz = svn:mime-type=application/x-gtar
*.zip = svn:mime-type=application/zip
*.ppt = svn:mime-type=application/vnd.ms-powerpoint
*.xls = svn:mime-type=application/vnd.ms-excel
*.smil = svn:mime-type=application/smil
*.ps = svn:mime-type=application/postscript
*.eps = svn:mime-type=application/postscript
*.psd = svn:mime-type=application/photoshop
*.ai = svn:mime-type=application/illustrator
*.gpgkey = svn:mime-type=application/gpg-keys

Complete config file to copy from

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: