svn2git
Transform a svn checkout into a git remote
by humancoder 1 year, 4 months ago and tagged with: git python svn
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/env python""" Make a Git checkout from an SVN repository """ import osfrom optparse import OptionParserfrom 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_outputrev = 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']) |

Currently 0 comments