Skip to content

Instantly share code, notes, and snippets.

@impiaaa
Created October 10, 2012 16:19
Show Gist options
  • Save impiaaa/3866671 to your computer and use it in GitHub Desktop.
Save impiaaa/3866671 to your computer and use it in GitHub Desktop.
Updates every repository in a folder. Supports CVS, SVN, Mercurial, Git, and Bazaar.
#!/bin/bash
# update repos.sh
#
#
# Created by Spencer Alves on 9/16/10.
# Copyright 2012 Spencer Alves. All rights reserved.
CVSUP="cvs update"
SVNUP="svn update"
HGUP="hg pull -u"
GITUP="git pull"
BZRUP="bzr update"
CVSREV=
function SVNREV { svn info | grep Revision | egrep -o \[0-9\]+; }
function HGREV { hg parents | egrep -o changeset:\.\*\[0-9\]+: | egrep -o \[0-9\]+; }
function GITREV { git log -n 1 | egrep -o ^commit\ [a-f0-9\]+ | egrep -o \[a-f0-9\]+\$; }
function BZRREV { bzr version-info | grep revno | egrep -o \[0-9\]+; }
CVSLOG="cvs history"
SVNLOG="svn log"
HGLOG="hg log"
GITLOG="git log"
BZRLOG="bzr log"
CVSDIR="CVS"
SVNDIR=".svn"
HGDIR=".hg"
GITDIR=".git"
BZRDIR=".bzr"
rootdir=`pwd`
for dir in *; do
echo $dir
# I should clean this up later...
if [ -d "${dir}/${CVSDIR}" ]; then
cd "${dir}"
${CVSUP} > /dev/null
echo ${dir} "updated"
cd "${rootdir}"
fi
if [ -d "${dir}/${SVNDIR}" ]; then
cd "${dir}"
oldrevision=`SVNREV`
${SVNUP} > /dev/null
newrevision=`SVNREV`
if [ ${newrevision} != ${oldrevision} ]; then
echo ${dir} "updated from" ${oldrevision} "to" ${newrevision}
${SVNLOG} -r ${oldrevision}:${newrevision}
fi
cd "${rootdir}"
fi
if [ -d "${dir}/${HGDIR}" ]; then
cd "${dir}"
oldrevision=`HGREV`
${HGUP} > /dev/null
newrevision=`HGREV`
if [ ${newrevision} != ${oldrevision} ]; then
echo ${dir} "updated from" ${oldrevision} "to" ${newrevision}
${HGLOG} -r ${oldrevision}:${newrevision}
fi
cd "${rootdir}"
fi
if [ -d "${dir}/${GITDIR}" ]; then
cd "${dir}"
oldrevision=`GITREV`
${GITUP} > /dev/null
newrevision=`GITREV`
if [ ${newrevision} != ${oldrevision} ]; then
echo ${dir} "updated from" ${oldrevision} "to" ${newrevision}
${GITLOG} ${oldrevision}..${newrevision} | cat
fi
cd "${rootdir}"
fi
if [ -d "${dir}/${BZRDIR}" ]; then
cd "${dir}"
oldrevision=`BZRREV`
${BZRUP} > /dev/null
newrevision=`BZRREV`
if [ ${newrevision} != ${oldrevision} ]; then
echo ${dir} "updated from" ${oldrevision} "to" ${newrevision}
${BZRLOG} -r${oldrevision}..${newrevision}
fi
cd "${rootdir}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment