Skip to content

Commit 024adf3

Browse files
committed
Fixed tests far enough to allow basic repository tests to be applied to any of the new database types. This reduces code duplication to the mere minimum, but allows custom tests to be added on top easily and flexibly
1 parent 112bb16 commit 024adf3

File tree

21 files changed

+152
-65
lines changed

21 files changed

+152
-65
lines changed

doc/source/changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ NEXT
2121
* ### Module Changes ###
2222

2323
* Removed rev_parse function from git.repo.fun - the respective functionality is available only through the repository's rev_parse method, which might in turn translate to any implementation.
24+
25+
* ### Exceptions ###
26+
27+
* There is a new common base for all exceptions git-python will throw, namely `GitPythonError`.
2428

2529
0.3.1 Beta 2
2630
============

git/db/cmd/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
2-
from complex import *
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php

git/db/cmd/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
bin_to_hex,
1616
hex_to_bin
1717
)
18-
from git.db.compat import RepoCompatInterface
18+
from git.db.compat import RepoCompatibilityInterface
1919
from git.util import RemoteProgress
2020
from git.db.interface import FetchInfo as GitdbFetchInfo
2121
from git.db.interface import PushInfo as GitdbPushInfo

git/db/cmd/complex.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
"""Module with our own git implementation - it uses the git command"""
22

3-
from git.db.compat import RepoCompatInterface
3+
from git.db.compat import RepoCompatibilityInterface
44
from git.db.py.complex import PureGitDB
55

66
from base import *
77

88

9-
__all__ = ['GitCmdDB', 'CmdCompatibilityGitDB']
9+
__all__ = ['GitCmdDB', 'CmdCompatibilityGitDB', 'CmdPartialGitDB']
1010

1111

12-
class CmdGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin,
13-
CmdHighLevelRepository, PureGitDB):
12+
class CmdPartialGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin,
13+
CmdHighLevelRepository ):
14+
"""Utility repository which only partially implements all required methods.
15+
It cannot be reliably used alone, but is provided to allow mixing it with other
16+
implementations"""
1417
pass
1518

16-
class CmdCompatibilityGitDB(CmdGitDB, RepoCompatInterface):
19+
20+
class CmdGitDB(CmdPartialGitDB, PureGitDB):
21+
"""A database which fills in its missing implementation using the pure python
22+
implementation"""
23+
pass
24+
25+
26+
class CmdCompatibilityGitDB(CmdGitDB, RepoCompatibilityInterface):
1727
"""Command git database with the compatabilty interface added for 0.3x code"""

git/db/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module providing adaptors to maintain backwards compatability"""
66

7-
class RepoCompatInterface(object):
7+
class RepoCompatibilityInterface(object):
88
"""Interface to install backwards compatability of the new complex repository
99
types with the previous, all in one, repository."""
1010

git/db/complex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Module with many useful complex databases with different useful combinations of primary implementations"""
22

33
from py.complex import PureGitDB
4-
from cmd.complex import CmdGitDB
5-
from compat import RepoCompatInterface
4+
from cmd.complex import CmdPartialGitDB
5+
from compat import RepoCompatibilityInterface
66

7-
__all__ = ['CmdGitDB', 'PureGitDB', 'PureCmdGitDB']
7+
__all__ = ['CmdPartialGitDB', 'PureGitDB', 'PureCmdGitDB']
88

9-
class PureCmdGitDB(PureGitDB, CmdGitDB, RepoCompatInterface):
9+
class PureCmdGitDB(PureGitDB, CmdPartialGitDB, RepoCompatibilityInterface):
1010
"""Repository which uses the pure implementation primarily, but falls back
1111
to the git command implementation. Please note that the CmdGitDB does it
1212
the opposite way around."""

git/db/py/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
6-
from complex import *

git/db/py/complex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ref import PureReferenceDB
2121
from submodule import PureSubmoduleDB
2222

23-
from git.db.compat import RepoCompatInterface
23+
from git.db.compat import RepoCompatibilityInterface
2424

2525
from git.util import (
2626
LazyMixin,
@@ -123,6 +123,6 @@ def __init__(self, root_path):
123123

124124

125125

126-
class PureCompatibilityGitDB(PureGitDB, RepoCompatInterface):
126+
class PureCompatibilityGitDB(PureGitDB, RepoCompatibilityInterface):
127127
"""Pure git database with a compatability layer required by 0.3x code"""
128128

git/db/py/resolve.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
from git.db.interface import ReferencesMixin
55
from git.exc import BadObject
6-
from git.refs import SymbolicReference
7-
from git.objects.base import Object
8-
from git.objects.commit import Commit
6+
from git.refs import (
7+
SymbolicReference,
8+
Reference,
9+
HEAD,
10+
Head,
11+
TagReference
12+
)
913
from git.refs.head import HEAD
1014
from git.refs.headref import Head
1115
from git.refs.tag import TagReference
16+
17+
from git.objects.base import Object
18+
from git.objects.commit import Commit
1219
from git.util import (
1320
join,
1421
isdir,

git/exc.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
from util import to_hex_sha
99

10-
class ODBError(Exception):
10+
class GitPythonError(Exception):
11+
"""Base exception for all git-python related errors"""
12+
13+
class ODBError(GitPythonError):
1114
"""All errors thrown by the object database"""
1215

1316

@@ -40,15 +43,15 @@ class UnsupportedOperation(ODBError):
4043
"""Thrown if the given operation cannot be supported by the object database"""
4144

4245

43-
class InvalidGitRepositoryError(Exception):
46+
class InvalidGitRepositoryError(GitPythonError):
4447
""" Thrown if the given repository appears to have an invalid format. """
4548

4649

47-
class NoSuchPathError(OSError):
50+
class NoSuchPathError(GitPythonError):
4851
""" Thrown if a path could not be access by the system. """
4952

5053

51-
class GitCommandError(Exception):
54+
class GitCommandError(GitPythonError):
5255
""" Thrown if execution of the git command fails with non-zero status code. """
5356
def __init__(self, command, status, stderr=None):
5457
self.stderr = stderr
@@ -60,7 +63,7 @@ def __str__(self):
6063
(' '.join(str(i) for i in self.command), self.status, self.stderr))
6164

6265

63-
class CheckoutError( Exception ):
66+
class CheckoutError(GitPythonError):
6467
"""Thrown if a file could not be checked out from the index as it contained
6568
changes.
6669
@@ -83,7 +86,7 @@ def __str__(self):
8386
return Exception.__str__(self) + ":%s" % self.failed_files
8487

8588

86-
class CacheError(Exception):
89+
class CacheError(GitPythonError):
8790
"""Base for all errors related to the git index, which is called cache internally"""
8891

8992

0 commit comments

Comments
 (0)