views:

263

answers:

2

I am building a target in nant that branches our project.

It creates a branch in SVN, checks out that branch, updates various files within that branch with the new provided version number, checks it all in.

The SVN branch works fine the first time (using the copy command URL->URL) , but if it is run a 2nd time, it copies the trunk to the BranchName/trunk rather than failing saying it already exists.

Is there a reasonable way for Nant to detect that the branch already exists and not to try to do the SVN copy a 2nd time?

I am trying to build some intelligence into the script so that if it is run a 2nd time with the same inputs that nothing bad happens.

+1  A: 

I don't know of a Nant-specific method, but you can use svn info to check:

>svn info http://svn.host.com/repo/no-such-path
http://svn.host.com/repo/no-such-path:  (Not a valid URL)

versus

>svn info http://svn.host.com/repo/existing-path
Path: existing-path
URL: http://svn.host.com/repo/existing-path
Repository Root: http://svn.host.com/repo
Repository UUID: ...
Revision: ...
Node Kind: ...
Last Changed Author: ...
Last Changed Rev: ..
Last Changed Date: ...

Regrettably, the ERRORLEVEL is 0 in either case, but you could use the --xml switch if it helps. Or look at some .NET bindings for Subversion.

Blair Conrad
Thanks, this gives me a lead... +1
Jeff Martin
A: 

Here is my final script:

<target name="branchSvn">
    <exec program="${svn.executable}" 
    commandline='info ${svn.build.root.path}/branches/${branch.name}/ --xml' output='svn_${branch.name}.xml' />
    <xmlpeek file='svn_${branch.name}.xml' xpath='/info' 
    property='branch.info' />
    <echo message='${svn.build.root.path}/branches/${branch.name}/ already exists.' 
    if="${branch.info!=''}" />
    <delete file='svn_${branch.name}.xml' />
    <exec program="${svn.executable}" 
    commandline='copy ${svn.build.root.path}/trunk ${svn.build.root.path}/branches/${branch.name}/ -m "Branched ${branch.name} by nant script."' 
    if="${branch.info==''}" />
</target>

I used the -xml function and xmlpeek to get the info i needed.

Jeff Martin