2
0
Эх сурвалжийг харах

Add test for porcelain.push return value (#1645)

Verify that porcelain.push returns SendPackResult with per-ref status
information. This functionality was already implemented but lacked test
coverage.

Fixes #780
Jelmer Vernooij 1 сар өмнө
parent
commit
add42e37db
3 өөрчлөгдсөн 61 нэмэгдсэн , 1 устгасан
  1. 5 0
      NEWS
  2. 3 1
      dulwich/porcelain.py
  3. 53 0
      tests/test_porcelain.py

+ 5 - 0
NEWS

@@ -5,6 +5,11 @@
    causing unnecessary bloat.
    (Jelmer Vernooij, #1643)
 
+ * Document that ``porcelain.push`` returns per-ref status information
+   in the ``SendPackResult`` object. Added test coverage to verify this
+   functionality works as expected.
+   (Jelmer Vernooij, #780)
+
 0.23.1	2025-06-30
 
  * Support ``untracked_files="normal"`` argument to ``porcelain.status``,

+ 3 - 1
dulwich/porcelain.py

@@ -1622,7 +1622,7 @@ def push(
     errstream=default_bytes_err_stream,
     force=False,
     **kwargs,
-) -> None:
+):
     """Remote push with dulwich via dulwich.client.
 
     Args:
@@ -1695,6 +1695,8 @@ def push(
         if remote_name is not None:
             _import_remote_refs(r.refs, remote_name, remote_changed_refs)
 
+        return result
+
     # Trigger auto GC if needed
     from .gc import maybe_auto_gc
 

+ 53 - 0
tests/test_porcelain.py

@@ -37,6 +37,7 @@ from io import BytesIO, StringIO
 from unittest import skipIf
 
 from dulwich import porcelain
+from dulwich.client import SendPackResult
 from dulwich.diff_tree import tree_changes
 from dulwich.errors import CommitError
 from dulwich.object_store import DEFAULT_TEMPFILE_GRACE_PERIOD
@@ -3764,6 +3765,58 @@ class PushTests(PorcelainTestCase):
         self.assertEqual(b"", outstream.getvalue())
         self.assertTrue(re.match(b"Push to .* successful.\n", errstream.getvalue()))
 
+    def test_push_returns_sendpackresult(self) -> None:
+        """Test that push returns a SendPackResult with per-ref information."""
+        outstream = BytesIO()
+        errstream = BytesIO()
+
+        # Create initial commit
+        porcelain.commit(
+            repo=self.repo.path,
+            message=b"init",
+            author=b"author <email>",
+            committer=b"committer <email>",
+        )
+
+        # Setup target repo cloned from temp test repo
+        clone_path = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, clone_path)
+        target_repo = porcelain.clone(
+            self.repo.path, target=clone_path, errstream=errstream
+        )
+        target_repo.close()
+
+        # Create a commit in the clone
+        handle, fullpath = tempfile.mkstemp(dir=clone_path)
+        os.close(handle)
+        porcelain.add(repo=clone_path, paths=[fullpath])
+        porcelain.commit(
+            repo=clone_path,
+            message=b"push",
+            author=b"author <email>",
+            committer=b"committer <email>",
+        )
+
+        # Push and check the return value
+        result = porcelain.push(
+            clone_path,
+            "origin",
+            b"HEAD:refs/heads/new-branch",
+            outstream=outstream,
+            errstream=errstream,
+        )
+
+        # Verify that we get a SendPackResult
+        self.assertIsInstance(result, SendPackResult)
+
+        # Verify that it contains refs
+        self.assertIsNotNone(result.refs)
+        self.assertIn(b"refs/heads/new-branch", result.refs)
+
+        # Verify ref_status - should be None for successful updates
+        if result.ref_status:
+            self.assertIsNone(result.ref_status.get(b"refs/heads/new-branch"))
+
 
 class PullTests(PorcelainTestCase):
     def setUp(self) -> None: