DZone 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

Luke has posted 4 posts at DZone. View Full User Profile

Accessing Subversion Repository Information In Ruby

08.07.2006
| 4462 views |
  • submit to reddit
        
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

Snippets Manager replied on Sun, 2008/10/19 - 5:51pm

Nice post .. thanks to esad too

Snippets Manager replied on Mon, 2012/05/07 - 2:26pm

Of course, this won't work if you're deploying through Capistrano and using svn export. Which we all _should_be doing, right?

Snippets Manager replied on Wed, 2006/12/20 - 11:31pm

or you can use: YAML.parse(`svnversion #{RAILS_ROOT}`).value

Snippets Manager replied on Mon, 2006/11/06 - 9:34am

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

Snippets Manager replied on Wed, 2006/10/04 - 12:51pm

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?