|
@@ -18,11 +18,17 @@
|
|
|
|
|
|
"""Tests for commit walking functionality."""
|
|
|
|
|
|
+from dulwich.diff_tree import (
|
|
|
+ CHANGE_ADD,
|
|
|
+ CHANGE_MODIFY,
|
|
|
+ TreeChange,
|
|
|
+ )
|
|
|
from dulwich.object_store import (
|
|
|
MemoryObjectStore,
|
|
|
)
|
|
|
from dulwich.objects import (
|
|
|
Commit,
|
|
|
+ Blob,
|
|
|
)
|
|
|
from dulwich.walk import (
|
|
|
WalkEntry,
|
|
@@ -30,10 +36,30 @@ from dulwich.walk import (
|
|
|
)
|
|
|
from dulwich.tests import TestCase
|
|
|
from utils import (
|
|
|
+ F,
|
|
|
+ make_object,
|
|
|
build_commit_graph,
|
|
|
)
|
|
|
|
|
|
|
|
|
+class TestWalkEntry(object):
|
|
|
+
|
|
|
+ def __init__(self, commit, changes):
|
|
|
+ self.commit = commit
|
|
|
+ self.changes = changes
|
|
|
+
|
|
|
+ def __repr__(self):
|
|
|
+ return '<TestWalkEntry commit=%s, changes=%r>' % (
|
|
|
+ self.commit.id, self.changes)
|
|
|
+
|
|
|
+ def __eq__(self, other):
|
|
|
+ if not isinstance(other, WalkEntry) or self.commit != other.commit:
|
|
|
+ return False
|
|
|
+ if self.changes is None:
|
|
|
+ return True
|
|
|
+ return self.changes == other.changes()
|
|
|
+
|
|
|
+
|
|
|
class WalkerTest(TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
@@ -55,7 +81,7 @@ class WalkerTest(TestCase):
|
|
|
walker = Walker(self.store, *args, **kwargs)
|
|
|
for i, entry in enumerate(expected):
|
|
|
if isinstance(entry, Commit):
|
|
|
- expected[i] = WalkEntry(entry)
|
|
|
+ expected[i] = TestWalkEntry(entry, None)
|
|
|
actual = list(walker)
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
@@ -95,3 +121,32 @@ class WalkerTest(TestCase):
|
|
|
reverse=True)
|
|
|
self.assertWalkYields([c2, c3], [c3.id], max_entries=2, reverse=True)
|
|
|
self.assertWalkYields([c3], [c3.id], max_entries=1, reverse=True)
|
|
|
+
|
|
|
+ def test_changes_one_parent(self):
|
|
|
+ blob_a1 = make_object(Blob, data='a1')
|
|
|
+ blob_a2 = make_object(Blob, data='a2')
|
|
|
+ blob_b2 = make_object(Blob, data='b2')
|
|
|
+ c1, c2 = self.make_linear_commits(
|
|
|
+ 2, trees={1: [('a', blob_a1)],
|
|
|
+ 2: [('a', blob_a2), ('b', blob_b2)]})
|
|
|
+ e1 = TestWalkEntry(c1, [TreeChange.add(('a', F, blob_a1.id))])
|
|
|
+ e2 = TestWalkEntry(c2, [TreeChange(CHANGE_MODIFY, ('a', F, blob_a1.id),
|
|
|
+ ('a', F, blob_a2.id)),
|
|
|
+ TreeChange.add(('b', F, blob_b2.id))])
|
|
|
+ self.assertWalkYields([e2, e1], [c2.id])
|
|
|
+
|
|
|
+ def test_changes_multiple_parents(self):
|
|
|
+ blob_a1 = make_object(Blob, data='a1')
|
|
|
+ blob_b2 = make_object(Blob, data='b2')
|
|
|
+ blob_a3 = make_object(Blob, data='a3')
|
|
|
+ c1, c2, c3 = self.make_commits(
|
|
|
+ [[1], [2], [3, 1, 2]],
|
|
|
+ trees={1: [('a', blob_a1)], 2: [('b', blob_b2)],
|
|
|
+ 3: [('a', blob_a3), ('b', blob_b2)]})
|
|
|
+ # a is a modify/add conflict and b is not conflicted.
|
|
|
+ changes = [[
|
|
|
+ TreeChange(CHANGE_MODIFY, ('a', F, blob_a1.id), ('a', F, blob_a3.id)),
|
|
|
+ TreeChange.add(('a', F, blob_a3.id)),
|
|
|
+ ]]
|
|
|
+ self.assertWalkYields([TestWalkEntry(c3, changes)], [c3.id],
|
|
|
+ exclude=[c1.id, c2.id])
|