Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Contributors are:
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
-Timothy B. Hartman <tbhartman _at_ gmail.com>
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>

Portions derived from other open source works and are clearly marked.
16 changes: 10 additions & 6 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
from git.compat import UnicodeMixin, safe_decode, string_types


class InvalidGitRepositoryError(Exception):
class GitError(Exception):
""" Base class for all package exceptions """


class InvalidGitRepositoryError(GitError):
""" Thrown if the given repository appears to have an invalid format. """


class WorkTreeRepositoryUnsupported(InvalidGitRepositoryError):
""" Thrown to indicate we can't handle work tree repositories """


class NoSuchPathError(OSError):
class NoSuchPathError(GitError, OSError):
""" Thrown if a path could not be access by the system. """


class CommandError(UnicodeMixin, Exception):
class CommandError(UnicodeMixin, GitError):
"""Base class for exceptions thrown at every stage of `Popen()` execution.

:param command:
Expand Down Expand Up @@ -74,7 +78,7 @@ def __init__(self, command, status, stderr=None, stdout=None):
super(GitCommandError, self).__init__(command, status, stderr, stdout)


class CheckoutError(Exception):
class CheckoutError(GitError):
"""Thrown if a file could not be checked out from the index as it contained
changes.

Expand All @@ -98,7 +102,7 @@ def __str__(self):
return Exception.__str__(self) + ":%s" % self.failed_files


class CacheError(Exception):
class CacheError(GitError):

"""Base for all errors related to the git index, which is called cache internally"""

Expand All @@ -117,7 +121,7 @@ def __init__(self, command, status, stderr=None, stdout=None):
self._msg = u"Hook('%s') failed%s"


class RepositoryDirtyError(Exception):
class RepositoryDirtyError(GitError):
"""Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten"""

def __init__(self, repo, message):
Expand Down
27 changes: 27 additions & 0 deletions git/test/test_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

import ddt
from git.exc import (
InvalidGitRepositoryError,
WorkTreeRepositoryUnsupported,
NoSuchPathError,
CommandError,
GitCommandNotFound,
GitCommandError,
CheckoutError,
CacheError,
UnmergedEntriesError,
HookExecutionError,
RepositoryDirtyError,
)
from git.test.lib import TestBase

Expand Down Expand Up @@ -44,6 +51,26 @@
@ddt.ddt
class TExc(TestBase):

def test_ExceptionsHaveBaseClass(self):
from git.exc import GitError
self.assertIsInstance(GitError(), Exception)

exception_classes = [
InvalidGitRepositoryError,
WorkTreeRepositoryUnsupported,
NoSuchPathError,
CommandError,
GitCommandNotFound,
GitCommandError,
CheckoutError,
CacheError,
UnmergedEntriesError,
HookExecutionError,
RepositoryDirtyError,
]
for ex_class in exception_classes:
self.assertTrue(issubclass(ex_class, GitError))

@ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
def test_CommandError_unicode(self, case):
argv, (cause, subs), stream = case
Expand Down