Browse Source

Fix dulwich.porcelain.ls_remote.

Jelmer Vernooij 8 years ago
parent
commit
df5daae28b
4 changed files with 28 additions and 8 deletions
  1. 5 0
      NEWS
  2. 2 0
      dulwich/client.py
  3. 6 8
      dulwich/porcelain.py
  4. 15 0
      dulwich/tests/test_porcelain.py

+ 5 - 0
NEWS

@@ -5,6 +5,11 @@
   * Only run worktree list compat tests against git 2.7.0,
     when 'git worktree list' was introduced. (Jelmer Vernooij)
 
+ BUG FIXES
+
+  * Fix dulwich.porcelain.ls_remote() on Python 3.
+    (#471, Jelmer Vernooij)
+
 0.16.1	2016-12-25
 
  BUG FIXES

+ 2 - 0
dulwich/client.py

@@ -809,6 +809,8 @@ class LocalGitClient(GitClient):
     @classmethod
     def _open_repo(cls, path):
         from dulwich.repo import Repo
+        if not isinstance(path, str):
+            path = path.decode(sys.getfilesystemencoding())
         return closing(Repo(path))
 
     def send_pack(self, path, determine_wants, generate_pack_contents,

+ 6 - 8
dulwich/porcelain.py

@@ -122,13 +122,6 @@ default_bytes_err_stream = getattr(sys.stderr, 'buffer', sys.stderr)
 DEFAULT_ENCODING = 'utf-8'
 
 
-def encode_path(path, default_encoding=DEFAULT_ENCODING):
-    """Encode a path as bytestring."""
-    if not isinstance(path, bytes):
-        path = path.encode(default_encoding)
-    return path
-
-
 def open_repo(path_or_repo):
     """Open an argument that can be a repository or a path for a repository."""
     if isinstance(path_or_repo, BaseRepo):
@@ -903,8 +896,13 @@ def fetch(repo, remote_location, outstream=sys.stdout,
 
 
 def ls_remote(remote):
+    """List the refs in a remote.
+
+    :param remote: Remote repository location
+    :return: Dictionary with remote refs
+    """
     client, host_path = get_transport_and_path(remote)
-    return client.get_refs(encode_path(host_path))
+    return client.get_refs(host_path)
 
 
 def repack(repo):

+ 15 - 0
dulwich/tests/test_porcelain.py

@@ -872,3 +872,18 @@ class LsTreeTests(PorcelainTestCase):
         self.assertEqual(
                 f.getvalue(),
                 '100644 blob 8b82634d7eae019850bb883f06abf428c58bc9aa\tfoo\n')
+
+
+class LsRemoteTests(PorcelainTestCase):
+
+    def test_empty(self):
+        self.assertEqual({}, porcelain.ls_remote(self.repo.path))
+
+    def test_some(self):
+        cid = porcelain.commit(repo=self.repo.path, message=b'test status',
+            author=b'', committer=b'')
+
+        self.assertEqual({
+            b'refs/heads/master': cid,
+            b'HEAD': cid},
+            porcelain.ls_remote(self.repo.path))