6

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.

7 Answers 7

4

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.

7

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 }'
4

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.

1
  • Basically, if you have multiple revisions of tags, you kind of defeat the purpose of tagging. Sep 23, 2009 at 19:43
2

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
1

If you have good version numbers

svn ls https://www.myDomain.com/svn/myRepo | sort -V | tail -n 1
1
 svn list --xml $REPO/tags | grep 'revision="' | cut -d '"' -f2 | tr -d ' ' | sort -bnu | tail -1
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .