def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) package_name = basename() svntype = svn_type() if svntype == 'tags': print "Can't work on tags!" sys.exit(1) elif svntype == 'unrecognized': print "Unrecognized svn structure!" sys.exit(1) if not exists(config.GIT_CACHE + package_name): print "No git repository found in %s." % config.GIT_CACHE print "Initiating cloning into cache." clone() # get the branch svn is on remote_branch = svn_branch() # the following is just convention: local_branch = "local/%s" % remote_branch cwd = os.getcwd() # perform all index updates in the cache to avoid conflicts os.chdir(config.GIT_CACHE + package_name) dummy, existing_branches = popen('git b', False, False) existing_branches = [b.strip() for b in existing_branches] if local_branch in existing_branches: popen('git checkout -f %s' % local_branch, False, False) else: popen('git checkout -f -b %s %s' % (local_branch, remote_branch), False, False) os.chdir(cwd) if not exists('.git'): popen('ln -s %s%s/.git' % (config.GIT_CACHE, package_name), False, False) print "Git branch '%s' is now following svn branch '%s':" % ( local_branch, remote_branch) popen('svn status') popen('git status')
def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) if not is_svn(): print "This only works on svn checkouts!" sys.exit(1) package_name = basename() svntype = svn_type() if svntype == 'tags': print "Can't work on tags!" sys.exit(1) elif svntype == 'unrecognized': print "Unrecognized svn structure!" sys.exit(1) if not exists(config.GIT_CACHE + package_name): print "No git repository found in %s." % config.GIT_CACHE print "Initiating cloning into cache." clone() else: # if we already have a cached copy, make sure it's up-to-date: print "Updating existing cache:" gitify(args=['fetch', package_name]) # get the branch svn is on remote_branch = svn_branch() # the following is just convention: local_branch = "local/%s" % remote_branch cwd = os.getcwd() # perform all index updates in the cache to avoid conflicts os.chdir(config.GIT_CACHE + package_name) dummy, existing_branches = popen('git branch', False, False) existing_branches = [b.strip('* ') for b in existing_branches] if local_branch in existing_branches: popen('git checkout -f %s' % local_branch, False, False) else: popen('git checkout -f -b %s %s' % (local_branch, remote_branch), False, False) os.chdir(cwd) if not exists('.git'): popen('cp -Rp %s%s/.git .' % (config.GIT_CACHE, package_name), False, False) # if the working copy is on another branch, switch: if local_branch != git_branch(): if local_branch in existing_branches: popen('git checkout -f %s' % local_branch) else: popen('git checkout -b %s' % local_branch) assert git_branch() == local_branch, ( "Changing branches failed, is on %r but should be on %r" % (git_branch(), local_branch)) print "Git branch '%s' is now following svn branch '%s':" % ( local_branch, remote_branch) popen('svn status') popen('git status')