diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | lib/git/__init__.py | 2 | ||||
-rw-r--r-- | lib/git/base.py | 27 | ||||
-rw-r--r-- | test/git/test_base.py | 48 | ||||
-rw-r--r-- | test/git/test_commit.py | 4 | ||||
-rw-r--r-- | test/git/test_repo.py | 2 |
6 files changed, 53 insertions, 33 deletions
@@ -13,6 +13,9 @@ General * Adjusted class hierarchy to generally allow comparison and hash for Objects and Refs * Improved Tag object which now is a Ref that may contain a tag object with additional Information +* id_abbrev method has been removed as it could not assure the returned short SHA's + where unique +* removed basename method from Objects with path's as it replicated features of os.path Diff ---- diff --git a/lib/git/__init__.py b/lib/git/__init__.py index 45cb4673..5ce3c122 100644 --- a/lib/git/__init__.py +++ b/lib/git/__init__.py @@ -18,7 +18,7 @@ from git.cmd import Git from git.head import Head from git.repo import Repo from git.stats import Stats -from git.tag import Tag +from git.tag import Tag,TagRef,TagObject from git.tree import Tree from git.utils import dashify from git.utils import touch diff --git a/lib/git/base.py b/lib/git/base.py index 4e5298e4..252ebe4b 100644 --- a/lib/git/base.py +++ b/lib/git/base.py @@ -110,14 +110,6 @@ class Object(LazyMixin): """ return '<git.%s "%s">' % (self.__class__.__name__, self.id) - @property - def id_abbrev(self): - """ - Returns - First 7 bytes of the commit's sha id as an abbreviation of the full string. - """ - return self.id[0:7] - @classmethod def get_type_by_name(cls, object_type_name): """ @@ -169,12 +161,15 @@ class IndexObject(Object): ``path`` : str is the path to the file in the file system, relative to the git repository root, i.e. file.ext or folder/other.ext + + NOTE + Path may not be set of the index object has been created directly as it cannot + be retrieved without knowing the parent tree. """ super(IndexObject, self).__init__(repo, id) + self._set_self_from_args_(locals()) if isinstance(mode, basestring): - mode = self._mode_str_to_int(mode) - self.mode = mode - self.path = path + self.mode = self._mode_str_to_int(mode) @classmethod def _mode_str_to_int( cls, modestr ): @@ -191,14 +186,6 @@ class IndexObject(Object): mode += int(char) << iteration*3 # END for each char return mode - - @property - def basename(self): - """ - Returns - The basename of the IndexObject's file path - """ - return os.path.basename(self.path) class Ref(object): @@ -222,7 +209,7 @@ class Ref(object): self.object = object def __str__(self): - return self.name() + return self.name def __repr__(self): return '<git.%s "%s">' % (self.__class__.__name__, self.path) diff --git a/test/git/test_base.py b/test/git/test_base.py index 787b92b6..8f522cec 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -8,32 +8,66 @@ import time from test.testlib import * from git import * import git.base as base +from itertools import chain class TestBase(object): type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070"), ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79"), - ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c") ) + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c"), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10") ) def setup(self): self.repo = Repo(GIT_REPO) - def test_base(self): - # test interface of base classes - fcreators = (self.repo.blob, self.repo.tree, self.repo.commit ) + def test_base_object(self): + # test interface of base object classes + fcreators = (self.repo.blob, self.repo.tree, self.repo.commit, lambda id: TagObject(self.repo,id) ) assert len(fcreators) == len(self.type_tuples) - for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): + + s = set() + num_objs = 0 + num_index_objs = 0 + for fcreator, (typename, hexsha) in zip(fcreators, self.type_tuples): item = fcreator(hexsha) + num_objs += 1 assert item.id == hexsha assert item.type == typename assert item.size + assert item.data + assert item == item + assert not item != item + assert str(item) == item.id + assert repr(item) + s.add(item) + + if isinstance(item, base.IndexObject): + num_index_objs += 1 + if hasattr(item,'path'): # never runs here + assert not item.path.startswith("/") # must be relative + assert isinstance(item.mode, int) + # END index object check # END for each object type to create - assert False,"TODO: Test for all types" + # each has a unique sha + assert len(s) == num_objs + assert num_index_objs == 2 + def test_tags(self): # tag refs can point to tag objects or to commits - assert False, "TODO: Tag handling" + s = set() + ref_count = 0 + for ref in chain(self.repo.tags, self.repo.heads): + ref_count += 1 + assert isinstance(ref, base.Ref) + assert str(ref) == ref.name + assert repr(ref) + assert ref == ref + assert not ref != ref + s.add(ref) + # END for each ref + assert len(s) == ref_count def test_get_type_by_name(self): for tname in base.Object.TYPES: diff --git a/test/git/test_commit.py b/test/git/test_commit.py index ab1801ee..71dad562 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -24,10 +24,6 @@ class TestCommit(object): assert_true(git.called) assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017', '--', ''), {'pretty': 'raw', 'max_count': 1})) - @patch_object(Git, '_call_process') - def test_id_abbrev(self, git): - git.return_value = fixture('rev_list_commit_idabbrev') - assert_equal('80f136f', self.repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev) @patch_object(Git, '_call_process') def test_diff(self, git): diff --git a/test/git/test_repo.py b/test/git/test_repo.py index aec85506..421b8256 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -58,7 +58,7 @@ class TestRepo(object): assert_equal("implement Grit#heads", c.message) c = commits[1] - assert_equal((,), c.parents) + assert_equal(tuple(), c.parents) c = commits[2] assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents)) |