
Untitled
By: a guest on
Aug 20th, 2012 | syntax:
None | size: 1.38 KB | hits: 9 | expires: Never
#! /bin/bash
#guarantee you are in the directory you are in (src: http://stackoverflow.com/a/246128)
cd -P "$(dirname "$0")"
# basically traverse down all directories until you run across a
# .git/.svn/.hg directory, then update/pull the directory (stop traversing)
#updaterepo <folder type found> <path name to display>
updaterepo()
{
echo "$(tput setaf 2)Updating repository: $(tput setaf 3)$2$(tput sgr0)"
case "$1" in
".git/")
# check if git repo is of git-svn type (src: http://stackoverflow.com/a/9086279)
if [ -d .git/svn ] && [ x != x"$(ls -A .git/svn/)" ]
then
git svn rebase
else
git pull
fi
;;
".svn/") svn update;;
".hg/") hg update;;
esac
echo
}
#traverses directories looking for .git, .svn, .hg folders (src: http://steve-parker.org/sh/eg/directories)
#traverse <folder to enter> <path name to display>
traverse()
{
cd "$1"
vc=0
# get all directories in current dir starting with '.'
# without . & .. (must have 2-3 chars after the '.')
for dir in $(ls -d .*/ | grep -P -e "^\..{2,3}/$")
do
case "$dir" in
".git/"|".svn/"|".hg/")
vc=1
updaterepo "$dir" "$2"
;;
esac
done
#do not enter diretory if it is repo controlled
if [ 1 -ne "$vc" ]
then
for dir in $(ls -d */)
do
traverse "$dir" "$2$dir"
done
fi
cd ..
}
# get the current directory name (src: http://stackoverflow.com/a/1371283)
traverse . "${PWD##*/}/"