Created
July 22, 2010 12:30
-
-
Save xarg/485905 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
""" Make a Git checkout from an SVN repository """ | |
import os | |
from optparse import OptionParser | |
from subprocess import Popen, PIPE | |
def run(cmd): | |
return Popen(cmd, stdout=PIPE).communicate()[0] | |
parser = OptionParser(usage="usage: %prog svn_url [-a]") | |
parser.add_option('-a', '--all', help='fetch all history', | |
action="store_true", dest='all_history', default=False) | |
parser.add_option('-r', '--revision', help='fetch specific revision', | |
type="int", dest='revision', default=None) | |
(options, args) = parser.parse_args() | |
if len(args) != 1: | |
parser.error('You must specify exactly one SVN URL') | |
url = args[0] | |
dirname = url.split('/')[-2 if url.endswith('/') else -1] | |
run(['mkdir', dirname]) | |
os.chdir(dirname) | |
svn_output = run(['svn', 'log', url, '--limit=1']) | |
print svn_output | |
rev = svn_output.split('\n')[1].split(' ')[0][1:] | |
print run(['git', 'svn', 'init', url]) | |
if options.all_history: | |
print run(['git', 'svn', 'fetch']) | |
elif options.revision: | |
print run(['git', 'svn', 'fetch', '-r', str(options.revision)]) | |
else: | |
print run(['git', 'svn', 'fetch', '-r', rev]) | |
print run(['git', 'checkout']) | |
f = open('.git/info/exclude', 'a') | |
f.write("*.pyc\n*egg-info\n") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment