35f3142d2d9c900898355f6945e91acf793c4f04
[invirt/scripts/git-migration.git] / git-migrate
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import subprocess
6 import shutil
7
8 def clonePackage(base, pkg):
9     if not os.path.isdir('%s.git' % pkg):
10         if os.path.isdir(pkg):
11             shutil.rmtree(pkg)
12         # Use --no-follow-parent because we're going to handle that with
13         # grafts.
14         subprocess.check_call(['git', 'svn', 'clone', '--no-follow-parent',
15                                '-Aauthors',
16                                '-q',
17                                '--no-metadata', '%s/packages/%s' % (base, pkg)],
18                               stdout=subprocess.PIPE)
19         
20         # Then make the repository bare, because git-svn can't do this
21         shutil.move('%s/.git' % pkg, '%s.git' % pkg)
22         shutil.rmtree('%s' % pkg)
23         subprocess.check_call(['git', 'config', 'core.bare', 'true'], cwd='%s.git' % pkg)
24
25 def cloneAllPackages(base):
26     for pkg in open('package-list'):
27         clonePackage(base, pkg.strip())
28
29 if __name__ == '__main__':
30     try:
31         base = sys.argv[1]
32     except:
33         base = 'svn://invirt.mit.edu/trunk'
34     
35     cloneAllPackages(base)