Version Control Updating Bash Script

A short while ago, I created a script to go through all my local copies of open source software that I had downloaded from GitHub, Google Code, and other places. The reason behind it being that going through and manually updating each one was a pain in the neck. After looking at Bash scripting, I came up with the following solution. Feel free to use it yourself.

#!/bin/bash

function usage() {
	echo " Usage: $0 -h."
	echo " Updates Git, SVN, or Mercurial repositories in a directory."
}

while getopts h o
do

	case $o in
	h) usage && exit 1;;
	esac

done

for i in $( ls ); do
	cd $i
	
	if [ -e .git ]
	then
		echo -e "\033[1mUpdating $i:\033[0m"
		git pull
	fi
	
	if [ -e .svn ]
	then
		echo -e "\033[1mUpdating $i:\033[0m"
		svn update
	fi
	
	if [ -e .hg ]
	then
		echo -e "\033[1mUpdating $i:\033[0m"
		hg pull -u
	fi
	
	cd ..
done

Posted 01/21/10 at 6:24 PM