Find the Latest SVN Repository Tag with Ruby

Here’s a quick and dirty (and I mean DIRTY – use at your own risk) way to extract the latest tag from a SVN repository.  This is a helper method I wrote for a Capistrano deploy script:

# Quick and dirty means to pull the latest tag name from an SVN repository

# TODO: Error checking – it should have some
# TODO: Check to see if the repository exists before running code
# TODO: Return nothing if the tag doesn’t look right (eg, the tag name is ‘tags’)

# Given an SVN repository URL, return the name of the latest tag in the repo/tags directory.
# * Assumes the standard SVN setup: trunk/, tags/, branches.  It will append the /tags/ directory to the end of the URL
# * Does ZERO error checking…returns whatever it finds.
def get_last_svn_tag(repo)

txt = `svn log #{repo}/tags/ –limit=1 -v`

# thanks to for this
re1=’.*?’    # Non-greedy match on filler
re2='((?:\\/[\\w\\.\\-]+)+)’    # Unix Path 1

if m.match(txt)
puts “(“<