views:

667

answers:

3

I have an existing SVN repository which contains a folder that holds my project. I wish to know if there's a way of creating a new repository with my project's folder set as its root and preserve all subversion history (log) along with it. Notice that I do not mind loosing the original repository revision numbers.

Thanks.

+2  A: 

You can copy the repository manually, or using svnadmin.

You can then move the sub-directories of your project to be under the root, and delete everything else, and thus remain with the directory structure you want. The history will be preserved, per-file, but it will remember that the files used to have a different path (which is probably a good thing).

Avi
+1  A: 

Avi's solution is probably easiest, but has the downside that the new repository will contain the full history of all the stuff outside of this one project. In the example below, I'm assuming that you are at the command line of a *NIX machine and that you are in a directory containing your existing repository.

svnadmin create new-project-repo  # create new repo next to old repo
svnadmin dump old-project-repo | svnadmin load new-project-repo
svn mv file://$PWD/new-project-repo/my-project/trunk    file://$PWD/new-project-repo/trunk
svn mv file://$PWD/new-project-repo/my-project/branches file://$PWD/new-project-repo/branches
svn mv file://$PWD/new-project-repo/my-project/tags     file://$PWD/new-project-repo/tags
# ... svn rm file://$PWD/new-project-repo/XXX for all the cruft still at the top level.

If you are running subversion 1.6.x, svnsync provides a better option. Prior to 1.6.x, svnsync could only be used to copy whole repositories. With 1.6.x it has gained the ability to copy only a given subtree of the repository.

svnadmin create new-project-repo
# svnsync needs the ability to set revision properties, so we must install a pre-revprop-change
# hook script which just exits with status 0 (no error).  On *NIX systems, the program `true` will do this.
ln -s /usr/bin/true new-project-repo/hooks/pre-revprop-change  # possibly /bin/true
svnsync init file://$PWD/new-project-repo file://$PWD/old-project-repo/my-project
svnsync sync file://$PWD/new-project-repo
# go drink some coffee
bendin
A: 

FYI: The svnsync option worked for me with subversion 1.5.3.

Also, here is a Windows batch script doing the same thing:

SET OLD_REPO_URL=https://old-project-repo/my-project
SET NEW_REPO_URL=D:/Repositories/new-project-repo
SET NEW_REPO_FILE_PATH=D:\Repositories\new-project-repo

svnadmin create %NEW_REPO_FILE_PATH%
echo exit 0 > %NEW_REPO_FILE_PATH%\hooks\pre-revprop-change.bat

svnsync init file:///%NEW_REPO_URL% %OLD_REPO_URL%
svnsync file:///%NEW_REPO_URL%

Note: You will not be able to browse the new repository until the sync is finished.

Paul