Last Updated: February 25, 2016
·
2.852K
· dave-irvine

Get the latest tag in your Subversion repository

For those still using Subversion!

Had a need today to find the latest tag in one of our repos. The standard order was coming out as you'd expect:

1.0.0.0/
1.0.0.1/
1.0.0.10/
1.0.0.11/
....

but possibly not how you'd like! Tailing the output actually gave 1.0.0.9 as the tag number, when the answer I really wanted was 1.0.0.45.

Verbose mode to the rescue. This lists the commit number first, so unless you are doing some very strange jiggery pokery, the latest tag should also have the highest commit number.

Pass it through sort, tail the results and awk for the 6th parameter (is there an awk for "last"?), the folder name; i.e the tag number.

svn ls -v <path/to/repo> | sort -d | tail -n 1 | awk '{print $6}'

Now there might be an issue here in that sort is running across the entire string provided by svn ls's verbose mode. This includes the name of the committer, and the last modified date. I imagine there is some combination whereby a committers name and the modified date may come out with a higher precedence than the revision number, but this didn't happen during my testing.

I'd be happy to hear about improvements on this snippet.