diff --git a/git/index/base.py b/git/index/base.py index 5ba817ed3..9d1db4e35 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -381,23 +381,21 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile arg_list.append("--aggressive") # END merge handling - # tmp file created in git home directory to be sure renaming - # works - /tmp/ dirs could be on another device. - with contextlib.ExitStack() as stack: - tmp_index = stack.enter_context(_named_temporary_file_for_subprocess(repo.git_dir)) + # Create the temporary file in the .git directory to be sure renaming + # works - /tmp/ directories could be on another device. + with _named_temporary_file_for_subprocess(repo.git_dir) as tmp_index: arg_list.append("--index-output=%s" % tmp_index) arg_list.extend(treeish) - # Move current index out of the way - otherwise the merge may fail + # Move the current index out of the way - otherwise the merge may fail # as it considers existing entries. Moving it essentially clears the index. # Unfortunately there is no 'soft' way to do it. # The TemporaryFileSwap ensures the original file gets put back. - - stack.enter_context(TemporaryFileSwap(join_path_native(repo.git_dir, "index"))) - repo.git.read_tree(*arg_list, **kwargs) - index = cls(repo, tmp_index) - index.entries # Force it to read the file as we will delete the temp-file. - return index + with TemporaryFileSwap(join_path_native(repo.git_dir, "index")): + repo.git.read_tree(*arg_list, **kwargs) + index = cls(repo, tmp_index) + index.entries # Force it to read the file as we will delete the temp-file. + return index # END index merge handling # UTILITIES diff --git a/git/index/util.py b/git/index/util.py index 61039fe7c..125925783 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -15,7 +15,7 @@ from typing import Any, Callable, TYPE_CHECKING, Optional, Type -from git.types import PathLike, _T +from git.types import Literal, PathLike, _T if TYPE_CHECKING: from git.index import IndexFile @@ -55,7 +55,7 @@ def __exit__( exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], - ) -> bool: + ) -> Literal[False]: if osp.isfile(self.tmp_file_path): os.replace(self.tmp_file_path, self.file_path) return False
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: