4
4
# This module is part of GitPython and is released under
5
5
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
6
7
+ from contextlib import ExitStack
7
8
import datetime
8
9
import glob
9
10
from io import BytesIO
@@ -360,20 +361,19 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile
360
361
# as it considers existing entries. moving it essentially clears the index.
361
362
# Unfortunately there is no 'soft' way to do it.
362
363
# The TemporaryFileSwap assure the original file get put back
363
- if repo .git_dir :
364
- index_handler = TemporaryFileSwap (join_path_native (repo .git_dir , "index" ))
365
364
try :
366
- repo .git .read_tree (* arg_list , ** kwargs )
367
- index = cls (repo , tmp_index )
368
- index .entries # force it to read the file as we will delete the temp-file
369
- del index_handler # release as soon as possible
365
+ with ExitStack () as stack :
366
+ if repo .git_dir :
367
+ stack .enter_context (TemporaryFileSwap (join_path_native (repo .git_dir , "index" )))
368
+ repo .git .read_tree (* arg_list , ** kwargs )
369
+ index = cls (repo , tmp_index )
370
+ index .entries # force it to read the file as we will delete the temp-file
371
+ return index
370
372
finally :
371
373
if osp .exists (tmp_index ):
372
374
os .remove (tmp_index )
373
375
# END index merge handling
374
376
375
- return index
376
-
377
377
# UTILITIES
378
378
@unbare_repo
379
379
def _iter_expand_paths (self : "IndexFile" , paths : Sequence [PathLike ]) -> Iterator [PathLike ]:
@@ -1156,7 +1156,6 @@ def checkout(
1156
1156
unknown_lines = []
1157
1157
1158
1158
def handle_stderr (proc : "Popen[bytes]" , iter_checked_out_files : Iterable [PathLike ]) -> None :
1159
-
1160
1159
stderr_IO = proc .stderr
1161
1160
if not stderr_IO :
1162
1161
return None # return early if stderr empty
0 commit comments