私はGitPythonをいくつかのレポ操作に使用しようとしていますが、期待しています。GitPython `repo.index.commit()`は永続的なgit.exeインスタンスを生成し、repoへのハンドルを保持します
この問題を解決するには、repo.index.commit()
を呼び出すと、ディレクトリ(おそらく.git\
にあるもの)のハンドルになるようです。後で私のアプリがやろうとしていることに他の失敗が起こります。ここで
は作業unittestのです:
import unittest
import git
import tempfile
import os.path
class Test(unittest.TestCase):
def testCreateRepo(self):
with tempfile.TemporaryDirectory(prefix=(__loader__.name) + "_") as mydir:
# MAKE NEW REPO
repo = git.Repo.init(path=os.path.join(mydir, "newRepo"), mkdir=True)
self.assertTrue(os.path.isdir(os.path.join(repo.working_dir, ".git")), "Failed to make new repo?")
# MAKE FILE, COMMIT REPO
testFileName = "testFile.txt"
open(os.path.join(repo.working_dir, testFileName) , "w").close()
repo.index.add([testFileName])
self.assertTrue(repo.is_dirty())
####
# COMMENTING THIS OUT --> TEST PASSES
repo.index.commit("added initial test file")
self.assertFalse(repo.is_dirty())
####
# adding this does not affect the handle
git.cmd.Git.clear_cache()
print("done") # exception thrown right after this, on __exit__
PermissionError:「C:\ Users \ユーザー%のUSER%\のAppData \ [WinError 32]それは別のプロセスによって使用されているため、プロセスはファイルにアクセスできません。ローカル\ Tempに\ EXAMPLE_gitpython_v3kbrly_ \ newRepo」
が少し深く掘って、gitPythonがgit.exeプロセスの複数のインスタンスを生成します、そして、それらのそれぞれが、レポnewRepo
のルートフォルダへのハンドルを保持しているようです。
- は...すぐにエラーの前に、Sysinternalsのを使用/
newRepo
に開いているハンドルを見に扱うのSysinternals/procexp Iを使用してgit.exe(git.exeの4つの別々のPID年代は正確には) - をブレークポイントを設定しました彼らはすべてが日食から産み出されていることを見ることができます - > python
これはrepo.index.commit()の呼び出しです。実際にはgit.exeが生成されます。 gitpythonの開発者と協力
これはどこにもないように見えますが、これは悪い振る舞いのようですので、私はバグを提出しました:https://github.com/gitpython-developers/GitPython/issues/553 – mike