diff --git a/AUTHORS b/AUTHORS index bf0f5e055..781695ba9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,5 +17,6 @@ Contributors are: -Phil Elson -Bernard `Guyzmo` Pratz -Timothy B. Hartman +-Konstantin Popov Portions derived from other open source works and are clearly marked. diff --git a/git/exc.py b/git/exc.py index 69ecc1d00..a737110c8 100644 --- a/git/exc.py +++ b/git/exc.py @@ -9,7 +9,11 @@ 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. """ @@ -17,11 +21,11 @@ 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: @@ -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. @@ -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""" @@ -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): diff --git a/git/test/test_exc.py b/git/test/test_exc.py index 33f440344..28d824d08 100644 --- a/git/test/test_exc.py +++ b/git/test/test_exc.py @@ -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 @@ -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