summaryrefslogtreecommitdiff
path: root/git/exc.py
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 08:17:32 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 08:17:32 +0800
commit38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2 (patch)
tree8ac0bc1540650cf3befff11735e1421de372fa92 /git/exc.py
parentb30720ee4d9762a03eae4fa7cfa4b0190d81784d (diff)
parent43c00af7e542911cce638cfab49c6a6dc9349e55 (diff)
downloadgitpython-38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2.tar.gz
Merge branch 'black-fmt'
Diffstat (limited to 'git/exc.py')
-rw-r--r--git/exc.py74
1 files changed, 46 insertions, 28 deletions
diff --git a/git/exc.py b/git/exc.py
index 045ea9d2..22fcde0d 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -6,7 +6,7 @@
""" Module containing all exceptions thrown throughout the git package, """
from gitdb.exc import BadName # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614
-from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614
+from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614
from git.compat import safe_decode
from git.util import remove_password_if_present
@@ -22,19 +22,19 @@ if TYPE_CHECKING:
class GitError(Exception):
- """ Base class for all package exceptions """
+ """Base class for all package exceptions"""
class InvalidGitRepositoryError(GitError):
- """ Thrown if the given repository appears to have an invalid format. """
+ """Thrown if the given repository appears to have an invalid format."""
class WorkTreeRepositoryUnsupported(InvalidGitRepositoryError):
- """ Thrown to indicate we can't handle work tree repositories """
+ """Thrown to indicate we can't handle work tree repositories"""
class NoSuchPathError(GitError, OSError):
- """ Thrown if a path could not be access by the system. """
+ """Thrown if a path could not be access by the system."""
class CommandError(GitError):
@@ -49,10 +49,13 @@ class CommandError(GitError):
#: "'%s' failed%s"
_msg = "Cmd('%s') failed%s"
- def __init__(self, command: Union[List[str], Tuple[str, ...], str],
- status: Union[str, int, None, Exception] = None,
- stderr: Union[bytes, str, None] = None,
- stdout: Union[bytes, str, None] = None) -> None:
+ def __init__(
+ self,
+ command: Union[List[str], Tuple[str, ...], str],
+ status: Union[str, int, None, Exception] = None,
+ stderr: Union[bytes, str, None] = None,
+ stdout: Union[bytes, str, None] = None,
+ ) -> None:
if not isinstance(command, (tuple, list)):
command = command.split()
self.command = remove_password_if_present(command)
@@ -62,22 +65,27 @@ class CommandError(GitError):
status = "%s('%s')" % (type(status).__name__, safe_decode(str(status)))
else:
try:
- status = 'exit code(%s)' % int(status)
+ status = "exit code(%s)" % int(status)
except (ValueError, TypeError):
s = safe_decode(str(status))
status = "'%s'" % s if isinstance(status, str) else s
self._cmd = safe_decode(self.command[0])
- self._cmdline = ' '.join(safe_decode(i) for i in self.command)
+ self._cmdline = " ".join(safe_decode(i) for i in self.command)
self._cause = status and " due to: %s" % status or "!"
stdout_decode = safe_decode(stdout)
stderr_decode = safe_decode(stderr)
- self.stdout = stdout_decode and "\n stdout: '%s'" % stdout_decode or ''
- self.stderr = stderr_decode and "\n stderr: '%s'" % stderr_decode or ''
+ self.stdout = stdout_decode and "\n stdout: '%s'" % stdout_decode or ""
+ self.stderr = stderr_decode and "\n stderr: '%s'" % stderr_decode or ""
def __str__(self) -> str:
return (self._msg + "\n cmdline: %s%s%s") % (
- self._cmd, self._cause, self._cmdline, self.stdout, self.stderr)
+ self._cmd,
+ self._cause,
+ self._cmdline,
+ self.stdout,
+ self.stderr,
+ )
class GitCommandNotFound(CommandError):
@@ -90,13 +98,15 @@ class GitCommandNotFound(CommandError):
class GitCommandError(CommandError):
- """ Thrown if execution of the git command fails with non-zero status code. """
-
- def __init__(self, command: Union[List[str], Tuple[str, ...], str],
- status: Union[str, int, None, Exception] = None,
- stderr: Union[bytes, str, None] = None,
- stdout: Union[bytes, str, None] = None,
- ) -> None:
+ """Thrown if execution of the git command fails with non-zero status code."""
+
+ def __init__(
+ self,
+ command: Union[List[str], Tuple[str, ...], str],
+ status: Union[str, int, None, Exception] = None,
+ stderr: Union[bytes, str, None] = None,
+ stdout: Union[bytes, str, None] = None,
+ ) -> None:
super(GitCommandError, self).__init__(command, status, stderr, stdout)
@@ -114,8 +124,13 @@ class CheckoutError(GitError):
were checked out successfully and hence match the version stored in the
index"""
- def __init__(self, message: str, failed_files: Sequence[PathLike], valid_files: Sequence[PathLike],
- failed_reasons: List[str]) -> None:
+ def __init__(
+ self,
+ message: str,
+ failed_files: Sequence[PathLike],
+ valid_files: Sequence[PathLike],
+ failed_reasons: List[str],
+ ) -> None:
Exception.__init__(self, message)
self.failed_files = failed_files
@@ -140,10 +155,13 @@ class HookExecutionError(CommandError):
"""Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned
via standard output"""
- def __init__(self, command: Union[List[str], Tuple[str, ...], str],
- status: Union[str, int, None, Exception],
- stderr: Union[bytes, str, None] = None,
- stdout: Union[bytes, str, None] = None) -> None:
+ def __init__(
+ self,
+ command: Union[List[str], Tuple[str, ...], str],
+ status: Union[str, int, None, Exception],
+ stderr: Union[bytes, str, None] = None,
+ stdout: Union[bytes, str, None] = None,
+ ) -> None:
super(HookExecutionError, self).__init__(command, status, stderr, stdout)
self._msg = "Hook('%s') failed%s"
@@ -152,7 +170,7 @@ class HookExecutionError(CommandError):
class RepositoryDirtyError(GitError):
"""Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten"""
- def __init__(self, repo: 'Repo', message: str) -> None:
+ def __init__(self, repo: "Repo", message: str) -> None:
self.repo = repo
self.message = message