8000 Merge pull request #1789 from EliahKagan/return · gitpython-developers/GitPython@32c02d1 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32c02d1

Browse files
authored
Merge pull request #1789 from EliahKagan/return
Fix mypy warning "Missing return statement"
2 parents b2c46f7 + e194d46 commit 32c02d1

File tree

2 files changed

+11
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -381,23 +381,21 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile
381381
arg_list.append("--aggressive")
382382
# END merge handling
383383

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:
388387
arg_list.append("--index-output=%s" % tmp_index)
389388
arg_list.extend(treeish)
390389

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
392391
# as it considers existing entries. Moving it essentially clears the index.
393392
# Unfortunately there is no 'soft' way to do it.
394393
# 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
401399
# END index merge handling
402400

403401
# UTILITIES
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from typing import Any, Callable, TYPE_CHECKING, Optional, Type
1717

18-
from git.types import PathLike, _T
18+
from git.types import Literal, PathLike, _T
1919

2020
if TYPE_CHECKING:
2121
from git.index import IndexFile
@@ -55,7 +55,7 @@ def __exit__(
5555
exc_type: Optional[Type[BaseException]],
5656
exc_val: Optional[BaseException],
5757
exc_tb: Optional[TracebackType],
58-
) -> bool:
58+
) -> Literal[False]:
5959
if osp.isfile(self.tmp_file_path):
6060
os.replace(self.tmp_file_path, self.file_path)
6161
return False