diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 18:40:35 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 18:40:35 +0200 |
commit | d97afa24ad1ae453002357e5023f3a116f76fb17 (patch) | |
tree | 6cfda2fd99649a49062d397dda5864ae9b24c3ba | |
parent | babf5765da3e328cc1060cb9b37fbdeb6fd58350 (diff) | |
download | gitpython-d97afa24ad1ae453002357e5023f3a116f76fb17.tar.gz |
Improved testing of index against trees, tests succeed with next commit
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | lib/git/index.py | 2 | ||||
-rw-r--r-- | test/git/test_index.py | 18 |
3 files changed, 20 insertions, 5 deletions
@@ -14,7 +14,10 @@ General deleted. * References should be parsed 'manually' to get around command invocation, but be sure to be able to read packed refs. - +* Effectively Objects only store hexsha's in their id attributes, so in fact + it should be renamed to 'sha'. There was a time when references where allowed as + well, but now objects will be 'baked' to the actual sha to assure comparisons work. + Config ------ * Expand .get* methods of GitConfigParser to support default value. If it is not None, diff --git a/lib/git/index.py b/lib/git/index.py index 6b51c5c7..1042d7b8 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -288,7 +288,7 @@ class Index(object): If 1 Tree is given, it will just be read into a new index If 2 Trees are given, they will be merged into a new index using a two way merge algorithm. Tree 1 is the 'current' tree, tree 2 is the 'other' - one. + one. It behaves like a fast-forward. If 3 Trees are given, a 3-way merge will be performed with the first tree being the common ancestor of tree 2 and tree 3. Tree 2 is the 'current' tree, tree 3 is the 'other' one diff --git a/test/git/test_index.py b/test/git/test_index.py index ead231d1..d256e7c0 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -41,6 +41,18 @@ class TestTree(TestCase): index_output.seek(0) assert index_output.read() == fixture("index_merge") + def _cmp_tree_index(self, tree, index): + # fail unless both objects contain the same paths and blobs + if isinstance(tree, str): + tree = self.repo.commit(tree).tree + + num_blobs = 0 + for blob in tree.traverse(predicate = lambda e: e.type == "blob"): + assert (blob.path,0) in index.entries + num_blobs += 1 + # END for each blob in tree + assert num_blobs == len(index.entries) + def test_merge(self): common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541" cur_sha = "4b43ca7ff72d5f535134241e7c797ddc9c7a3573" @@ -49,12 +61,12 @@ class TestTree(TestCase): # simple index from tree base_index = Index.from_tree(self.repo, common_ancestor_sha) assert base_index.entries + self._cmp_tree_index(common_ancestor_sha, base_index) - # merge two trees + # merge two trees - its like a fast-forward two_way_index = Index.from_tree(self.repo, common_ancestor_sha, cur_sha) assert two_way_index.entries - for e in two_way_index.entries.values(): - print "%i | %s" % ( e.stage, e.path ) + self._cmp_tree_index(cur_sha, two_way_index) # merge three trees - here we have a merge conflict tree_way_index = Index.from_tree(self.repo, common_ancestor_sha, cur_sha, other_sha) |