Automatically creating a tag in subversion

svn

I maintain the build system at my company, which is currently using CVS. This build system is used across multiple projects and multiple CVS repositories.

Whenever we have a release milestone, we create a tag. In CVS, this is easy:

$ cvs tag TAG_NAME

That command works regardless of the CVS module or repository, as long as it is executed in a CVS working directory.

In order to do the same thing in subversion though, it looks like I will first have to parse the output of svn info to get the repository root. Then I can create the tag with:

svn cp . $REPO_ROOT/tags/TAG_NAME -m"Created tag TAG_NAME"

This of course assumes that the svn repository has the recommended "trunk, tags, branches" directory structure. So to be safe I'll probably need to verify this first.

That seems like a lot of work just to map a revision number to a symbolic name. Is there a better way?

Best Answer

I use svn from the command line almost exclusively and0t I quickly tired of typing in monster URLs. I finally wrote a script svnurl, which I use from the shell. It operates on the assumption that an "project" hast the form:

.../PROJECTNAME/trunk
                tags
                branches

Let's assume you are somewhere in a working copy of PROJECTNAME/branches/foo:

svnurl -tl  # gives a list of tags for the current project 
svnurl -tlu # the same as full urls
svnurl -t 1.1 # the url for the tag 1.1 of the current project
# analagous functions for branches
svnurl -ru  # the url of the "root" of the current working copy
            # eg  svn://.../PROJECTNAME/branches/foo
svnurl -T   # the url of the trunk of the current project
svnurl -pn  # the name of the current project, `PROJECTNAME`
# ...

Usage looks something like this:

$ svn cp $(svnurl -T) $(svnurl -t 1.1.1)  # tag trunk as 1.1.1

The code isn't beautiful, but it has saved me many keystrokes and been useful in ways I hadn't expected. I'd be willing to share it if you are interested.