def inner(repo: Dolt): _, current_branches = repo.branch() branches = [branch.name for branch in current_branches] assert new_branch_name not in branches, 'Branch {} already exists'.format( new_branch_name) logger.info( 'Creating new branch on repo in {} named {} at refspec {}'.format( repo.repo_dir, new_branch_name, refspec)) repo.branch(new_branch_name) return new_branch_name
def inner(repo: Dolt): current_branch, current_branch_list = repo.branch() original_branch = current_branch.name if branch != original_branch and not commit: raise ValueError( 'If writes are to another branch, and commit is not True, writes will be lost' ) if current_branch.name != branch: logger.info('Current branch is {}, checking out {}'.format( current_branch.name, branch)) if branch not in [b.name for b in current_branch_list]: logger.info('{} does not exist, creating'.format(branch)) repo.branch(branch_name=branch) repo.checkout(branch) if transaction_mode: raise NotImplementedError( 'transaction_mode is not yet implemented') tables_updated = [writer(repo) for writer in writers] if commit: if not repo.status().is_clean: logger.info( 'Committing to repo located in {} for tables:\n{}'.format( repo.repo_dir, tables_updated)) for table in tables_updated: repo.add(table) repo.commit(message) else: logger.warning('No changes to repo in:\n{}'.format( repo.repo_dir)) current_branch, branches = repo.branch() if original_branch != current_branch.name: logger.info( 'Checked out {} from {}, checking out {} to restore state'. format([b.name for b in branches], original_branch, original_branch)) repo.checkout(original_branch) return branch
def inner(table_name: str, repo: Dolt) -> DoltTableUpdate: current_branch, _ = repo.branch() if branch and branch != current_branch: repo.checkout(branch) from_commit, to_commit = get_from_commit_to_commit(repo, commit_ref) metadata = MetaData(bind=repo.engine) metadata.reflect() table = metadata.tables[table_name] pks_to_drop = get_dropped_pks(repo.engine, table, from_commit, to_commit) result = _read_from_dolt_diff(repo.engine, table, from_commit, to_commit) return pks_to_drop, result
def _verify_branches(repo: Dolt, branch_list: List[str]): _, branches = repo.branch() assert set(branch.name for branch in branches) == set(branch for branch in branch_list)