Răsfoiți Sursa

add tests to demonstrate date ordering issue with topo sort

When the timestamp for a commit on a branch is older than the point at
which it is being merged back into master, the topo sort does not
produce the values in the same order as the git command line tool. So
although the results are technically sorted in a correct topologicial
form, they produce incorrect information when checking for the most
recent tag or other information when traversing the results.

This patch adds 2 tests to demonstrate the problem.

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 8 ani în urmă
părinte
comite
386fbd5ab5
1 a modificat fișierele cu 27 adăugiri și 0 ștergeri
  1. 27 0
      dulwich/tests/test_walk.py

+ 27 - 0
dulwich/tests/test_walk.py

@@ -144,6 +144,33 @@ class WalkerTest(TestCase):
         self.assertWalkYields([c4, c3], [c4.id], exclude=[c2.id])
         self.assertWalkYields([c4, c2], [c4.id], exclude=[c3.id])
 
+    def test_merge_of_new_branch_from_old_base(self):
+        # The commit on the branch was made at a time after any of the
+        # commits on master, but the branch was from an older commit.
+        # See also test_merge_of_old_branch
+        self.maxDiff = None
+        c1, c2, c3, c4, c5 = self.make_commits(
+            [[1], [2, 1], [3, 2], [4, 1], [5, 3, 4]],
+            times=[1, 2, 3, 4, 5],
+        )
+        self.assertWalkYields([c5, c4, c3, c2, c1], [c5.id])
+        self.assertWalkYields([c3, c2, c1], [c3.id])
+        self.assertWalkYields([c2, c1], [c2.id])
+
+    def test_merge_of_old_branch(self):
+        # The commit on the branch was made at a time before any of
+        # the commits on master, but it was merged into master after
+        # those commits.
+        # See also test_merge_of_new_branch_from_old_base
+        self.maxDiff = None
+        c1, c2, c3, c4, c5 = self.make_commits(
+            [[1], [2, 1], [3, 2], [4, 1], [5, 3, 4]],
+            times=[1, 3, 4, 2, 5],
+        )
+        self.assertWalkYields([c5, c4, c3, c2, c1], [c5.id])
+        self.assertWalkYields([c3, c2, c1], [c3.id])
+        self.assertWalkYields([c2, c1], [c2.id])
+
     def test_reverse(self):
         c1, c2, c3 = self.make_linear_commits(3)
         self.assertWalkYields([c1, c2, c3], [c3.id], reverse=True)