Browse Source

Add porcelain for update_server_info.

Jelmer Vernooij 11 years ago
parent
commit
61169bd000
3 changed files with 28 additions and 5 deletions
  1. 1 3
      bin/dulwich
  2. 11 0
      dulwich/porcelain.py
  3. 16 2
      dulwich/tests/test_porcelain.py

+ 1 - 3
bin/dulwich

@@ -37,7 +37,6 @@ from dulwich.porcelain import archive
 from dulwich.pack import Pack, sha_to_hex
 from dulwich.pack import Pack, sha_to_hex
 from dulwich.patch import write_tree_diff
 from dulwich.patch import write_tree_diff
 from dulwich.repo import Repo
 from dulwich.repo import Repo
-from dulwich.server import update_server_info
 
 
 
 
 def cmd_archive(args):
 def cmd_archive(args):
@@ -205,8 +204,7 @@ def cmd_commit(args):
 
 
 
 
 def cmd_update_server_info(args):
 def cmd_update_server_info(args):
-    r = Repo(".")
-    update_server_info(r)
+    update_server_info(".")
 
 
 
 
 commands = {
 commands = {

+ 11 - 0
dulwich/porcelain.py

@@ -19,6 +19,8 @@
 import sys
 import sys
 
 
 from dulwich.client import get_transport_and_path
 from dulwich.client import get_transport_and_path
+from dulwich.repo import Repo
+from dulwich.server import update_server_info as server_update_server_info
 
 
 """Simple wrapper that provides porcelain-like functions on top of Dulwich.
 """Simple wrapper that provides porcelain-like functions on top of Dulwich.
 
 
@@ -44,3 +46,12 @@ def archive(location, committish=None, outstream=sys.stdout,
     if committish is None:
     if committish is None:
         committish = "HEAD"
         committish = "HEAD"
     client.archive(path, committish, outstream.write, errstream.write)
     client.archive(path, committish, outstream.write, errstream.write)
+
+
+def update_server_info(path="."):
+    """Update server info files for a repository.
+
+    :param path: path to the repository
+    """
+    r = Repo(path)
+    server_update_server_info(r)

+ 16 - 2
dulwich/tests/test_porcelain.py

@@ -19,12 +19,14 @@
 """Tests for dulwich.porcelain."""
 """Tests for dulwich.porcelain."""
 
 
 from cStringIO import StringIO
 from cStringIO import StringIO
+import os
 import shutil
 import shutil
 import tarfile
 import tarfile
 import tempfile
 import tempfile
 
 
 from dulwich.porcelain import (
 from dulwich.porcelain import (
     archive,
     archive,
+    update_server_info,
     )
     )
 from dulwich.repo import Repo
 from dulwich.repo import Repo
 from dulwich.tests.utils import (
 from dulwich.tests.utils import (
@@ -39,8 +41,7 @@ from dulwich.tests.utils import (
     )
     )
 
 
 
 
-class ArchiveTests(TestCase):
-    """Tests for the archive command."""
+class PorcelainTestCase(TestCase):
 
 
     def setUp(self):
     def setUp(self):
         super(TestCase, self).setUp()
         super(TestCase, self).setUp()
@@ -48,6 +49,10 @@ class ArchiveTests(TestCase):
         self.addCleanup(shutil.rmtree, repo_dir)
         self.addCleanup(shutil.rmtree, repo_dir)
         self.repo = Repo.init_bare(repo_dir)
         self.repo = Repo.init_bare(repo_dir)
 
 
+
+class ArchiveTests(PorcelainTestCase):
+    """Tests for the archive command."""
+
     def test_simple(self):
     def test_simple(self):
         c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
         c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
         self.repo.refs["refs/heads/master"] = c3.id
         self.repo.refs["refs/heads/master"] = c3.id
@@ -58,3 +63,12 @@ class ArchiveTests(TestCase):
         tf = tarfile.TarFile(fileobj=out)
         tf = tarfile.TarFile(fileobj=out)
         self.addCleanup(tf.close)
         self.addCleanup(tf.close)
         self.assertEquals([], tf.getnames())
         self.assertEquals([], tf.getnames())
+
+
+class UpdateServerInfoTests(PorcelainTestCase):
+
+    def test_simple(self):
+        c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
+        self.repo.refs["refs/heads/foo"] = c3.id
+        update_server_info(self.repo.path)
+        self.assertTrue(os.path.exists(os.path.join(self.repo.controldir(), 'info', 'refs')))