Two way git mirror: Difference between revisions

Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
added support for tags
 
(19 intermediate revisions by the same user not shown)
Line 1:
This articles describes how to setup a two way mirror of git repositories. I hope this article will be helpful as it works around a number of caveats for two way git mirrors.
{{TODO|introduction}}
 
== Motivation ==
 
{{TODO|motivation}}
 
 
== Setup ==
Line 12 ⟶ 7:
<source lang="bash">
cd /srv/gitsync
git clone --bare git@github.com:[account]/[repository].git
mv [repository].git [repository]
</source>
Line 24 ⟶ 19:
</source>
 
The mirroring should happen right after changes have been pushed to one of the repositories. Therefore a webhook is required to trigger the mirror script.
{{TODO|Setup webhook at github and sourceforge}}
 
On Sourceforge a project admin needs to enable it at Admin -> Tools -> Repository -> Webhooks. On Github it is at Settings -> Webhooks &amp; Services -> Add Webhook.
 
== Mirror scripts ==
Line 41 ⟶ 37:
git fetch --all -p
# push branches from sourceforge to github and via versa.
git push github "refs/remotes/sourceforge/*:refs/heads/*" "refs/tags/*:refs/tags/*"
git push sourceforge "refs/remotes/github/*:refs/heads/*" "refs/tags/*:refs/tags/*"
}
 
Line 80 ⟶ 76:
// validate repository name to prevent injection and traversing attacks
$repo = $_REQUEST['repository'];
if (!preg_match('/^[a-zA-Z0-9]+$/', $repo)) {
die('invalid repository name');
}
Line 87 ⟶ 83:
system('sudo -Hu gitsync /usr/local/bin/gitsync '.$repo);
</source>
 
 
== Security ==