Browse Source

Allow unicode or bytestring host paths in GitClient.

Jelmer Vernooij 8 years ago
parent
commit
6676b7f6c6
2 changed files with 15 additions and 6 deletions
  1. 3 0
      NEWS
  2. 12 6
      dulwich/client.py

+ 3 - 0
NEWS

@@ -10,6 +10,9 @@
   * Fix dulwich.porcelain.ls_remote() on Python 3.
     (#471, Jelmer Vernooij)
 
+  * Allow both unicode and byte strings for host paths
+    in dulwich.client. (#435, Jelmer Vernooij)
+
 0.16.1	2016-12-25
 
  BUG FIXES

+ 12 - 6
dulwich/client.py

@@ -497,6 +497,12 @@ class GitClient(object):
 class TraditionalGitClient(GitClient):
     """Traditional Git client."""
 
+    DEFAULT_ENCODING = 'utf-8'
+
+    def __init__(self, path_encoding=DEFAULT_ENCODING, **kwargs):
+        self._remote_path_encoding = path_encoding
+        super(TraditionalGitClient, self).__init__(**kwargs)
+
     def _connect(self, cmd, path):
         """Create a connection to the server.
 
@@ -672,9 +678,9 @@ class TCPGitClient(TraditionalGitClient):
 
     def _connect(self, cmd, path):
         if type(cmd) is not bytes:
-            raise TypeError(path)
+            raise TypeError(cmd)
         if type(path) is not bytes:
-            raise TypeError(path)
+            path = path.encode(self._remote_path_encoding)
         sockaddrs = socket.getaddrinfo(
             self._host, self._port, socket.AF_UNSPEC, socket.SOCK_STREAM)
         s = None
@@ -772,9 +778,9 @@ class SubprocessGitClient(TraditionalGitClient):
 
     def _connect(self, service, path):
         if type(service) is not bytes:
-            raise TypeError(path)
+            raise TypeError(service)
         if type(path) is not bytes:
-            raise TypeError(path)
+            path = path.encode(self._remote_path_encoding)
         if self.git_command is None:
             git_command = find_git_command()
         argv = git_command + [service.decode('ascii'), path]
@@ -997,9 +1003,9 @@ class SSHGitClient(TraditionalGitClient):
 
     def _connect(self, cmd, path):
         if type(cmd) is not bytes:
-            raise TypeError(path)
+            raise TypeError(cmd)
         if type(path) is not bytes:
-            raise TypeError(path)
+            path = path.encode(self._remote_path_encoding)
         if path.startswith(b"/~"):
             path = path[1:]
         argv = self._get_cmd_path(cmd) + b" '" + path + b"'"