如何使用python git克隆存储库,并获得克隆过程的进度?

Jon*_*han 6 python git

我希望能够使用某些库使用python git克隆大型存储库,但重要的是,我希望能够看到克隆的进展情况。我尝试了pygit2和GitPython,但是它们似乎没有显示出它们的进度。还有另一种方法吗?

Rob*_*obᵩ 9

您可以RemoteProgressGitPython使用。这是一个粗略的例子:

import git

class Progress(git.remote.RemoteProgress):
    def update(self, op_code, cur_count, max_count=None, message=''):
        print 'update(%s, %s, %s, %s)'%(op_code, cur_count, max_count, message)

repo = git.Repo.clone_from(
    'https://github.com/gitpython-developers/GitPython',
    './git-python',
    progress=Progress())
Run Code Online (Sandbox Code Playgroud)

或者使用这个update()函数来获得更精细的消息格式:

    def update(self, op_code, cur_count, max_count=None, message=''):
        print self._cur_line
Run Code Online (Sandbox Code Playgroud)