Pārlūkot izejas kodu

Followup fix for #608; also handle Repo.get_refs.

Jelmer Vernooij 7 gadi atpakaļ
vecāks
revīzija
7c75ebd0d0
2 mainītis faili ar 6 papildinājumiem un 3 dzēšanām
  1. 2 3
      dulwich/refs.py
  2. 4 0
      dulwich/tests/test_refs.py

+ 2 - 3
dulwich/refs.py

@@ -475,6 +475,8 @@ class DiskRefsContainer(RefsContainer):
 
     def __init__(self, path, worktree_path=None, logger=None):
         super(DiskRefsContainer, self).__init__(logger=logger)
+        if getattr(path, 'encode', None) is not None:
+            path = path.encode(sys.getfilesystemencoding())
         self.path = path
         self.worktree_path = worktree_path or path
         self._packed_refs = None
@@ -525,9 +527,6 @@ class DiskRefsContainer(RefsContainer):
         """Return the disk path of a ref.
 
         """
-        if (getattr(self.path, "encode", None) and
-                getattr(name, "decode", None)):
-            name = name.decode(sys.getfilesystemencoding())
         if os.path.sep != "/":
             name = name.replace("/", os.path.sep)
         # TODO: as the 'HEAD' reference is working tree specific, it

+ 4 - 0
dulwich/tests/test_refs.py

@@ -502,6 +502,10 @@ class DiskRefsContainerTests(RefsContainerTests, TestCase):
         self.assertEqual({r[len(b'refs/'):] for r in expected_refs
                           if r.startswith(b'refs/')},
                          set(self._repo.refs.subkeys(b'refs/')))
+        expected_refs.remove(b'refs/heads/loop')
+        expected_refs.add(b'HEAD')
+        self.assertEqual(expected_refs,
+                         set(self._repo.get_refs().keys()))
 
 
 _TEST_REFS_SERIALIZED = (