@@ -632,39 +632,40 @@ def test_tag_message(self, rw_repo):
632632 @with_rw_repo ("0.1.6" )
633633 def 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
641641 TagReference .create (rw_repo , "normal-tag" )
642-
642+
643643 # Pack refs
644644 rw_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
648648 packed_refs_path = osp .join (rw_repo .common_dir , "packed-refs" )
649-
649+
650650 with open (packed_refs_path , "rb" ) as f :
651651 content = 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
655655 head_sha = rw_repo .head .commit .hexsha
656656 non_utf8_line = f"\n { head_sha } refs/tags/caf\xf1 \n " .encode ("latin-1" )
657-
657+
658658 with open (packed_refs_path , "wb" ) as f :
659659 f .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
663663 tags = list (rw_repo .tags )
664664 assert len (tags ) >= 1
665-
665+
666666 # Verify we can iterate packed refs without error
667667 from git .refs import SymbolicReference
668+
668669 packed_refs = list (SymbolicReference ._iter_packed_refs (rw_repo ))
669670 assert len (packed_refs ) >= 2 # At least normal-tag and the non-UTF8 tag
670671
0 commit comments