Get Latest Tag From Subversion

Is there a way to determine the newest tag in subversion?

For an application I've deployed the client needs to have another server that they can access in case the live server goes down. There is already an automated system to copy the database to the backup server. The application code is in a subversion repository and I would like to write a script that copies the code from subversion to the backup server automatically. I have a script that does this, however, I need to manually tell it what tag to retrieve. Is there a way to make this totally automated.

The server is running Redhat.


If your tags are listed sequentially when sorted, you could grab the name of the latest with something along the lines of:

svn ls .../path/to/repo/tags | tail -n 1

If your project's tag structure is not so strict, the result of svn ls will need to be passed the -v (verbose) option and sorted based on the date in the output.


This shell command outputs the most recently created tag in your tags directory.

svn log -v --limit 1 tagsURL | awk '/^   A/ { print $2 }'

If you are calling the command from within a checked out repository, you can use the relative svn path token ^:

svn log -v --limit 1 ^/tags | awk '/^   A/ { print $2 }'

My understanding is that tags are just copies of the main branch you made with the 'svn copy' command. So, if you are doing this, aren't you giving these tags version numbers? Just grab the highest number?

Perhaps you mean the latest revision number of a repo? In that case it would just be something like:

svn info https://www.myDomain.com/svn/myRepo | grep Revision | awk '{print $2}'

Or maybe you want:

svn ls https://www.myDomain.com/svn/myRepo/tags

You could then do an svn info on each of those directories, and the one with the highest Last changed Revision number would be the latest tag.


If your tags don't sort 'naturally' (if you follow semantic versioning, 1.10.0 will be listed after 1.1.0 not after 1.9.0 in svn ls output), you can use the guaranteed-to-sort revision ID of your tags directory:

 svn ls -v --config-dir=/root/.subversion https://svn/project/tags | sort -n |  awk '{ field = $NF }; END{ print field }'
 1.10.0

If you have good version numbers

svn ls https://www.myDomain.com/svn/myRepo | sort -V | tail -n 1