| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -381,23 +381,21 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile | |||
| 381 | 381 | arg_list.append("--aggressive") | |
| 382 | 382 | # END merge handling | |
| 383 | 383 | ||
| 384 | - # tmp file created in git home directory to be sure renaming | ||
| 385 | - # works - /tmp/ dirs could be on another device. | ||
| 386 | - with contextlib.ExitStack() as stack: | ||
| 387 | - tmp_index = stack.enter_context(_named_temporary_file_for_subprocess(repo.git_dir)) | ||
| 384 | + # Create the temporary file in the .git directory to be sure renaming | ||
| 385 | + # works - /tmp/ directories could be on another device. | ||
| 386 | + with _named_temporary_file_for_subprocess(repo.git_dir) as tmp_index: | ||
| 388 | 387 | arg_list.append("--index-output=%s" % tmp_index) | |
| 389 | 388 | arg_list.extend(treeish) | |
| 390 | 389 | ||
| 391 | - # Move current index out of the way - otherwise the merge may fail | ||
| 390 | + # Move the current index out of the way - otherwise the merge may fail | ||
| 392 | 391 | # as it considers existing entries. Moving it essentially clears the index. | |
| 393 | 392 | # Unfortunately there is no 'soft' way to do it. | |
| 394 | 393 | # The TemporaryFileSwap ensures the original file gets put back. | |
| 395 | - | ||
| 396 | - stack.enter_context(TemporaryFileSwap(join_path_native(repo.git_dir, "index"))) | ||
| 397 | - repo.git.read_tree(*arg_list, **kwargs) | ||
| 398 | - index = cls(repo, tmp_index) | ||
| 399 | - index.entries # Force it to read the file as we will delete the temp-file. | ||
| 400 | - return index | ||
| 394 | + with TemporaryFileSwap(join_path_native(repo.git_dir, "index")): | ||
| 395 | + repo.git.read_tree(*arg_list, **kwargs) | ||
| 396 | + index = cls(repo, tmp_index) | ||
| 397 | + index.entries # Force it to read the file as we will delete the temp-file. | ||
| 398 | + return index | ||
| 401 | 399 | # END index merge handling | |
| 402 | 400 | ||
| 403 | 401 | # UTILITIES | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | from typing import Any, Callable, TYPE_CHECKING, Optional, Type | |
| 17 | 17 | ||
| 18 | - from git.types import PathLike, _T | ||
| 18 | + from git.types import Literal, PathLike, _T | ||
| 19 | 19 | ||
| 20 | 20 | if TYPE_CHECKING: | |
| 21 | 21 | from git.index import IndexFile | |
@@ -55,7 +55,7 @@ def __exit__( | |||
| 55 | 55 | exc_type: Optional[Type[BaseException]], | |
| 56 | 56 | exc_val: Optional[BaseException], | |
| 57 | 57 | exc_tb: Optional[TracebackType], | |
| 58 | - ) -> bool: | ||
| 58 | + ) -> Literal[False]: | ||
| 59 | 59 | if osp.isfile(self.tmp_file_path): | |
| 60 | 60 | os.replace(self.tmp_file_path, self.file_path) | |
| 61 | 61 | return False | |
| Back | FazBrowse Home | New Git URL |
0 commit comments