Skip to content

Commit dc4adb0

Browse files
committed
Fix rmtree bug on Windows
1 parent be626e5 commit dc4adb0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/repo_smith/initialize_repo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self, spec_data: Any) -> None:
4141
@contextmanager
4242
def initialize(self, existing_path: Optional[str] = None) -> Iterator[Repo]:
4343
tmp_dir = tempfile.mkdtemp() if existing_path is None else existing_path
44+
repo: Optional[Repo] = None
4445
try:
4546
if self.__spec.clone_from is not None:
4647
repo = Repo.clone_from(self.__spec.clone_from.repo_url, tmp_dir)
@@ -57,7 +58,9 @@ def initialize(self, existing_path: Optional[str] = None) -> Iterator[Repo]:
5758
self.__post_hooks[step.id](repo)
5859
yield repo
5960
finally:
60-
shutil.rmtree(tmp_dir)
61+
if repo is not None:
62+
repo.git.clear_cache()
63+
shutil.rmtree(tmp_dir)
6164

6265
def add_pre_hook(self, id: str, hook: Hook) -> None:
6366
if id not in self.__step_ids:

0 commit comments

Comments
 (0)