views:

1032

answers:

3

Is it possible to have multiple repositories for the same project?

I am currently using SVN with TortoiseSVN with the repositories on an external hard disk at my home, and well as regards a backup-wise solution, this isn't ideal.

So what I have in my mind is making an account with unfuddle and having a second (my home one being the first) repository to where I can commit there (even for a remote-backup solution).

Now of course, I want integrity in my code and I don't want discrepancies between the two (or more ?) repositories, which means that both repositories should be both updated when I commit my code.

So what can I do to make this happen?

Something I have in my mind is committing to my primary repository (the home one) and then it automatically commits to the online repository (the unfuddle one) automatically (because of course I don't want to manually commit to both repositories every time I commit my code)

Is this possible ?

+3  A: 

Everything's possible :)

EDIT haste never leads to quality nor did my answer, missing all the Windows references in the question. So here's a run down on how to get the sync working on Windows.

You have 2 Machines in this case:

  • Machine A: where the repository runs now.
  • Machine B: where you'd like to
    sync to.

Create a new repository on B that you wish to sync to from A. It's very important that this repository is blank (running on rev0).

On B, in the SVN folder of the newly created repos, browse to /hooks and create the following bat files:

start-commit.bat

IF "%2" == "someusername" (goto :label1) else (echo "Only the someusername account may commit new revisions" >&2 )

exit 1
goto :eof

:label1
exit 0

pre-revprop-change.bat

IF "%3" == "someuser" (goto :label1) else (echo "Only the someuser user may change revision properties" >&2 )

exit 1
goto :eof

:label1
exit 0

someuser being a syncuser that exists in machineA's repos and is the only user with rights in machineB's repository. It's very important no commits are done manually to machineB's repository.

In the /hooks folder of the repository on machine A

post-commit.bat

CD PATH_TO_SUBVERSION\bin
svnsync sync svn://machineB/repos --non-interactive --no-auth-cache --source-username machineAusername --source-password machineApassword --sync-username machineBusername --sync-password machineBpassword

Once these bats are in place we need to tell the repository on B we want to sync to it:

svnsync initialize svn://machineB/repos svn://machineA/repos --non-interactive --no-auth-cache --source-username machineAusername --source-password machineApassword --sync-username machineBusername --sync-password machineBpassword

which should return something like: Copied properties for revision 0.

Now every time you commit into the repository on machine A it will be copied over to machine B's repository.

It's very important to note that if you want to sync to googlecode or another online repository that they commit a trunk/branches/tags structure into revision 1. You have to contact them to reset the repository if you wish to use these 3rd party repository location as the sync repository.

To give credit where due i copied the pre-revprop-change.bat and start-commit.bat from http://www.svnforum.org/2017/viewtopic.php?t=5745&sid=06551a22d9c0b5780cf1faab6b0e8ce9

I just implemented this myself on a test repository and seems to work like a charm. I'm glad i noticed this question though svnsync has sunk too deep down in my skull. I meant to do set it up when setting up svn at work. So i know what the first thing is i'll be doing at work tomorrow, thanks for that!

EDIT 2:

If you like me have tons of repositories this generic post-commit.bat might appeal to you:

SET REPOS=%1
SET REV=%2 
SET REPOS=%REPOS:D:\SVN=%


CD "C:\Program Files\Subversion\bin"

svnsync sync svn://machineB/%REPOS%-sync --non-interactive --no-auth-cache --source-username usernameA --source-password passwordA --sync-username usernameB --sync-password passwordB

This catches the repository name and uses it to dynamically determine the sync URL. i suffixed all my sync repositories on machine B with -sync for clarity. The D:\SVN bit is the svnserve root on machineB eventhought this generic bat file should be placed in the /hooks of machineA's svnserve root.

Martijn Laarman
He's using TortoiseSVN, so he's on Windows. A linux solution may not be helpful.
Ben S
heh indeed, I am on a Windows machine...
Andreas Grech
do forgive my hasteful reply ! i'll post up how to create your own hooks on windows.
Martijn Laarman
Be prepared when syncing at a later stage when some repositories are at revision 6000 it will take a while. Found that out today when implementing syncing at work :p
Martijn Laarman
+1  A: 

I'm not sure I fully understood your problem, but I think that what you are looking for is svnsync.

You can have your main repository inside your notebook's hard disk and a mirror repository at your desktop/home server.

Just commit your changes to the main repository and then sync it to your mirror repository(ies). This process is incremental, so only the revisions since the last sync are trasferred, but be careful with unversioned properties.

Also you might wanna take a look in here and here.

A: 

From a pure SVN perspective nope, you can only have one .svn folder which points to only 1 repo in your working folder.

You can make use of post-commit-hooks on your svn repo to try and keep both repos in sync.. but really you just have the wrong tool if that is what you want.

The problem your are describing is at its heart a distributed version control system like GIT. Which allows you to make commits locally and also to push it to a remote repository.

You could even use GIT locally and SVN as your remote repo if you were so inclined.

  • see GIT for the tool
  • see GitHub for free public hosting
Stephen Bailey