Skip to content

Commit 0bbcf2f

Browse files
konstantin-popovByron
authored andcommitted
Add base class for package exceptions.
1 parent c121f60 commit 0bbcf2f

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ Contributors are:
1717
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
1818
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
1919
-Timothy B. Hartman <tbhartman _at_ gmail.com>
20+
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
2021

2122
Portions derived from other open source works and are clearly marked.

git/exc.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@
99
from git.compat import UnicodeMixin, safe_decode, string_types
1010

1111

12-
class InvalidGitRepositoryError(Exception):
12+
class GitError(Exception):
13+
""" Base class for all package exceptions """
14+
15+
16+
class InvalidGitRepositoryError(GitError):
1317
""" Thrown if the given repository appears to have an invalid format. """
1418

1519

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

1923

20-
class NoSuchPathError(OSError):
24+
class NoSuchPathError(GitError, OSError):
2125
""" Thrown if a path could not be access by the system. """
2226

2327

24-
class CommandError(UnicodeMixin, Exception):
28+
class CommandError(UnicodeMixin, GitError):
2529
"""Base class for exceptions thrown at every stage of `Popen()` execution.
2630
2731
:param command:
@@ -74,7 +78,7 @@ def __init__(self, command, status, stderr=None, stdout=None):
7478
super(GitCommandError, self).__init__(command, status, stderr, stdout)
7579

7680

77-
class CheckoutError(Exception):
81+
class CheckoutError(GitError):
7882
"""Thrown if a file could not be checked out from the index as it contained
7983
changes.
8084
@@ -98,7 +102,7 @@ def __str__(self):
98102
return Exception.__str__(self) + ":%s" % self.failed_files
99103

100104

101-
class CacheError(Exception):
105+
class CacheError(GitError):
102106

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

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

119123

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

123127
def __init__(self, repo, message):

git/test/test_exc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010

1111
import ddt
1212
from git.exc import (
13+
InvalidGitRepositoryError,
14+
WorkTreeRepositoryUnsupported,
15+
NoSuchPathError,
1316
CommandError,
1417
GitCommandNotFound,
1518
GitCommandError,
19+
CheckoutError,
20+
CacheError,
21+
UnmergedEntriesError,
1622
HookExecutionError,
23+
RepositoryDirtyError,
1724
)
1825
from git.test.lib import TestBase
1926

@@ -44,6 +51,26 @@
4451
@ddt.ddt
4552
class TExc(TestBase):
4653

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+
4774
@ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
4875
def test_CommandError_unicode(self, case):
4976
argv, (cause, subs), stream = case

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy