Exemplo n.º 1
0
    def __call__(self, db: dolt.Dolt):
        starting_head = db.head
        starting_branch = db.active_branch

        try:
            self.checkout(db)
            yield db
        finally:
            self.merge(db, starting_branch)
            db.checkout(starting_branch, error=False)
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 def checkout(self, db: dolt.Dolt):
     # branch must exist
     db.checkout(branch=self.branch, error=False)
Exemplo n.º 4
0
def test_checkout_non_existent_branch(doltdb):
    repo = Dolt(doltdb)
    repo.checkout("main")