diff --git a/git/index/base.py b/git/index/base.py index 209bfa8de..503f63179 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -339,7 +339,7 @@ def from_tree(cls, repo: 'Repo', *treeish: Treeish, **kwargs: Any) -> 'IndexFile # tmp file created in git home directory to be sure renaming # works - /tmp/ dirs could be on another device - tmp_index = tempfile.mktemp('', '', repo.git_dir) + tmp_index = tempfile.mkdtemp('', '', repo.git_dir) arg_list.append("--index-output=%s" % tmp_index) arg_list.extend(treeish) diff --git a/git/index/util.py b/git/index/util.py index 4f8af5531..91bdbef87 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -38,7 +38,7 @@ class TemporaryFileSwap(object): def __init__(self, file_path: PathLike) -> None: self.file_path = file_path - self.tmp_file_path = str(self.file_path) + tempfile.mktemp('', '', '') + self.tmp_file_path = str(self.file_path) + tempfile.mkdtemp('', '', '') # it may be that the source does not exist try: os.rename(self.file_path, self.tmp_file_path)