Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions src/scmrepo/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Union,
)

from funcy import cached_property
from funcy import cached_property, reraise

from scmrepo.exceptions import (
AuthError,
Expand Down Expand Up @@ -284,17 +284,18 @@ def add(self, paths: Union[str, Iterable[str]], update=False):

def commit(self, msg: str, no_verify: bool = False):
from dulwich.errors import CommitError
from dulwich.porcelain import commit
from dulwich.porcelain import Error, TimezoneFormatError, commit
from dulwich.repo import InvalidUserIdentity

try:
commit(self.root_dir, message=msg, no_verify=no_verify)
except CommitError as exc:
raise SCMError("Git commit failed") from exc
except InvalidUserIdentity as exc:
raise SCMError(
"Git username and email must be configured"
) from exc
with reraise((Error, CommitError), SCMError("Git commit failed")):
try:
commit(self.root_dir, message=msg, no_verify=no_verify)
except InvalidUserIdentity as exc:
raise SCMError(
"Git username and email must be configured"
) from exc
except TimezoneFormatError as exc:
raise SCMError("Invalid Git timestamp") from exc

def checkout(
self,
Expand All @@ -311,16 +312,17 @@ def fetch(
force: bool = False,
unshallow: bool = False,
):
from dulwich.porcelain import fetch
from dulwich.porcelain import Error, fetch
from dulwich.protocol import DEPTH_INFINITE

remote_b = os.fsencode(remote) if remote else b"origin"
fetch(
self.repo,
remote_location=remote_b,
force=force,
depth=DEPTH_INFINITE if unshallow else None,
)
with reraise(Error, SCMError("Git fetch failed")):
remote_b = os.fsencode(remote) if remote else b"origin"
fetch(
self.repo,
remote_location=remote_b,
force=force,
depth=DEPTH_INFINITE if unshallow else None,
)

def pull(self, **kwargs):
raise NotImplementedError
Expand Down Expand Up @@ -768,11 +770,13 @@ def checkout_index(
def status(
self, ignored: bool = False, untracked_files: str = "all"
) -> Tuple[Mapping[str, Iterable[str]], Iterable[str], Iterable[str]]:
from dulwich.porcelain import Error
from dulwich.porcelain import status as git_status

staged, unstaged, untracked = git_status(
self.root_dir, ignored=ignored, untracked_files=untracked_files
)
with reraise(Error, SCMError("Git status failed")):
staged, unstaged, untracked = git_status(
self.root_dir, ignored=ignored, untracked_files=untracked_files
)

return (
{
Expand Down