Browse Source

Fix shlex, now on python2.

Jelmer Vernooij 9 years ago
parent
commit
4302d2cf55
2 changed files with 8 additions and 7 deletions
  1. 4 3
      dulwich/client.py
  2. 4 4
      dulwich/tests/test_client.py

+ 4 - 3
dulwich/client.py

@@ -977,9 +977,10 @@ class SSHGitClient(TraditionalGitClient):
 
     def _get_cmd_path(self, cmd):
         cmd = self.alternative_paths.get(cmd, b'git-' + cmd)
-        cmd = shlex.split(cmd)
-        cmd = [x.decode('ascii') for x in cmd]
-        return cmd
+        if sys.version == 2:
+            return [x.decode('ascii') for x in shlex.split(cmd)]
+        else:
+            return shlex.split(cmd.decode('ascii'))
 
     def _connect(self, cmd, path):
         if path.startswith("/~"):

+ 4 - 4
dulwich/tests/test_client.py

@@ -531,14 +531,14 @@ class SSHGitClientTests(TestCase):
                 self.client._get_cmd_path(b'upload-pack'))
 
     def test_alternative_command_path(self):
-        self.client.alternative_paths['upload-pack'] = (
-            '/usr/lib/git/git-upload-pack')
+        self.client.alternative_paths[b'upload-pack'] = (
+            b'/usr/lib/git/git-upload-pack')
         self.assertEqual(['/usr/lib/git/git-upload-pack'],
             self.client._get_cmd_path(b'upload-pack'))
 
     def test_alternative_command_path_spaces(self):
-        self.client.alternative_paths['upload-pack'] = (
-            '/usr/lib/git/git-upload-pack -ibla')
+        self.client.alternative_paths[b'upload-pack'] = (
+            b'/usr/lib/git/git-upload-pack -ibla')
         self.assertEqual(['/usr/lib/git/git-upload-pack', '-ibla'],
             self.client._get_cmd_path(b'upload-pack'))