Automatic tag creation in subversion

I support the build system in my company, which currently uses CVS. This build system is used for several projects and multiple CVS repositories.

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

$ cvs tag TAG_NAME 

This command works regardless of the CVS module or repository if it is executed in the CVS working directory.

To do the same in subversion, although it seems like I first need to parse the output of svn info to get the root of the repository. 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 directory structure "trunk, tags, branches". Therefore, to be safe, I probably have to check this first.

It seems like a lot of work to match the version number with a symbolic name. Is there a better way?

+6
svn
source share
4 answers

Here's how I did it, if anyone is interested:

 <!-- First, we need to get the svn repository root URL by parsing the output of 'svn info'. --> <exec executable="svn" failonerror="yes"> <arg line="info"/> <redirector outputproperty="svninfo.out" errorproperty="svninfo.err"> <outputfilterchain> <linecontains> <contains value="Repository Root: "/> </linecontains> <tokenfilter> <replacestring from="Repository Root: " to=""/> </tokenfilter> </outputfilterchain> </redirector> </exec> <echo level="verbose" message="Root from svn info: ${svninfo.out}"/> <!-- Set the svn.root property from the svn info output, and append the module prefix if it exists. The module prefix allows multiple projects to use the same repository root. --> <condition property="svn.root" value="${svninfo.out}/${svn.module.prefix}"> <isset property="svn.module.prefix"/> </condition> <!-- Note that the next line will have no effect if the property was set in the condition above, since ant properties are immutable. The effect is an "else", if the condition above is NOT true. --> <property name="svn.root" value="${svninfo.out}"/> <echo level="verbose" message="Root: ${svn.root}"/> <!-- Verify the tags directory exists. --> <exec executable="svn" failonerror="no" outputproperty="null" errorproperty="svn.ls.error"> <arg line="ls ${svn.root}/tags"/> </exec> <fail> Cannot find 'tags' subdirectory. ${svn.ls.error} The subversion repository is expected to have 'trunk', 'branches', and 'tags' subdirectories. The tag '${tag}' will need to be manually created. <condition> <not> <equals arg1="${svn.ls.error}" arg2="" trim="yes"/> </not> </condition> </fail> <!-- Finally, do the actual tag (copy in subversion). --> <exec executable="svn" failonerror="yes"> <arg line="cp . ${svn.root}/tags/${tag} -m 'Created tag ${tag}'"/> </exec> 

I also want to note that I am aware of the differences between CVS and subversion with respect to tags, and that a subversion revision is equivalent to a tag for all practical purposes. Unfortunately, this is not very relevant; my users want to have a symbolic name consisting of a module name and a (different) version number.

+5
source share

I use svn from the command line almost exclusively, and I quickly get tired of typing in monster urls. I finally wrote the svnurl script that I use from the shell. It acts on the assumption that the "project" has the form:

 .../PROJECTNAME/trunk tags branches 

Suppose you are somewhere in a working copy of PROJECTNAME / branch / 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 is not beautiful, but it saved me a lot of keystrokes and was useful in a way that I did not expect. I would like to share it if you are interested.

+5
source share

You are missing the basic principle of Subversion: the version number is the tag. When you β€œtag” it with svn cp, you simply make a copy of this particular version with a longer name. And unlike the CVS tag, you (or other developers) could continue the ongoing development on this "tag". This is not a static entity, like a CVS tag (well, to be honest, you can move a tag to separate CVS files that effectively "change" it).

Most svn users handle tags as CVS represented them. And (under Apache, at least) you can configure the DAV server to not allow writes / checks in any tag directory. I have not tried this, and this may prevent you from using http URLs to create tags (you will have to use file paths from the shell on the hosting). But for all practical purposes, the release process should be more interested in a specific revision number than in some arbitrary text string. The latter may be changed after release; the first should always * * always give you access to the same set of files every time you check it.

[*] There is always a way to play with files behind the scenes, after the fact ... I used to edit RCS and CVS files with vi when I needed to correct a comment, etc. But without some serious svn intelligence, this version number should be fairly constant.

+5
source share

Unlike CVS, tags are more than just a symbolic name in subversions, then period. We create a tag, you are actually creating a branch. I recommend reading this if you have not already done so: http://svnbook.red-bean.com/

+2
source share

All Articles