Created
March 24, 2020 03:43
-
-
Save MisterBianco/7021246ea500687dc0ce79a583d6f978 to your computer and use it in GitHub Desktop.
A python tool to update all repos under a given directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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