Also use TemporaryDirectory in git_checkout

This commit is contained in:
Daniël de Kok 2023-01-25 13:17:39 +01:00
parent 1ac4144949
commit ccbaaa3b3c

View File

@ -1,3 +1,4 @@
from tempfile import TemporaryDirectory
from typing import Dict, Any, Union, List, Optional, Tuple, Iterable
from typing import TYPE_CHECKING, overload
import sys
@ -405,13 +406,14 @@ def git_checkout(
f"temporarily. To only download the files needed, make sure "
f"you're using Git v2.22 or above."
)
with make_tempdir() as tmp_dir:
cmd = f"git -C {tmp_dir} clone {repo} . -b {branch}"
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
cmd = f"git -C {tmp_path} clone {repo} . -b {branch}"
run_command(cmd, capture=True)
# We need Path(name) to make sure we also support subdirectories
try:
source_path = tmp_dir / Path(subpath)
if not is_subpath_of(tmp_dir, source_path):
source_path = tmp_path / Path(subpath)
if not is_subpath_of(tmp_path, source_path):
err = f"'{subpath}' is a path outside of the cloned repository."
msg.fail(err, repo, exits=1)
if os.path.isdir(source_path):