| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c121f60 commit 0bbcf2f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,5 +17,6 @@ Contributors are: | |||
| 17 | 17 | -Phil Elson <pelson _dot_ pub _at_ gmail.com> | |
| 18 | 18 | -Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net> | |
| 19 | 19 | -Timothy B. Hartman <tbhartman _at_ gmail.com> | |
| 20 | + -Konstantin Popov <konstantin.popov.89 _at_ yandex.ru> | ||
| 20 | 21 | ||
| 21 | 22 | Portions derived from other open source works and are clearly marked. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,19 +9,23 @@ | |||
| 9 | 9 | from git.compat import UnicodeMixin, safe_decode, string_types | |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | - class InvalidGitRepositoryError(Exception): | ||
| 12 | + class GitError(Exception): | ||
| 13 | + """ Base class for all package exceptions """ | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + class InvalidGitRepositoryError(GitError): | ||
| 13 | 17 | """ Thrown if the given repository appears to have an invalid format. """ | |
| 14 | 18 | ||
| 15 | 19 | ||
| 16 | 20 | class WorkTreeRepositoryUnsupported(InvalidGitRepositoryError): | |
| 17 | 21 | """ Thrown to indicate we can't handle work tree repositories """ | |
| 18 | 22 | ||
| 19 | 23 | ||
| 20 | - class NoSuchPathError(OSError): | ||
| 24 | + class NoSuchPathError(GitError, OSError): | ||
| 21 | 25 | """ Thrown if a path could not be access by the system. """ | |
| 22 | 26 | ||
| 23 | 27 | ||
| 24 | - class CommandError(UnicodeMixin, Exception): | ||
| 28 | + class CommandError(UnicodeMixin, GitError): | ||
| 25 | 29 | """Base class for exceptions thrown at every stage of `Popen()` execution. | |
| 26 | 30 | ||
| 27 | 31 | :param command: | |
@@ -74,7 +78,7 @@ def __init__(self, command, status, stderr=None, stdout=None): | |||
| 74 | 78 | super(GitCommandError, self).__init__(command, status, stderr, stdout) | |
| 75 | 79 | ||
| 76 | 80 | ||
| 77 | - class CheckoutError(Exception): | ||
| 81 | + class CheckoutError(GitError): | ||
| 78 | 82 | """Thrown if a file could not be checked out from the index as it contained | |
| 79 | 83 | changes. | |
| 80 | 84 | ||
@@ -98,7 +102,7 @@ def __str__(self): | |||
| 98 | 102 | return Exception.__str__(self) + ":%s" % self.failed_files | |
| 99 | 103 | ||
| 100 | 104 | ||
| 101 | - class CacheError(Exception): | ||
| 105 | + class CacheError(GitError): | ||
| 102 | 106 | ||
| 103 | 107 | """Base for all errors related to the git index, which is called cache internally""" | |
| 104 | 108 | ||
@@ -117,7 +121,7 @@ def __init__(self, command, status, stderr=None, stdout=None): | |||
| 117 | 121 | self._msg = u"Hook('%s') failed%s" | |
| 118 | 122 | ||
| 119 | 123 | ||
| 120 | - class RepositoryDirtyError(Exception): | ||
| 124 | + class RepositoryDirtyError(GitError): | ||
| 121 | 125 | """Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten""" | |
| 122 | 126 | ||
| 123 | 127 | def __init__(self, repo, message): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,10 +10,17 @@ | |||
| 10 | 10 | ||
| 11 | 11 | import ddt | |
| 12 | 12 | from git.exc import ( | |
| 13 | + InvalidGitRepositoryError, | ||
| 14 | + WorkTreeRepositoryUnsupported, | ||
| 15 | + NoSuchPathError, | ||
| 13 | 16 | CommandError, | |
| 14 | 17 | GitCommandNotFound, | |
| 15 | 18 | GitCommandError, | |
| 19 | + CheckoutError, | ||
| 20 | + CacheError, | ||
| 21 | + UnmergedEntriesError, | ||
| 16 | 22 | HookExecutionError, | |
| 23 | + RepositoryDirtyError, | ||
| 17 | 24 | ) | |
| 18 | 25 | from git.test.lib import TestBase | |
| 19 | 26 | ||
@@ -44,6 +51,26 @@ | |||
| 44 | 51 | @ddt.ddt | |
| 45 | 52 | class TExc(TestBase): | |
| 46 | 53 | ||
| 54 | + def test_ExceptionsHaveBaseClass(self): | ||
| 55 | + from git.exc import GitError | ||
| 56 | + self.assertIsInstance(GitError(), Exception) | ||
| 57 | + | ||
| 58 | + exception_classes = [ | ||
| 59 | + InvalidGitRepositoryError, | ||
| 60 | + WorkTreeRepositoryUnsupported, | ||
| 61 | + NoSuchPathError, | ||
| 62 | + CommandError, | ||
| 63 | + GitCommandNotFound, | ||
| 64 | + GitCommandError, | ||
| 65 | + CheckoutError, | ||
| 66 | + CacheError, | ||
| 67 | + UnmergedEntriesError, | ||
| 68 | + HookExecutionError, | ||
| 69 | + RepositoryDirtyError, | ||
| 70 | + ] | ||
| 71 | + for ex_class in exception_classes: | ||
| 72 | + self.assertTrue(issubclass(ex_class, GitError)) | ||
| 73 | + | ||
| 47 | 74 | @ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings))) | |
| 48 | 75 | def test_CommandError_unicode(self, case): | |
| 49 | 76 | argv, (cause, subs), stream = case | |
| Back | FazBrowse Home | New Git URL |
0 commit comments