gitPython 克隆 GitCommandError

gitPython clone GitCommandError

我正在用这样的函数测试 gitPython 的克隆,

git.Repo.clone_from("https://github.com/nicothin/web-design.git","/home/tom/src",branch='master',recursive=True)

但它总是报错,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/git/repo/base.py", line 885, in clone_from
    return cls._clone(git, url, to_path, GitCmdObjectDB, progress, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/repo/base.py", line 831, in _clone
    finalize_process(proc)
  File "/usr/local/lib/python2.7/dist-packages/git/util.py", line 155, in finalize_process
    proc.wait()
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 319, in wait
    raise GitCommandError(self.args, status, self.proc.stderr.read())
ValueError: I/O operation on closed file

有人能告诉我如何解决这个问题吗?我试图修复 GIT_PYTHON_GIT_EXECUTEABLE 和 GIT_PYTHON_TRACE ,它们都不起作用。

好的,我自己解决了这个问题。根据 GitHub 问题记录,如 this,这是一个错误。我是 运行 Ubuntu 15.10,默认的 GitPython 版本是 1.0.2,所以我无法调试它,因为我不知道 git 命令 returns.

在我从 GitPython github 存储库获取源代码并安装后,我能够看到异常中发生了什么。最后 clone_from() 命令的目标路径必须是一个新路径,如果它已经存在,则会出现 git 命令错误,所以我将其更改为

git.Repo.clone_from("https://github.com/nicothin/web-design.git","/home/tom/src/mustBeNewPath",branch='master',recursive=True)

问题已解决。