Answer a question

I'd like to be able to git clone a large repository using python, using some library, but importantly I'd like to be able to see the progress of the clone as it's happening. I tried pygit2 and GitPython, but they don't seem to show their progress. Is there another way?

Answers

You can use RemoteProgress from GitPython. Here is a crude example:

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())

Or use this update() function for a slightly more refined message format:

    def update(self, op_code, cur_count, max_count=None, message=''):
        print self._cur_line
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐