Created
March 21, 2014 22:54
-
-
Save corpix/9698194 to your computer and use it in GitHub Desktop.
Simple git mirroring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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