Skip to content

Instantly share code, notes, and snippets.

@corpix
Created March 21, 2014 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpix/9698194 to your computer and use it in GitHub Desktop.
Save corpix/9698194 to your computer and use it in GitHub Desktop.
Simple git mirroring
#!/usr/bin/env python
import os
from subprocess import call
import hashlib
me = os.path.dirname(os.path.realpath(__file__))
tmp = "%s/tmp" % me
repos = [
{
"from": "...",
"to": "..."
}
]
for i in repos:
m = hashlib.sha1()
m.update(i["from"])
m.update("|")
m.update(i["to"])
target_name = m.hexdigest()
target = "%s/%s" % (tmp, target_name)
print('Giving a try to: %s #%s' % (i, target_name))
if not os.path.exists(target):
call([ "git", "clone", "--mirror", "git://%s" % i["from"], target ])
call([ "git", "--git-dir=%s" % target, "remote", "add", "mirror", "git+ssh://%s" % i["to"] ])
call([ "git", "--git-dir=%s" % target, "fetch", "origin" ])
call([ "git", "--git-dir=%s" % target, "push", "--mirror", "mirror" ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment