Skip to content

Instantly share code, notes, and snippets.

@MisterBianco
Created March 24, 2020 03:43
Show Gist options
  • Save MisterBianco/7021246ea500687dc0ce79a583d6f978 to your computer and use it in GitHub Desktop.
Save MisterBianco/7021246ea500687dc0ce79a583d6f978 to your computer and use it in GitHub Desktop.
A python tool to update all repos under a given directory.
#!/usr/bin/env python3
#~*~ coding: utf-8 ~*~
import os
import git
import click
def pull(repo, dirx):
print("Path: " + dirx)
for fetch_info in repo.remotes.origin.fetch():
print("Updated %s to %s" % (fetch_info.ref, fetch_info.commit))
print("-" * 50)
@click.command()
@click.argument('dir', type=click.Path(file_okay=False, exists=True))
def main(dir):
for dirx in [x[0] for x in os.walk(dir)]:
try:
gitRepo = git.Repo(dirx)
pull(gitRepo, dirx)
except (git.exc.InvalidGitRepositoryError, git.exc.NoSuchPathError, git.exc.GitCommandError) as err:
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment