From 4a534eba97db3c2cfb2926368756fd633d25c056 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 12:24:47 +0200 Subject: Added frame for index implementation and testing --- test/git/test_index.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/git/test_index.py (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py new file mode 100644 index 00000000..f58405d2 --- /dev/null +++ b/test/git/test_index.py @@ -0,0 +1,17 @@ +# test_index.py +# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +from test.testlib import * +from git import * + +class TestTree(TestCase): + + @classmethod + def setUpAll(cls): + cls.repo = Repo(GIT_REPO) + + def test_base(self): + self.fail("TODO") -- cgit v1.2.1 From 50a9920b1bd9e6e8cf452c774c499b0b9014ccef Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 17:04:23 +0200 Subject: Added initial version of the index reading from file - IndexEntry interface is to be improved though, writing needs to be implemented as well --- test/git/test_index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index f58405d2..272e68b3 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -14,4 +14,6 @@ class TestTree(TestCase): cls.repo = Repo(GIT_REPO) def test_base(self): - self.fail("TODO") + index = Index.from_file(fixture_path("index")) + assert index.entries + assert index.version > 0 -- cgit v1.2.1 From 56823868efddd3bdbc0b624cdc79adc3a2e94a75 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 21:32:00 +0200 Subject: Improved tuple access of EntryIndex class including test, stage and type access still needs to be decoded though --- test/git/test_index.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 272e68b3..91ce22fd 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -6,6 +6,7 @@ from test.testlib import * from git import * +import inspect class TestTree(TestCase): @@ -14,6 +15,19 @@ class TestTree(TestCase): cls.repo = Repo(GIT_REPO) def test_base(self): + # read from file index = Index.from_file(fixture_path("index")) assert index.entries assert index.version > 0 + + # test entry + last_val = None + entry = index.entries.itervalues().next() + for name, method in inspect.getmembers(entry,inspect.ismethod): + val = method(entry) + assert val != last_val + last_val = val + # END for each method + + # write + self.fail("writing, object type and stage") -- cgit v1.2.1 From 152bab7eb64e249122fefab0d5531db1e065f539 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Oct 2009 22:05:51 +0200 Subject: improved IndexEntry type and added test for parsing of the stage --- test/git/test_index.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 91ce22fd..86bde655 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -23,11 +23,15 @@ class TestTree(TestCase): # test entry last_val = None entry = index.entries.itervalues().next() - for name, method in inspect.getmembers(entry,inspect.ismethod): - val = method(entry) - assert val != last_val - last_val = val + for attr in ("path","ctime","mtime","dev","inode","mode","uid", + "gid","size","sha","stage"): + val = getattr(entry, attr) # END for each method + # test stage + index_merge = Index.from_file(fixture_path("index_merge")) + assert len(list(e for e in index_merge.entries.itervalues() if e.stage != 0 )) + # write - self.fail("writing, object type and stage") + self.fail("writing, what is 'size' attribute for ?") + -- cgit v1.2.1 From b9d6494f1075e5370a20e406c3edb102fca12854 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 13:34:43 +0200 Subject: index writing added including simple test, improved docs of IndexEntry --- test/git/test_index.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 86bde655..7a0e21eb 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -7,6 +7,7 @@ from test.testlib import * from git import * import inspect +import os class TestTree(TestCase): @@ -30,8 +31,13 @@ class TestTree(TestCase): # test stage index_merge = Index.from_file(fixture_path("index_merge")) + assert len(index_merge.entries) == 106 assert len(list(e for e in index_merge.entries.itervalues() if e.stage != 0 )) - # write - self.fail("writing, what is 'size' attribute for ?") + # write the data - it must match the original + index_output = os.tmpfile() + index_merge.write(index_output) + + index_output.seek(0) + assert index_output.read() == fixture("index_merge") -- cgit v1.2.1 From babf5765da3e328cc1060cb9b37fbdeb6fd58350 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 16:52:25 +0200 Subject: Initial version of merge including tests for one-way, two-way and tree-way merge --- test/git/test_index.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 7a0e21eb..ead231d1 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -41,3 +41,24 @@ class TestTree(TestCase): index_output.seek(0) assert index_output.read() == fixture("index_merge") + def test_merge(self): + common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541" + cur_sha = "4b43ca7ff72d5f535134241e7c797ddc9c7a3573" + other_sha = "39f85c4358b7346fee22169da9cad93901ea9eb9" + + # simple index from tree + base_index = Index.from_tree(self.repo, common_ancestor_sha) + assert base_index.entries + + # merge two trees + 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 ) + + # merge three trees - here we have a merge conflict + tree_way_index = Index.from_tree(self.repo, common_ancestor_sha, cur_sha, other_sha) + assert len(list(e for e in tree_way_index.entries.values() if e.stage != 0)) + + def test_custom_commit(self): + self.fail("Custom commit:write tree, make commit with custom parents") -- cgit v1.2.1 From d97afa24ad1ae453002357e5023f3a116f76fb17 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 18:40:35 +0200 Subject: Improved testing of index against trees, tests succeed with next commit --- test/git/test_index.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'test/git/test_index.py') 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) -- cgit v1.2.1 From 6662422ba52753f8b10bc053aba82bac3f2e1b9c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 21:25:52 +0200 Subject: index.iter_blobs method added including tests ( which have been improved generally for more coverage ) --- test/git/test_index.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index d256e7c0..524f0778 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -8,6 +8,7 @@ from test.testlib import * from git import * import inspect import os +import tempfile class TestTree(TestCase): @@ -17,7 +18,7 @@ class TestTree(TestCase): def test_base(self): # read from file - index = Index.from_file(fixture_path("index")) + index = Index.from_file(self.repo, fixture_path("index")) assert index.entries assert index.version > 0 @@ -30,7 +31,7 @@ class TestTree(TestCase): # END for each method # test stage - index_merge = Index.from_file(fixture_path("index_merge")) + index_merge = Index.from_file(self.repo, fixture_path("index_merge")) assert len(index_merge.entries) == 106 assert len(list(e for e in index_merge.entries.itervalues() if e.stage != 0 )) @@ -40,6 +41,11 @@ class TestTree(TestCase): index_output.seek(0) assert index_output.read() == fixture("index_merge") + + tmpfile = tempfile.mktemp() + Index.to_file(index_merge, tmpfile) + assert os.path.isfile(tmpfile) + os.remove(tmpfile) def _cmp_tree_index(self, tree, index): # fail unless both objects contain the same paths and blobs @@ -53,7 +59,7 @@ class TestTree(TestCase): # END for each blob in tree assert num_blobs == len(index.entries) - def test_merge(self): + def test_from_tree(self): common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541" cur_sha = "4b43ca7ff72d5f535134241e7c797ddc9c7a3573" other_sha = "39f85c4358b7346fee22169da9cad93901ea9eb9" @@ -70,7 +76,16 @@ class TestTree(TestCase): # merge three trees - here we have a merge conflict tree_way_index = Index.from_tree(self.repo, common_ancestor_sha, cur_sha, other_sha) - assert len(list(e for e in tree_way_index.entries.values() if e.stage != 0)) + assert len(list(e for e in tree_way_index.entries.values() if e.stage != 0)) + + + # ITERATE BLOBS + merge_required = lambda t: t[0] != 0 + merge_blobs = list(tree_way_index.iter_blobs(merge_required)) + assert merge_blobs + assert merge_blobs[0][0] in (1,2,3) + assert isinstance(merge_blobs[0][1], Blob) + def test_custom_commit(self): self.fail("Custom commit:write tree, make commit with custom parents") -- cgit v1.2.1 From 7b50af0a20bcc7280940ce07593007d17c5acabd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 21 Oct 2009 23:11:40 +0200 Subject: index: Added write_tree method including test --- test/git/test_index.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 524f0778..a4e01054 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -87,5 +87,12 @@ class TestTree(TestCase): assert isinstance(merge_blobs[0][1], Blob) + # writing a tree should fail with an unmerged index + self.failUnlessRaises(GitCommandError, tree_way_index.write_tree) + + # removed unmerged entries + self.fail("remove unmerged") + + def test_custom_commit(self): self.fail("Custom commit:write tree, make commit with custom parents") -- cgit v1.2.1 From aa921fee6014ef43bb2740240e9663e614e25662 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 00:32:16 +0200 Subject: Implemented merge/resolve handling , but realized that index writing is not yet working properly as it is sha1 checked as well. This explains what my 20 byte 'extension_data' actually is ;) --- test/git/test_index.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index a4e01054..6208a1d9 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -75,23 +75,28 @@ class TestTree(TestCase): 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) - assert len(list(e for e in tree_way_index.entries.values() if e.stage != 0)) + three_way_index = Index.from_tree(self.repo, common_ancestor_sha, cur_sha, other_sha) + assert len(list(e for e in three_way_index.entries.values() if e.stage != 0)) # ITERATE BLOBS merge_required = lambda t: t[0] != 0 - merge_blobs = list(tree_way_index.iter_blobs(merge_required)) + merge_blobs = list(three_way_index.iter_blobs(merge_required)) assert merge_blobs assert merge_blobs[0][0] in (1,2,3) assert isinstance(merge_blobs[0][1], Blob) # writing a tree should fail with an unmerged index - self.failUnlessRaises(GitCommandError, tree_way_index.write_tree) + self.failUnlessRaises(GitCommandError, three_way_index.write_tree) # removed unmerged entries - self.fail("remove unmerged") + unmerged_blob_map = three_way_index.unmerged_blobs() + assert unmerged_blob_map + + # pick the first blob at the first stage we find and use it as resolved version + three_way_index.resolve_blobs( l[0][1] for l in unmerged_blob_map.itervalues() ) + three_way_index.write_tree() def test_custom_commit(self): -- cgit v1.2.1 From 30d822a468dc909aac5c83d078a59bfc85fc27aa Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 10:15:47 +0200 Subject: index writing now creates a sha on the content making it possible to write valid indices after manually removing or altering entriesgst --- test/git/test_index.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index 6208a1d9..c8f6f4e3 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -96,7 +96,14 @@ class TestTree(TestCase): # pick the first blob at the first stage we find and use it as resolved version three_way_index.resolve_blobs( l[0][1] for l in unmerged_blob_map.itervalues() ) - three_way_index.write_tree() + tree = three_way_index.write_tree() + assert isinstance(tree, Tree) + num_blobs = 0 + for blob in tree.traverse(predicate=lambda item: item.type == "blob"): + assert (blob.path,0) in three_way_index.entries + num_blobs += 1 + # END for each blob + assert num_blobs == len(three_way_index.entries) def test_custom_commit(self): -- cgit v1.2.1 From 1f2b19de3301e76ab3a6187a49c9c93ff78bafbd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 13:40:56 +0200 Subject: Removed index test marker for custom commits as this boils down to a good way to add files to the index/remove them and make commits which are possibly customized with custom parents --- test/git/test_index.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/git/test_index.py') diff --git a/test/git/test_index.py b/test/git/test_index.py index c8f6f4e3..4c17f5e5 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -104,7 +104,5 @@ class TestTree(TestCase): num_blobs += 1 # END for each blob assert num_blobs == len(three_way_index.entries) - - - def test_custom_commit(self): - self.fail("Custom commit:write tree, make commit with custom parents") + + -- cgit v1.2.1