Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _iter_packed_refs(cls, repo: "Repo") -> Iterator[Tuple[str, str]]:
The packed refs file will be kept open as long as we iterate.
"""
try:
with open(cls._get_packed_refs_path(repo), "rt", encoding="UTF-8") as fp:
with open(cls._get_packed_refs_path(repo), "rt", encoding="UTF-8", errors="surrogateescape") as fp:
for line in fp:
line = line.strip()
if not line:
Expand Down
13 changes: 13 additions & 0 deletions test/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def test_from_pathlike(self):
# Check remoteness
assert Reference(self.rorepo, PathLikeMock("refs/remotes/origin")).is_remote()

def test_iter_packed_refs_with_non_utf8_name(self):
with tempfile.TemporaryDirectory() as tdir:
with self._repo_with_initial_commit(Path(tdir)) as repo:
packed_refs_path = Path(Reference._get_packed_refs_path(repo))
hexsha = repo.head.commit.hexsha
packed_refs_path.write_bytes(
b"# pack-refs with: peeled\n" + hexsha.encode("ascii") + b" refs/tags/non-utf8-\xe9\n"
)

tag_data = [(tag.commit.hexsha, tag.path) for tag in repo.tags]

self.assertEqual(tag_data, [(hexsha, "refs/tags/non-utf8-\udce9")])
Comment thread
Byron marked this conversation as resolved.

def test_tag_base(self):
tag_object_refs = []
for tag in self.rorepo.tags:
Expand Down
Loading