开发者

How do I make a branch from a SVN tag with Maven?

Suppose I have tagged the release version of our project under $SVNROOT/project/tags/1.0. Suppose now that I need to create a branch from that tag, mark it as being a SNAPSHOT, and update the scm configuration.

I tried with the release:prepare goal thus:

$ svn co $SVNROOT/project/tags/1.0 project-1.0
$ cd project-1.0
$ mvn release:branch -DbranchName=project-1.0.X -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

But this fails, with an error message warning me that I don't have commit rights into the $SVNROOT/project/tags/1.0 project-1.0 path (which is perfectly true---we don't allow commits into tags).

What am I doing wrong here, and why was Maven trying to commit something in the tag?

Update

Just to clarify: I am running this from the directory into which I've checked out the tag. The exact error I'm getting is the following:

[INFO] Executing: /bin/sh -c cd xxx && svn --non-interactive commit --file /tmp/maven-scm-28755080.commit --targets /tmp/maven-scm-535803351230252749-targets
[INFO] Working directory: xxx
org.apache.maven.shared.release.scm.ReleaseScmCommandException: Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 


        at org.apache.maven.shared.release.phase.ScmCommitPhase.checkin(ScmCommitPhase.java:133)
        at org.apache.maven.shared.release.phase.ScmCommitPhase.execute(ScmCommitPhase.java:109)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:379)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:350)
        at org.apache.maven.plugins.release.BranchReleaseMojo.execute(BranchReleaseMojo.java:133)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
        at org.apache.maven.lifec开发者_C百科ycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 


Where did you execute that command mvn release:branch?

As mentioned in this thread:

What the plugin doco does specify is that the release:branch goal should be invoked from a checkout location with the revision/tag you want to branch from. (i.e. tags/<my_release_version>).

I used the following commandline to create a maintenance branch (branches/myapp-1.3.1) from an existing tag location (tags/myapp-1.3):

mvn release:branch -DbranchName=myapp-1.3.1 -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=false

The -DupdateBranchVersions flag pertains to the versions in the pom.xml - not the scm versions.
If false, it will retain the same version as the tagged release;
if true, it will prompt for a version, defaulting to a snapshot of the tagged release, which may or may not be what you want.

See also this thread:

First you need to start with a working copy checked out from the Tag.
If the tag was created by the release plugin, the starting scm url should be correct, and point back to the tag.

Then use the plugin to crate the branch and switch the working copy to the branch.

An alternative is to manually:

  • copy from the tag to a new branch
  • switch the working copy to the new branch (or check out a working copy from the new branch)
  • update the pom to use the new branch's url- commit the update to the pom


mvn release:branch
   -DbranchName=${project.artifactId}_${project.version} 
   -Dusername=${username} 
   -Dpassword=${passwd} 
   -DupdateBranchVersions=true 
   -DupdateVersionsToSnapshot=true 
   -DremoteTagging=false 
   -DsuppressCommitBeforeBranch=true 
   -DupdateWorkingCopyVersions=false

-DautoVersionSubmodules=true

When ran, Maven will prompt for the version to be used in the branch. I provided 1.5.0-azuresupport-SNAPSHOT. Since autoVersionSubmodules is set to true, Maven Release will automatically use this versions for all submodules and hence also update all inner-project dependencies to that version.

-DsuppressCommitBeforeBranch=true

By default, Maven Releases creates intermediate commits to the current working copy. I’m not sure of the reason, but I think it was because some VCS do not support branching/tagging of modified working copies. This parameter makes sure, no intermediate commits are made to the working copy.

-DremoteTagging=false

With SVN, by default, tags are created remotely. If you want to ommit intermediate commits, this must be set to false.

-DupdateBranchVersions=true

-DupdateWorkingCopyVersions=false

When branching, you can either define new versions for the current working copy, or the new branch, or both. As set here, the working copy will be left alone, and the plugin will ask for a new version for the branch.

here you have all the -D arguments explained http://startbigthinksmall.wordpress.com/2011/11/29/create-branches-with-maven-release-plugin-svn/


The commands you're running looks OK and strictly follow the example given in Create a Branch:

By default, the POM in the new branch keeps the same version as the local working copy, and the local POM is incremented to the next revision. If you want to update versions in the new branch and not in the working copy, run:

mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

Note: This can be useful if you want to create a branch from a tag

However, it seems that it's a 'pre-commit' hook that is failing and complaining. So I wonder:

  • what you're doing in this hook
  • what happens if you disable this hook temporarily


The actual problem is that the release:branch goal commits to tags, which is an unconscionable bug. There is no workaround. Your pre-commit hook is likely failing because it is designed--probably correctly--to prevent commits inside a tag directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜