Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Accessing Subversion repository information in Ruby (See related posts)

require 'yaml'
svn_info = YAML.load(`svn info /my/working/copy`)
puts svn_info['URL']
#=> "svn://some-remote-repository.com/svn"
puts svn_info['Revision']
#=> "133"


Should also work with svk info as well. Credit to htonl in #caboose for the YAML tip.

Comments on this post

gwendy posts on Oct 04, 2006 at 13:00
Unfortunately, this only returns the revision number of #{RAILS_ROOT} (natch), which (at least in my case) is always going to to be "1", regardless of how many revisions the contained files undergo. Is there a way to pull the revision of the most recently updated child item?
esad posts on Nov 06, 2006 at 08:47
Hm, I tried doing svn info recursively. It is bit slow (few seconds) but it works!

require 'yaml'

def get_svn_revision
  return nil if $RAILS_ENV == 'production'
  
  max = 0
  entries = `svn info -R #{RAILS_ROOT}/*`.split(/\n\n/)
  entries.each do |entry|
    r = YAML.parse(entry)['Revision'].value.to_i
    max = r if r > max
  end
  return max
end

$SVN_REVISION = get_svn_revision
sciascid posts on Dec 20, 2006 at 22:36
or you can use:

YAML.parse(`svnversion #{RAILS_ROOT}`).value
RSL posts on Mar 24, 2007 at 08:43
Of course, this won't work if you're deploying through Capistrano and using svn export. Which we all _should_be doing, right?

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts