Skip to content Skip to sidebar Skip to footer

Python Progress Bar For Git Clone

Im using GitPython to clone a repo within my program. I figured how to display the the status of the clone with the clone_from command but I want the status to look more like a tqd

Solution 1:

You can try something like:

import git
    from git import RemoteProgress
    from tqdm import tqdm
    
    
    classCloneProgress(RemoteProgress):
        defupdate(self, op_code, cur_count, max_count=None, message=''):
            pbar = tqdm(total=max_count)
            pbar.update(cur_count)
    
    git.Repo.clone_from(project_url, repo_dir, branch='master', progress=CloneProgress()

Solution 2:

This is an improved version of the other answer. The bar is created only once when the CloneProgress class is initialized. And when updating, it sets the bar at the correct amount.

import git
from git import RemoteProgress
from tqdm import tqdm

classCloneProgress(RemoteProgress):
    def__init__(self):
        super().__init__()
        self.pbar = tqdm()

    defupdate(self, op_code, cur_count, max_count=None, message=''):
        self.pbar.total = max_count
        self.pbar.n = cur_count
        self.pbar.refresh()

git.Repo.clone_from(project_url, repo_dir, branch='master', progress=CloneProgress()

Post a Comment for "Python Progress Bar For Git Clone"