diff --git a/dvc/scm/git/backend/dulwich.py b/dvc/scm/git/backend/dulwich.py index 865aa50a9..98eec2ab6 100644 --- a/dvc/scm/git/backend/dulwich.py +++ b/dvc/scm/git/backend/dulwich.py @@ -200,7 +200,12 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method raise NotImplementedError def branch(self, branch: str): - raise NotImplementedError + from dulwich.porcelain import Error, branch_create + + try: + branch_create(self.root_dir, branch) + except Error as exc: + raise SCMError(f"Failed to create branch '{branch}'") from exc def tag(self, tag: str): raise NotImplementedError diff --git a/dvc/scm/git/backend/pygit2.py b/dvc/scm/git/backend/pygit2.py index 7f26eb6d0..e8cb3a6e7 100644 --- a/dvc/scm/git/backend/pygit2.py +++ b/dvc/scm/git/backend/pygit2.py @@ -116,7 +116,13 @@ class Pygit2Backend(BaseGitBackend): # pylint:disable=abstract-method raise NotImplementedError def branch(self, branch: str): - raise NotImplementedError + from pygit2 import GitError + + try: + commit = self.repo[self.repo.head.target] + self.repo.create_branch(branch, commit) + except GitError as exc: + raise SCMError(f"Failed to create branch '{branch}'") from exc def tag(self, tag: str): raise NotImplementedError