Skip to content

Commit 553a70a

Browse files
codexByron
authored andcommitted
Use Windows-safe cleanup for object-directory test
The replacement Python 3.7 Windows run confirmed that every test assertion passes, but tempfile.TemporaryDirectory cannot remove the read-only loose object produced by Git and reports WinError 5. Use the test suite's existing with_rw_directory helper, which collects lingering references and removes read-only files correctly on Windows. Validation: focused pytest; Ruff check and format; mypy; compileall; git diff --check.
1 parent c43d203 commit 553a70a

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

test/test_repo.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,29 +271,29 @@ def test_repo_discovery_uses_storage_environment(self):
271271

272272
assert osp.samefile(Repo(git_dir).common_dir, byte_common_dir)
273273

274-
def test_repo_discovery_preserves_object_directory(self):
275-
with tempfile.TemporaryDirectory() as tdir:
276-
git_dir = Path(tdir) / "git"
277-
payload = b"custom object database"
278-
payload_file = Path(tdir) / "payload"
279-
payload_file.write_bytes(payload)
280-
281-
source_repo = Repo.init(git_dir, bare=True)
282-
blob_hexsha = source_repo.git.hash_object("-w", payload_file)
283-
source_repo.close()
284-
object_dir = Path(tdir) / "objects"
285-
(git_dir / "objects").rename(object_dir)
286-
287-
with cwd(tdir), mock.patch.dict(os.environ, {"GIT_DIR": "git", "GIT_OBJECT_DIRECTORY": "objects"}):
288-
repo = Repo(odbt=GitDB)
289-
290-
with repo:
291-
assert osp.samefile(repo.odb.root_path(), object_dir)
292-
assert repo.odb.has_object(bytes.fromhex(blob_hexsha))
293-
assert repo.git.cat_file("blob", blob_hexsha) == payload.decode()
294-
repo.alternates = ["other/location"]
295-
assert repo.alternates == ["other/location"]
296-
assert (object_dir / "info" / "alternates").is_file()
274+
@with_rw_directory
275+
def test_repo_discovery_preserves_object_directory(self, tdir):
276+
git_dir = Path(tdir) / "git"
277+
payload = b"custom object database"
278+
payload_file = Path(tdir) / "payload"
279+
payload_file.write_bytes(payload)
280+
281+
source_repo = Repo.init(git_dir, bare=True)
282+
blob_hexsha = source_repo.git.hash_object("-w", payload_file)
283+
source_repo.close()
284+
object_dir = Path(tdir) / "objects"
285+
(git_dir / "objects").rename(object_dir)
286+
287+
with cwd(tdir), mock.patch.dict(os.environ, {"GIT_DIR": "git", "GIT_OBJECT_DIRECTORY": "objects"}):
288+
repo = Repo(odbt=GitDB)
289+
290+
with repo:
291+
assert osp.samefile(repo.odb.root_path(), object_dir)
292+
assert repo.odb.has_object(bytes.fromhex(blob_hexsha))
293+
assert repo.git.cat_file("blob", blob_hexsha) == payload.decode()
294+
repo.alternates = ["other/location"]
295+
assert repo.alternates == ["other/location"]
296+
assert (object_dir / "info" / "alternates").is_file()
297297

298298
@with_rw_repo("0.3.2.1")
299299
def test_repo_creation_from_different_paths(self, rw_repo):

0 commit comments

Comments
 (0)