From 7d13d24a1f0c329a72074ff52ff2635098f4fe5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Rowlands=20=28=EB=B3=80=EA=B8=B0=ED=98=B8=29?= Date: Fri, 19 Feb 2021 17:18:15 +0900 Subject: [PATCH] pygit/dulwich: implement create branch (#5497) * pygit: implement create branch * dulwich: implement create branch --- dvc/scm/git/backend/dulwich.py | 7 ++++++- dvc/scm/git/backend/pygit2.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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