def delete(self, branch_name, origin, with_db): """Delete the specified branch. args: branch_name -- name of branch to delete origin -- if True, delete the branch from the remote repository as well with_db -- if True, call drop_databases for the current branch name """ sh('git branch -D %s' % branch_name) if origin: sh('git push origin :%s' % branch_name) if with_db: self.drop_databases(branch_name)
def create(self, branch_name, origin, with_db): """Create a new branch. args: branch_name -- name of new branch origin -- if True, push new branch to remote repository with_db -- if True, call copy_databases for new branch """ sh('git branch %s' % branch_name) if origin: sh('git push -u origin %s' % branch_name) if with_db: self.copy_databases(branch_name)
def setup_dbs(databases, branches_to_ignore=None): """Append the current branch name to NAME values of all databases. args: databases -- django settings DATABASES branches_to_ignore -- if the current branch is in branches_to_ignore, the names of databases will not be changed. (default None) """ curr_branch = sh('git rev-parse --abbrev-ref HEAD', False) if branches_to_ignore is None: branches_to_ignore = () if curr_branch not in branches_to_ignore: for db in databases.values(): db['NAME'] = db_name(db['NAME'], curr_branch)
def checkout(self, branch_name, origin, with_db): """Checkout the specified branch. args: branch_name -- the name of the branch to git checkout origin -- if True, fetch and track the branch from origin with_db -- if True, copy databases for the checked out branch """ if origin: sh('git fetch') sh('git checkout --track -b {b} origin/{b}'.format(b=branch_name)) if with_db: self.copy_databases(branch_name) else: sh('git checkout %s' % branch_name)
def _perform_branch_db_operation(self, branch_name, method_name): for db in self.databases.values(): engine = get_engine(db, db_name(db['NAME'], branch_name)) sh(operator.methodcaller(method_name)(engine))