Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

7 Answers 7

up vote 4 down vote accepted

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.

share
locked by Michael Hampton Jun 9 at 16:05

This post has been locked while disputes about its content are being resolved. For more info visit meta.

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 }'
share|improve this answer

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.

share|improve this answer
    
Basically, if you have multiple revisions of tags, you kind of defeat the purpose of tagging. –  Kyle Brandt Sep 23 '09 at 19:43
 svn list --xml $REPO/tags | grep 'revision="' | cut -d '"' -f2 | tr -d ' ' | sort -bnu | tail -1
share|improve this answer

If you have good version numbers

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

I like Jim Huang's solution, works like a charm. If you get the error "Broken Pipe" (I get it on Ubuntu and Mac), just try to surround the command like the following:

exec 6>&2 2>/dev/null; svn log -v tagsURL | awk '/^   A/ { print $2 }' | head -1;  exec 2>&6 6>&-

This will simply suppress the error message. I checked some mailing lists and obviously nobody knows why this error occurs.

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.