aboutsummaryrefslogblamecommitdiff
path: root/ssh-sync-repos.py
blob: 756686d2db65047e8e06764625efe04b6c8228d6 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                                                             



                                               

                            

                                           


                                  

                                              

                       


                                                                            
                                                                     


                                                                                  
                                                                 
                 
 
          
#!/usr/bin/env python
#
# Synchronize Cryptech git repositories via SSH by asking gitolite for a JSON
# listing of repositories.  Not useful unless you have an SSH account, sorry.

from subprocess import check_call, check_output
from os.path    import isdir
from json       import loads
from sys        import exit

user = "git@git.cryptech.is"
cmd  = "ssh {} info -json -lc".format(user)
info = loads(check_output(cmd.split()))
errs = 0

for repo in sorted(info["repos"]):
    try:
        if all(c not in repo for c in "*?[]"):
            print("")
            print(repo)
            pull = isdir(repo)
            if pull:
                check_call(("git", "fetch", "--all", "--prune"), cwd = repo)
                check_call(("git", "merge", "--ff-only"), cwd = repo)
            else:
                check_call(("git", "clone", "{}:{}.git".format(user, repo), repo))
    except:
        print("** Error", "pulling" if pull else "cloning", repo)
        errs += 1

exit(errs)