@@ -632,39 +632,40 @@ def test_tag_message(self, rw_repo):
632632@with_rw_repo ("0.1.6" )
633633def test_packed_refs_with_non_utf8_encoding (self ,rw_repo ):
634634"""Test that packed-refs files with non-UTF8 encoded ref names can be read.
635-
635+
636636 This addresses issue #2064 where GitPython would fail with UnicodeDecodeError
637637 when reading packed-refs files containing non-UTF8 characters (e.g., Latin-1
638638 encoded tag names).
639639 """
640640# Create a tag with ASCII name first
641641TagReference .create (rw_repo ,"normal-tag" )
642-
642+
643643# Pack refs
644644rw_repo .git .pack_refs (all = True )
645-
645+
646646# Manually insert a non-UTF8 ref into the packed-refs file
647647# Using Latin-1 characters that are invalid UTF-8
648648packed_refs_path = osp .join (rw_repo .common_dir ,"packed-refs" )
649-
649+
650650with open (packed_refs_path ,"rb" )as f :
651651content = f .read ()
652-
652+
653653# Add a fake ref with Latin-1 encoded name (ñ = 0xF1 in Latin-1, invalid UTF-8)
654654# Using a valid SHA from the repo
655655head_sha = rw_repo .head .commit .hexsha
656656non_utf8_line = f"\n { head_sha } refs/tags/caf\xf1 \n " .encode ("latin-1" )
657-
657+
658658with open (packed_refs_path ,"wb" )as f :
659659f .write (content + non_utf8_line )
660-
660+
661661# This should NOT raise UnicodeDecodeError with the fix
662662# It should successfully read all tags including the non-UTF8 one
663663tags = list (rw_repo .tags )
664664assert len (tags )>= 1
665-
665+
666666# Verify we can iterate packed refs without error
667667from git .refs import SymbolicReference
668+
668669packed_refs = list (SymbolicReference ._iter_packed_refs (rw_repo ))
669670assert len (packed_refs )>= 2 # At least normal-tag and the non-UTF8 tag
670671