Forráskód Böngészése

Add some documentation.

Jelmer Vernooij 8 éve
szülő
commit
2f96306888
3 módosított fájl, 16 hozzáadás és 5 törlés
  1. 9 0
      dulwich/client.py
  2. 5 2
      dulwich/porcelain.py
  3. 2 3
      dulwich/tests/test_client.py

+ 9 - 0
dulwich/client.py

@@ -218,6 +218,8 @@ class GitClient(object):
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
                                  and rejects ref updates
+        :return: new_refs dictionary containing the changes that were made
+            {refname: new_ref}, including deleted refs.
         """
         raise NotImplementedError(self.send_pack)
 
@@ -497,6 +499,8 @@ class TraditionalGitClient(GitClient):
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
                                  and rejects ref updates
+        :return: new_refs dictionary containing the changes that were made
+            {refname: new_ref}, including deleted refs.
         """
         proto, unused_can_read = self._connect(b'receive-pack', path)
         with proto:
@@ -769,6 +773,8 @@ class LocalGitClient(GitClient):
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
                                  and rejects ref updates
+        :return: new_refs dictionary containing the changes that were made
+            {refname: new_ref}, including deleted refs.
         """
         from dulwich.repo import Repo
 
@@ -1042,6 +1048,8 @@ class HttpGitClient(GitClient):
         :raises SendPackError: if server rejects the pack data
         :raises UpdateRefsError: if the server supports report-status
                                  and rejects ref updates
+        :return: new_refs dictionary containing the changes that were made
+            {refname: new_ref}, including deleted refs.
         """
         url = self._get_url(path)
         old_refs, server_capabilities = self._discover_references(
@@ -1053,6 +1061,7 @@ class HttpGitClient(GitClient):
 
         new_refs = determine_wants(dict(old_refs))
         if new_refs is None:
+            # Determine wants function is aborting the push.
             return old_refs
         if self.dumb:
             raise NotImplementedError(self.fetch_pack)

+ 5 - 2
dulwich/porcelain.py

@@ -82,7 +82,10 @@ from dulwich.pack import (
     write_pack_objects,
     )
 from dulwich.patch import write_tree_diff
-from dulwich.protocol import Protocol
+from dulwich.protocol import (
+    Protocol,
+    ZERO_SHA,
+    )
 from dulwich.repo import (BaseRepo, Repo)
 from dulwich.server import (
     FileSystemBackend,
@@ -580,7 +583,7 @@ def push(repo, remote_location, refspecs=None,
             # TODO: Handle selected_refs == {None: None}
             for (lh, rh, force) in selected_refs:
                 if lh is None:
-                    del refs[rh]
+                    refs[rh] = ZERO_SHA
                 else:
                     refs[rh] = r.refs[lh]
             return refs

+ 2 - 3
dulwich/tests/test_client.py

@@ -45,6 +45,7 @@ from dulwich.tests import (
 from dulwich.protocol import (
     TCP_GIT_PORT,
     Protocol,
+    ZERO_SHA,
     )
 from dulwich.pack import (
     write_pack_objects,
@@ -656,6 +657,7 @@ class LocalGitClientTests(TestCase):
         self.assertDictEqual(local.refs.as_dict(), refs)
 
     def send_and_verify(self, branch, local, target):
+        """Send a branch from local to remote repository and verify it worked."""
         client = LocalGitClient()
         ref_name = b"refs/heads/" + branch
         new_refs = client.send_pack(target.path,
@@ -664,9 +666,6 @@ class LocalGitClientTests(TestCase):
 
         self.assertEqual(local.refs[ref_name], new_refs[ref_name])
 
-        for name, sha in new_refs.items():
-            self.assertEqual(new_refs[name], target.refs[name])
-
         obj_local = local.get_object(new_refs[ref_name])
         obj_target = target.get_object(new_refs[ref_name])
         self.assertEqual(obj_local, obj_target)