Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit a3859ee

Browse files
fixes
1 parent 8186159 commit a3859ee

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

‎git/index/base.py‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,26 +353,22 @@ def from_tree(cls, repo: "Repo", *treeish: Treeish, **kwargs: Any) -> "IndexFile
353353

354354
# tmp file created in git home directory to be sure renaming
355355
# works - /tmp/ dirs could be on another device
356-
tmp_index = tempfile.mktemp("", "", repo.git_dir)
357-
arg_list.append("--index-output=%s" % tmp_index)
358-
arg_list.extend(treeish)
359-
360-
# move current index out of the way - otherwise the merge may fail
361-
# as it considers existing entries. moving it essentially clears the index.
362-
# Unfortunately there is no 'soft' way to do it.
363-
# The TemporaryFileSwap assure the original file get put back
364-
try:
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
372-
finally:
373-
if osp.exists(tmp_index):
374-
os.remove(tmp_index)
375-
# END index merge handling
356+
with ExitStack() as stack:
357+
tmp_index = stack.enter_context(tempfile.NamedTemporaryFile(dir=repo.git_dir))
358+
arg_list.append("--index-output=%s" % tmp_index.name)
359+
arg_list.extend(treeish)
360+
361+
# move current index out of the way - otherwise the merge may fail
362+
# as it considers existing entries. moving it essentially clears the index.
363+
# Unfortunately there is no 'soft' way to do it.
364+
# The TemporaryFileSwap assure the original file get put back
365+
366+
stack.enter_context(TemporaryFileSwap(join_path_native(repo.git_dir, "index")))
367+
repo.git.read_tree(*arg_list, **kwargs)
368+
index = cls(repo, tmp_index.name)
369+
index.entries # force it to read the file as we will delete the temp-file
370+
return index
371+
# END index merge handling
376372

377373
# UTILITIES
378374
@unbare_repo

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /