@@ -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
0 commit comments