Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source Control: Multiple repositories for the same project

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 ?

like image 470
Andreas Grech Avatar asked Mar 05 '09 20:03

Andreas Grech


2 Answers

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 synchronise 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 repository, 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 machine A's repository and is the only user with rights in machine B's repository. It's very important no commits are done manually to machine B'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 batch files are in place we need to tell the repository on B we want to synchronise 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 synchronise to Google Code 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 third party repository location as the synchronisation 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 synchronisation repositories on machine B with -sync for clarity. The D:\SVN bit is the svnserve root on machineB even though this generic BAT file should be placed in the /hooks of machineA's svnserve root.

like image 124
Martijn Laarman Avatar answered Oct 15 '22 07:10

Martijn Laarman


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.

like image 36
user16120 Avatar answered Oct 15 '22 06:10

user16120