def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) status, dummy = popen('git svn dcommit', True, True) if status == 0: popen('svn up --force', True, True) print "Pushed local changes to svn." else: print "An error occurred, consult output above."
def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) stashed = False if local_changes(): stashed = True print "Stashing uncommitted local changes." status, dummy = popen('git stash', False, False) status, dummy = popen('git svn rebase', False, False) for line in dummy: print line if stashed: status, dummy = popen('git stash pop', False, False)
def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) status, dummy = popen("git svn dcommit", True, True) if not is_svn(): print "This only works on svn checkouts!" sys.exit(1) if status == 0: popen("svn up --force", True, True) print "Pushed local changes to svn." else: print "An error occurred, consult output above."
def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) status, dummy = popen('git svn dcommit', True, True) if not is_svn(): print "This only works on svn checkouts!" sys.exit(1) if status == 0: popen('svn up --force', True, True) print "Pushed local changes to svn." else: print "An error occurred, consult output above."
def test_dirty_index(self): # A fresh repository is never dirty: self.failIf(index_is_dirty()) # Adding a new file on the filesustem... newfile = open("%s/bar.txt" % self.packagedir, 'aw') newfile.write('This is bar\n') newfile.close() # ... doesn't change that self.failIf(index_is_dirty()) # only after adding it to the index will it become 'dirty' popen('git add bar.txt') self.failUnless(index_is_dirty()) # Once we've actually committed the change, we're clean again: popen('git commit -m "added bar"', False, False) self.failIf(index_is_dirty())
def test_dirty_index(self): # A fresh repository is never dirty: self.failIf(index_is_dirty()) # Adding a new file on the filesustem... newfile = open("%s/bar.txt" % self.packagedir, 'aw') newfile.write('This is bar\n') newfile.close() # ... doesn't change that self.failIf(index_is_dirty()) # only after adding it to the index will it become 'dirty' popen('git add bar.txt') self.failUnless(index_is_dirty()) # Once we've actually committed the change, we're clean again: popen('git ci -m "added bar"', False, False) self.failIf(index_is_dirty())
def svn_log(): """Returns the svn log of the base url as XML element""" code, result = popen('svn log --stop-on-copy --xml %s' % base_url(), False, False) parser = ElementTree.XMLTreeBuilder() parser.feed(''.join(result)) return parser.close()
def local_changes(): """ returns whether there are uncommitted local changes """ result, output = popen('git status', False, False) try: return not output[-1].startswith("nothing to commit") except IndexError: return True
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) stashed = False if local_changes(): stashed = True print "Stashing uncommitted local changes." status, dummy = popen("git stash", False, False) status, dummy = popen("git svn rebase", False, False) for line in dummy: print line if stashed: status, dummy = popen("git stash pop", False, False)
def local_changes(): """ returns whether there are uncommitted local changes """ result, output = popen('git status', False, False) try: return not output[1].startswith("nothing to commit") except IndexError: return True
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) stashed = False if local_changes(): stashed = True print "Stashing uncommitted local changes." status, dummy = popen('git stash', False, False) status, dummy = popen('git svn rebase', False, False) for line in dummy: print line if stashed: status, dummy = popen('git stash pop', False, False)
def git_branch(): """returns the name of the branch git is currently on""" result, output = popen('git branch', False, False) branch = None for line in output: if line.startswith('*'): branch = line.split('*')[-1].strip() break return branch
def test_local_changes(self): # A fresh repository doesn't have uncommitted changes: self.failIf(local_changes()) # Adding a new file on the filesustem... newfile = open("%s/bar.txt" % self.packagedir, 'aw') newfile.write('This is bar\n') newfile.close() # ... changes that self.failUnless(local_changes()) # Once we've actually committed the change, we're clean again: popen('git add bar.txt') self.failUnless(local_changes()) popen('git commit -m "added bar"', False, False) self.failIf(local_changes()) # Modifying an existing file will have the same effect: popen('echo "modified" >> bar.txt') self.failUnless(local_changes()) popen('git add bar.txt') popen('git commit -m "modified bar"', False, False) self.failIf(local_changes())
def test_local_changes(self): # A fresh repository doesn't have uncommitted changes: self.failIf(local_changes()) # Adding a new file on the filesustem... newfile = open("%s/bar.txt" % self.packagedir, 'aw') newfile.write('This is bar\n') newfile.close() # ... changes that self.failUnless(local_changes()) # Once we've actually committed the change, we're clean again: popen('git add bar.txt') self.failUnless(local_changes()) popen('git ci -m "added bar"', False, False) self.failIf(local_changes()) # Modifying an existing file will have the same effect: popen('echo "modified" >> bar.txt') self.failUnless(local_changes()) popen('git add bar.txt') popen('git ci -m "modified bar"', False, False) self.failIf(local_changes())
def clone(): """ A convenience/efficiency wrapper around git-svn clone that tries to figure out the first and last revisions of the given package that need to be cloned and then just clones that range. This is particularly useful for large repositories such as plone and its collective. Original (bash) code from Andreas Zeidler a.k.a. witsch """ if not is_svn(): print "This only works on svn checkouts!" sys.exit(1) package_name = basename() if exists(config.GIT_CACHE + package_name): print "git repository already found in %s%s." % (config.GIT_CACHE, package_name) sys.exit(1) print "Analyzing svn log..." logentries = list(svn_log().getiterator('logentry')) last_revision = logentries[0].attrib['revision'] first_revision = logentries[-1].attrib['revision'] baseurl = base_url() print "Cloning %s from r%s:%s into %s" % ( baseurl, first_revision, last_revision, config.GIT_CACHE) cwd = os.getcwd() if not exists(config.GIT_CACHE): os.mkdir(config.GIT_CACHE) os.chdir(config.GIT_CACHE) popen("git svn clone -r%s:%s %s -s" % (first_revision, last_revision, baseurl)) os.chdir(cwd) return 0
def clone(): """ A convenience/efficiency wrapper around git-svn clone that tries to figure out the first and last revisions of the given package that need to be cloned and then just clones that range. This is particularly useful for large repositories such as plone and its collective. Original (bash) code from Andreas Zeidler a.k.a. witsch """ if not is_svn(): print "This only works on svn checkouts!" sys.exit(1) package_name = basename() if exists(config.GIT_CACHE + package_name): print "git repository already found in %s%s." % (config.GIT_CACHE, package_name) sys.exit(1) print "Analyzing svn log..." logentries = svn_log().getiterator('logentry') last_revision = logentries[0].attrib['revision'] first_revision = logentries[-1].attrib['revision'] baseurl = base_url() print "Cloning %s from r%s:%s into %s" % ( baseurl, first_revision, last_revision, config.GIT_CACHE) cwd = os.getcwd() if not exists(config.GIT_CACHE): os.mkdir(config.GIT_CACHE) os.chdir(config.GIT_CACHE) popen("git svn clone -r%s:%s %s -s" % (first_revision, last_revision, baseurl)) os.chdir(cwd) return 0
def __call__(self): options, args = self.parser.parse_args(self.gitify.args[2:]) try: input = args[0] except IndexError: input = '*' cwd = os.getcwd() updated = 0 for package in glob(abspath("%s/%s" % (config.GIT_CACHE, input))): os.chdir(package) print "fetching %s" % package popen("git svn fetch", options.verbose, True) updated += 1 if updated > 0: print "Done. %d packages updated." % updated else: print "No packages found for %s" % input os.chdir(cwd)
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 shell(self, cmd): """executes the shell command and prints its output""" code, output = popen(cmd, False, False) for line in output: print line
def index_is_dirty(): """ Returns whether anything has been added to the git index """ result, output = popen('git diff --cached', False, False) return len(output) > 0
def svn_info(): """Returns the svn info as XML element""" code, result = popen('svn info --xml .', False, False) parser = ElementTree.XMLTreeBuilder() parser.feed(''.join(result)) return parser.close()
def basename(): return popen('basename $PWD', False, False)[1][0]
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')