我试图使用GitPython进行一些回购操作,但遇到了与我的应用程序的问题,与处理打开我wouldn'没想到。GitPython`repo.index.commit()`产生持久的git.exe实例,拥有处理回购
Bug-jarring的问题,似乎呼吁repo.index.commit()
结果处理目录(大概是在.git\
)。之后,这会导致我的应用尝试执行的其他失败。
这里是一个工作单元测试:
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:[WinError 32]的方法,因为它被另一个过程不能访问该文件:C:\用户\%USER%\应用程序数据\本地的\ Temp \ EXAMPLE_gitpython_v3kbrly_ \ newRepo”
挖得更深一些,似乎gitPython滋生git.exe进程的多个实例,和他们每个人持有的句柄回购newRepo
的根文件夹。
- 立即设置断点的错误之前,使用Sysinternals的/手柄,看看打开的句柄
newRepo
... git.exe使用的Sysinternals/procexp我(git.exe的4个独立PID的要准确) - 可以看到它们都是从eclipse衍生出来的 - > python
单步执行,这是对repo.index.commit()的调用,它实际上会导致生成git.exe。
这似乎没有得到任何地方,这似乎是不好的行为,所以我提交了一个bug:https://github.com/gitpython-developers/GitPython/issues/553 – mike