def _get_db(self, config: DoltConfig): if config.id in self._dbcache: return self._dbcache[config.id] # TODO: clone remote try: Dolt.init(repo_dir=config.database) except DoltException as e: pass if ".dolt" not in os.listdir(config.database): raise ValueError( f"Passed a path {config.database} that is not a Dolt database directory" ) doltdb = Dolt(repo_dir=config.database) current_branch, branches = doltdb.branch() logger.info( f"Dolt database in {config.database} at branch {current_branch.name}, using branch {config.branch}" ) if config.branch == current_branch.name: pass elif config.branch not in [branch.name for branch in branches]: raise ValueError(f"Passed branch '{config.branch}' that does not exist") else: doltdb.checkout(config.branch, checkout_branch=False) if not doltdb.status().is_clean: raise Exception( "DoltDT as context manager requires clean working set for transaction semantics" ) if not config.commit: config.commit = self._get_latest_commit_hash(doltdb) self._dbcache[config.id] = doltdb return doltdb
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)