Skip to content

Commit d1cce0f

Browse files
codexByron
authored andcommitted
Handle undecodable repository metadata on Windows
Python 3.9 on Windows raised UnicodeDecodeError while the repository-discovery regression test parsed invalid commondir bytes, causing the Python package test (windows, 3.9) check to fail. Treat UnicodeError like an unreadable metadata file in both commondir and gitfile parsing. Invalid bytes now make discovery reject the candidate repository, matching Git's behavior. Validation: env PYTHONPATH=gitdb:smmap .venv/bin/python -m pytest -q test/test_repo.py::TestRepo::test_repo_discovery_rejects_invalid_metadata; .venv/bin/python -m compileall -q git/repo/fun.py; git diff --check
1 parent 83c3e64 commit d1cce0f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

git/repo/fun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def is_git_dir(d: PathLike) -> bool:
9494
if osp.lexists(common_dir_file):
9595
return False
9696
common_dir = os.fspath(d)
97-
except OSError:
97+
except (OSError, UnicodeError):
9898
return False
9999
else:
100100
if not common_dir:
@@ -125,7 +125,7 @@ def find_worktree_git_dir(dotgit: PathLike) -> Optional[str]:
125125

126126
try:
127127
content = os.fsdecode(Path(dotgit).read_bytes()).rstrip("\r\n")
128-
except OSError:
128+
except (OSError, UnicodeError):
129129
return None
130130
return content[8:] if len(content) >= 9 and content.startswith("gitdir: ") else None
131131

0 commit comments

Comments
 (0)