Skip to content

Instantly share code, notes, and snippets.

@luca-m
Last active December 16, 2015 04:59
Show Gist options
  • Select an option

  • Save luca-m/5381563 to your computer and use it in GitHub Desktop.

Select an option

Save luca-m/5381563 to your computer and use it in GitHub Desktop.
If you are used to use software downloaded from git repositories and you are tired to manually pull latest version of your favourite software, this quick script for auto-update all gits in a given folder might make you save a bunch of minutes.
#!/usr/bin/env python
#-------------------------------------------------------------
# Name: gitupdate.py
# Purpose: Update all git repositories found in subfolders.
# Author: stk
# Created: 14/04/2013
# Copyright: (c) stk
# Python Version: 2.7
# Dependencies: git,hg,svn
#-------------------------------------------------------------
import os
import subprocess
import argparse
DIR=['.git','.hg','.svn']
CMD={'.git':'git pull origin master','.hg':'hg pull default','.svn':'svn update'}
def update(projectpath,cmd):
print ">>> Updating '%s':"%(os.path.basename(projectpath))
res=''
try:
updcmd="cd '%s';"%projectpath
updcmd+=cmd
res=subprocess.check_output(updcmd,shell=True)
outmsg='SUCCESS'
except subprocess.CalledProcessError as e:
outmsg='FAIL: %s '%str(e)
print res
print "<<< Done '%s' (%s)"%(os.path.basename(projectpath),outmsg)
def navigate(folder):
""" """
for (path,dirs,files) in os.walk(folder):
for D in DIR:
if D in dirs:
update(path,CMD[D])
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-f","--folder", help="Folder where to search for git projects",action="store")
args = parser.parse_args()
path = os.path.curdir
if args.folder:
path = args.folder
navigate(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment