|
@@ -25,9 +25,9 @@ import os
|
|
|
import shutil
|
|
import shutil
|
|
|
import tempfile
|
|
import tempfile
|
|
|
|
|
|
|
|
-from dulwich import porcelain
|
|
|
|
|
from dulwich.bisect import BisectState
|
|
from dulwich.bisect import BisectState
|
|
|
from dulwich.objects import Tree
|
|
from dulwich.objects import Tree
|
|
|
|
|
+from dulwich.repo import Repo
|
|
|
from dulwich.tests.utils import make_commit
|
|
from dulwich.tests.utils import make_commit
|
|
|
|
|
|
|
|
from . import TestCase
|
|
from . import TestCase
|
|
@@ -38,7 +38,7 @@ class BisectStateTests(TestCase):
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
def setUp(self) -> None:
|
|
|
self.test_dir = tempfile.mkdtemp()
|
|
self.test_dir = tempfile.mkdtemp()
|
|
|
- self.repo = porcelain.init(self.test_dir)
|
|
|
|
|
|
|
+ self.repo = Repo.init(self.test_dir)
|
|
|
|
|
|
|
|
def tearDown(self) -> None:
|
|
def tearDown(self) -> None:
|
|
|
shutil.rmtree(self.test_dir)
|
|
shutil.rmtree(self.test_dir)
|
|
@@ -158,98 +158,3 @@ class BisectStateTests(TestCase):
|
|
|
# Reset
|
|
# Reset
|
|
|
state.reset()
|
|
state.reset()
|
|
|
self.assertFalse(state.is_active)
|
|
self.assertFalse(state.is_active)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class BisectPorcelainTests(TestCase):
|
|
|
|
|
- """Tests for porcelain bisect functions."""
|
|
|
|
|
-
|
|
|
|
|
- def setUp(self) -> None:
|
|
|
|
|
- self.test_dir = tempfile.mkdtemp()
|
|
|
|
|
- self.repo = porcelain.init(self.test_dir)
|
|
|
|
|
-
|
|
|
|
|
- # Create tree objects
|
|
|
|
|
- tree = Tree()
|
|
|
|
|
- self.repo.object_store.add_object(tree)
|
|
|
|
|
-
|
|
|
|
|
- # Create some commits with proper trees
|
|
|
|
|
- self.c1 = make_commit(id=b"1" * 40, message=b"initial commit", tree=tree.id)
|
|
|
|
|
- self.c2 = make_commit(
|
|
|
|
|
- id=b"2" * 40, message=b"second commit", parents=[b"1" * 40], tree=tree.id
|
|
|
|
|
- )
|
|
|
|
|
- self.c3 = make_commit(
|
|
|
|
|
- id=b"3" * 40, message=b"third commit", parents=[b"2" * 40], tree=tree.id
|
|
|
|
|
- )
|
|
|
|
|
- self.c4 = make_commit(
|
|
|
|
|
- id=b"4" * 40, message=b"fourth commit", parents=[b"3" * 40], tree=tree.id
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- # Add commits to object store
|
|
|
|
|
- for commit in [self.c1, self.c2, self.c3, self.c4]:
|
|
|
|
|
- self.repo.object_store.add_object(commit)
|
|
|
|
|
-
|
|
|
|
|
- # Set HEAD to latest commit
|
|
|
|
|
- self.repo.refs[b"HEAD"] = self.c4.id
|
|
|
|
|
- self.repo.refs[b"refs/heads/master"] = self.c4.id
|
|
|
|
|
-
|
|
|
|
|
- def tearDown(self) -> None:
|
|
|
|
|
- shutil.rmtree(self.test_dir)
|
|
|
|
|
-
|
|
|
|
|
- def test_bisect_start(self) -> None:
|
|
|
|
|
- """Test bisect_start porcelain function."""
|
|
|
|
|
- porcelain.bisect_start(self.test_dir)
|
|
|
|
|
-
|
|
|
|
|
- # Check that bisect state files exist
|
|
|
|
|
- self.assertTrue(
|
|
|
|
|
- os.path.exists(os.path.join(self.repo.controldir(), "BISECT_START"))
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- def test_bisect_bad_good(self) -> None:
|
|
|
|
|
- """Test marking commits as bad and good."""
|
|
|
|
|
- porcelain.bisect_start(self.test_dir)
|
|
|
|
|
- porcelain.bisect_bad(self.test_dir, self.c4.id.decode("ascii"))
|
|
|
|
|
- porcelain.bisect_good(self.test_dir, self.c1.id.decode("ascii"))
|
|
|
|
|
-
|
|
|
|
|
- # Check that refs were created
|
|
|
|
|
- self.assertTrue(
|
|
|
|
|
- os.path.exists(
|
|
|
|
|
- os.path.join(self.repo.controldir(), "refs", "bisect", "bad")
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- self.assertTrue(
|
|
|
|
|
- os.path.exists(
|
|
|
|
|
- os.path.join(
|
|
|
|
|
- self.repo.controldir(),
|
|
|
|
|
- "refs",
|
|
|
|
|
- "bisect",
|
|
|
|
|
- f"good-{self.c1.id.decode('ascii')}",
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- def test_bisect_log(self) -> None:
|
|
|
|
|
- """Test getting bisect log."""
|
|
|
|
|
- porcelain.bisect_start(self.test_dir)
|
|
|
|
|
- porcelain.bisect_bad(self.test_dir, self.c4.id.decode("ascii"))
|
|
|
|
|
- porcelain.bisect_good(self.test_dir, self.c1.id.decode("ascii"))
|
|
|
|
|
-
|
|
|
|
|
- log = porcelain.bisect_log(self.test_dir)
|
|
|
|
|
-
|
|
|
|
|
- self.assertIn("git bisect start", log)
|
|
|
|
|
- self.assertIn("git bisect bad", log)
|
|
|
|
|
- self.assertIn("git bisect good", log)
|
|
|
|
|
-
|
|
|
|
|
- def test_bisect_reset(self) -> None:
|
|
|
|
|
- """Test resetting bisect state."""
|
|
|
|
|
- porcelain.bisect_start(self.test_dir)
|
|
|
|
|
- porcelain.bisect_bad(self.test_dir)
|
|
|
|
|
- porcelain.bisect_good(self.test_dir, self.c1.id.decode("ascii"))
|
|
|
|
|
-
|
|
|
|
|
- porcelain.bisect_reset(self.test_dir)
|
|
|
|
|
-
|
|
|
|
|
- # Check that bisect state files are removed
|
|
|
|
|
- self.assertFalse(
|
|
|
|
|
- os.path.exists(os.path.join(self.repo.controldir(), "BISECT_START"))
|
|
|
|
|
- )
|
|
|
|
|
- self.assertFalse(
|
|
|
|
|
- os.path.exists(os.path.join(self.repo.controldir(), "refs", "bisect"))
|
|
|
|
|
- )
|
|
|