summaryrefslogtreecommitdiff
path: root/test/git/test_fun.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-23 00:28:36 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-23 00:28:36 +0200
commitc0ef65b43688b1a4615a1e7332f6215f9a8abb19 (patch)
treeb1a4c8ec385fe8a57db5b1e2f1088e1e7e700dfd /test/git/test_fun.py
parentbe97c4558992a437cde235aafc7ae2bd6df84ac8 (diff)
downloadgitpython-c0ef65b43688b1a4615a1e7332f6215f9a8abb19.tar.gz
Implemented simple tree merging and a simple test, more elaborate testing is in progress
Diffstat (limited to 'test/git/test_fun.py')
-rw-r--r--test/git/test_fun.py64
1 files changed, 57 insertions, 7 deletions
diff --git a/test/git/test_fun.py b/test/git/test_fun.py
index ccf15c77..4ddc1910 100644
--- a/test/git/test_fun.py
+++ b/test/git/test_fun.py
@@ -8,17 +8,67 @@ from git.index.fun import (
aggressive_tree_merge
)
+from git.index import IndexFile
+from stat import (
+ S_IFDIR,
+ S_IFREG,
+ S_IFLNK
+ )
+
class TestFun(TestBase):
+ def _assert_index_entries(self, entries, trees):
+ index = IndexFile.from_tree(self.rorepo, *trees)
+ assert entries
+ assert len(index.entries) == len(entries)
+ for entry in entries:
+ assert (entry.path, entry.stage) in index.entries
+ # END assert entry matches fully
+
def test_aggressive_tree_merge(self):
# head tree with additions, removals and modification compared to its predecessor
+ odb = self.rorepo.odb
HC = self.rorepo.commit("6c1faef799095f3990e9970bc2cb10aa0221cf9c")
H = HC.tree
B = HC.parents[0].tree
- # test new index from single tree
+ # entries from single tree
+ trees = [H.sha]
+ self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
+
+ # from multiple trees
+ trees = [B.sha, H.sha]
+ self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
+
+ # three way, no conflict
+ tree = self.rorepo.tree
+ B = tree("35a09c0534e89b2d43ec4101a5fb54576b577905")
+ H = tree("4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4")
+ M = tree("1f2b19de3301e76ab3a6187a49c9c93ff78bafbd")
+ trees = [B.sha, H.sha, M.sha]
+ self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
+
+ # three-way, conflict in at least one file, both modified
+ B = tree("a7a4388eeaa4b6b94192dce67257a34c4a6cbd26")
+ H = tree("f9cec00938d9059882bb8eabdaf2f775943e00e5")
+ M = tree("44a601a068f4f543f73fd9c49e264c931b1e1652")
+ trees = [B.sha, H.sha, M.sha]
+ self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
+
+ def make_tree(odb, entries):
+ """create a tree from the given tree entries and safe it to the database"""
+
+
+ @with_rw_repo('0.1.6')
+ def test_three_way_merge(self, rwrepo):
+ def mkfile(name, sha, executable=0):
+ return (sha, S_IFREG | 644 | executable*0111, name)
+ def mkcommit(name, sha):
+ return (sha, S_IFDIR | S_IFLNK, name)
+ odb = rwrepo.odb
+
- def _assert_entries(self, entries, num_trees):
+ def _assert_tree_entries(self, entries, num_trees):
assert len(entries[0]) == num_trees
for entry in entries:
paths = set(e[2] for e in entry if e)
@@ -37,25 +87,25 @@ class TestFun(TestBase):
# two very different trees
entries = traverse_trees_recursive(odb, [B_old.sha, H.sha], '')
- self._assert_entries(entries, 2)
+ self._assert_tree_entries(entries, 2)
oentries = traverse_trees_recursive(odb, [H.sha, B_old.sha], '')
assert len(oentries) == len(entries)
- self._assert_entries(oentries, 2)
+ self._assert_tree_entries(oentries, 2)
# single tree
is_no_tree = lambda i, d: i.type != 'tree'
entries = traverse_trees_recursive(odb, [B.sha], '')
assert len(entries) == len(list(B.traverse(predicate=is_no_tree)))
- self._assert_entries(entries, 1)
+ self._assert_tree_entries(entries, 1)
# two trees
entries = traverse_trees_recursive(odb, [B.sha, H.sha], '')
- self._assert_entries(entries, 2)
+ self._assert_tree_entries(entries, 2)
# tree trees
entries = traverse_trees_recursive(odb, [B.sha, H.sha, M.sha], '')
- self._assert_entries(entries, 3)
+ self._assert_tree_entries(entries, 3)
def test_tree_traversal_single(self):
max_count = 50