diff options
-rw-r--r-- | lib/git/objects/base.py | 2 | ||||
-rw-r--r-- | lib/git/objects/commit.py | 4 | ||||
-rw-r--r-- | lib/git/objects/tag.py | 2 | ||||
-rw-r--r-- | lib/git/objects/tree.py | 2 | ||||
-rw-r--r-- | test/git/test_commit.py | 15 |
5 files changed, 20 insertions, 5 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index d3e0d943..9789d72a 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -121,7 +121,7 @@ class IndexObject(Object): self.mode = self._mode_str_to_int(mode) def _set_cache_(self, attr): - if attr in self.__slots__: + if attr in IndexObject.__slots__: # they cannot be retrieved lateron ( not without searching for them ) raise AttributeError( "path and mode attributes must have been set during %s object creation" % type(self).__name__ ) else: diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index 340686ea..69fb3710 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -71,7 +71,7 @@ class Commit(base.Object, Iterable): # END for each parent to convert if self.id and tree is not None: - self.tree = Tree(repo, id=tree) + self.tree = Tree(repo, id=tree, path='') # END id to tree conversion def _set_cache_(self, attr): @@ -80,7 +80,7 @@ class Commit(base.Object, Iterable): to be set. We set all values at once. """ - if attr in self.__slots__: + if attr in Commit.__slots__: temp = Commit.list_items(self.repo, self.id, max_count=1)[0] self.parents = temp.parents self.tree = temp.tree diff --git a/lib/git/objects/tag.py b/lib/git/objects/tag.py index 261d835f..77d715c7 100644 --- a/lib/git/objects/tag.py +++ b/lib/git/objects/tag.py @@ -48,7 +48,7 @@ class TagObject(base.Object): """ Cache all our attributes at once """ - if attr in self.__slots__: + if attr in TagObject.__slots__: output = self.repo.git.cat_file(self.type,self.id) lines = output.split("\n") diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py index 1bc35d95..01dfb37b 100644 --- a/lib/git/objects/tree.py +++ b/lib/git/objects/tree.py @@ -29,7 +29,7 @@ class Tree(base.IndexObject): type = "tree" __slots__ = "_cache" - def __init__(self, repo, id, mode=None, path=None): + def __init__(self, repo, id, mode=0, path=None): super(Tree, self).__init__(repo, id, mode, path) def _set_cache_(self, attr): diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 00af6b52..fd8fc51e 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -229,3 +229,18 @@ class TestCommit(object): commit3 = Commit(self.repo, id='zyx') assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) + + def test_iteration(self): + root = self.repo.tree() + head = self.repo.active_branch + num_objs = 0 + + # find the first commit containing the given path - always do a full + # iteration ( restricted to the path in question ), but in fact it should + # return quite a lot of commits, we just take one and hence abort the operation + for obj in root.traverse(): + num_objs += 1 + commit = Commit.iter_items( self.repo, head, obj.path ).next() + assert obj in commit.tree.traverse() + # END for each object + |