Allow overriding paths to executables in GitSSHClient.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 28 Jun 2010 19:40:01 +0000 (21:40 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 28 Jun 2010 19:40:01 +0000 (21:40 +0200)
1  2 
NEWS
dulwich/client.py
dulwich/tests/test_client.py

diff --cc NEWS
index 0ebb2d734b73c0f89c0328eeede2995766953c30,716af74e5e45b1505be511a0bd4a0ad34f454c45..5f62331adb30c22d7d13c9baf8a779d0dfdd57b7
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
  
    * Move named file initilization to BaseRepo. (Dave Borowitz)
  
 +  * Add logging utilities and git/HTTP server logging. (Dave Borowitz)
 +
 +  * 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)
index 2b69852f023ca3f8322c2f1c4db3940912ce7b04,de79c9b897fe450cce630030aaa2049c2fc3536c..3fe75374a9be7a673ed3c1b4966e19c9f9587c76
@@@ -348,13 -371,26 +348,17 @@@ class SSHGitClient(GitClient)
          self.host = host
          self.port = port
          self.username = username
 -        self.receive_pack_path = "git-receive-pack"
 -        self.upload_pack_path = "git-upload-pack"
 -        self._args = args
 -        self._kwargs = kwargs
 +        GitClient.__init__(self, *args, **kwargs)
++        self.alternative_paths = {}
 -    def send_pack(self, path, determine_wants, generate_pack_contents):
 -        remote = get_ssh_vendor().connect_ssh(
 -            self.host, ["'%s' '%s'" % (self.receive_pack_path, path)],
 -            port=self.port, username=self.username)
 -        client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs)
 -        return client.send_pack(path, determine_wants, generate_pack_contents)
++    def _get_cmd_path(self, cmd):
++        return self.alternative_paths.get(cmd, 'git-%s' % cmd)
  
 -    def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
 -        progress):
 -        remote = get_ssh_vendor().connect_ssh(
 -            self.host, ["'%s' '%s'" % (self.upload_pack_path, path)],
 +    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)
 -        client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs)
 -        return client.fetch_pack(path, determine_wants, graph_walker, pack_data,
 -                                 progress)
 +        return Protocol(con.read, con.write), con.can_read
  
  
  def get_transport_and_path(uri):
index 117745aa76f957c4cb2e393a6ac79773678803c2,cf0f41f0bc7a5f0b251c6b31c483d6d441d82241..976b9df99a12d771a207aa8c5142f62f0b9f7ad5
@@@ -20,24 -20,8 +20,25 @@@ from cStringIO import StringI
  
  from dulwich.client import (
      GitClient,
++    SSHGitClient,
      )
 +from dulwich.tests import (
 +    TestCase,
 +    )
 +from dulwich.protocol import (
 +    Protocol,
 +    )
 +
 +
 +class DummyClient(GitClient):
 +    def __init__(self, can_read, read, write):
 +        self.can_read = can_read
 +        self.read = read
 +        self.write = write
 +        GitClient.__init__(self)
 +
 +    def _connect(self, service, path):
 +        return Protocol(self.read, self.write), self.can_read
  
  
  # TODO(durin42): add unit-level tests of GitClient
@@@ -64,3 -47,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"))
++