浏览代码

Allow overriding paths to executables in GitSSHClient.

Jelmer Vernooij 14 年之前
父节点
当前提交
121f9e8e85
共有 3 个文件被更改,包括 24 次插入1 次删除
  1. 3 0
      NEWS
  2. 5 1
      dulwich/client.py
  3. 16 0
      dulwich/tests/test_client.py

+ 3 - 0
NEWS

@@ -18,6 +18,9 @@
   * The GitClient interface has been cleaned up and instances are now reusable.
     (Augie Fackler)
 
+  * Allow overriding paths to executables in GitSSHClient. 
+    (Ross Light, Jelmer Vernooij, #585204)
+
  TESTS
 
   * Add tests for sorted_tree_items and C implementation. (Dave Borowitz)

+ 5 - 1
dulwich/client.py

@@ -349,10 +349,14 @@ class SSHGitClient(GitClient):
         self.port = port
         self.username = username
         GitClient.__init__(self, *args, **kwargs)
+        self.alternative_paths = {}
+
+    def _get_cmd_path(self, cmd):
+        return self.alternative_paths.get(cmd, 'git-%s' % cmd)
 
     def _connect(self, cmd, path):
         con = get_ssh_vendor().connect_ssh(
-            self.host, ["%s '%s'" % ('git-' + cmd, path)],
+            self.host, ["%s '%s'" % (self._get_cmd_path(cmd), path)],
             port=self.port, username=self.username)
         return Protocol(con.read, con.write), con.can_read
 

+ 16 - 0
dulwich/tests/test_client.py

@@ -20,6 +20,7 @@ from cStringIO import StringIO
 
 from dulwich.client import (
     GitClient,
+    SSHGitClient,
     )
 from dulwich.tests import (
     TestCase,
@@ -64,3 +65,18 @@ class GitClientTests(TestCase):
         self.rin.seek(0)
         self.client.fetch_pack("bla", lambda heads: [], None, None, None)
         self.assertEquals(self.rout.getvalue(), "0000")
+
+
+class SSHGitClientTests(TestCase):
+
+    def setUp(self):
+        super(SSHGitClientTests, self).setUp()
+        self.client = SSHGitClient("git.samba.org")
+
+    def test_default_command(self):
+        self.assertEquals("git-upload-pack", self.client._get_cmd_path("upload-pack"))
+
+    def test_alternative_command_path(self):
+        self.client.alternative_paths["upload-pack"] = "/usr/lib/git/git-upload-pack"
+        self.assertEquals("/usr/lib/git/git-upload-pack", self.client._get_cmd_path("upload-pack"))
+