Browse Source

client: fix send_pack when there is nothing to send

Includes a functional test that failed prior to this fix.

Change-Id: I7d95cff21c56a198a836479d8e88a3589e0f196c
Augie Fackler 15 years ago
parent
commit
1e1b0eb334
2 changed files with 12 additions and 4 deletions
  1. 1 1
      dulwich/client.py
  2. 11 3
      dulwich/tests/compat/test_client.py

+ 1 - 1
dulwich/client.py

@@ -122,7 +122,7 @@ class GitClient(object):
                       "%s %s %s\0%s" % (old_sha1, new_sha1, refname,
                                         ' '.join(self._send_capabilities)))
                     sent_capabilities = True
-            if not new_sha1 in (have, ZERO_SHA):
+            if new_sha1 not in have and new_sha1 != ZERO_SHA:
                 want.append(new_sha1)
         self.proto.write_pkt_line(None)
         if not want:

+ 11 - 3
dulwich/tests/compat/test_client.py

@@ -80,7 +80,7 @@ class DulwichClientTest(CompatTestCase):
         dest = repo.Repo(os.path.join(self.gitroot, 'dest'))
         self.assertReposEqual(src, dest)
 
-    def test_send_pack(self):
+    def _do_send_pack(self):
         c = client.TCPGitClient('localhost')
         srcpath = os.path.join(self.gitroot, 'server_new.export')
         src = repo.Repo(srcpath)
@@ -88,8 +88,16 @@ class DulwichClientTest(CompatTestCase):
         del sendrefs['HEAD']
         c.send_pack('/dest', lambda _: sendrefs,
                     src.object_store.generate_pack_contents)
-        dest = repo.Repo(os.path.join(self.gitroot, 'dest'))
-        self.assertReposEqual(src, dest)
+
+    def test_send_pack(self):
+        self._do_send_pack()
+        self.assertDestEqualsSrc()
+
+    def test_send_pack_nothing_to_send(self):
+        self._do_send_pack()
+        self.assertDestEqualsSrc()
+        # nothing to send, but shouldn't raise either.
+        self._do_send_pack()
 
     def test_send_without_report_status(self):
         c = client.TCPGitClient('localhost')