Created
August 13, 2010 06:17
-
-
Save harryxu/522409 to your computer and use it in GitHub Desktop.
vcsup. Update all vcs dirs in a specific path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Update all vcs dirs in a specific path. | |
# Support git, hg and svn. | |
basePath=`pwd` | |
function vcsup() | |
{ | |
echo "checing $1" | |
# git | |
if [[ -d "$1/.git" ]] | |
then | |
if [[ -d "$1/.git/svn" ]] | |
then | |
cmd='git svn rebase' | |
else | |
cmd='git pull' | |
fi | |
# hg | |
elif [[ -d "$1/.hg" ]] | |
then | |
cmd='hg pull' | |
# svn | |
elif [[ -d "$1/.svn" ]] | |
then | |
cmd='svn up' | |
fi | |
if [[ -n "$cmd" ]] | |
then | |
cd $1 | |
echo "vcsup: $cmd" | |
$cmd | |
cd - | |
cmd= | |
return 0 | |
else | |
echo "not vcs dir" | |
return 1; | |
fi | |
} | |
if [[ -n "$1" ]] | |
then | |
if [[ $1 =~ ^/ ]] | |
then | |
basePath=$1 | |
else | |
basePath="$basePath/$1" | |
fi | |
fi | |
if [[ -d $basePath ]] | |
then | |
vcsup $basePath | |
if [[ "$?" -eq 1 ]] | |
then | |
for i in `ls $basePath` | |
do | |
p="$basePath/$i" | |
if [[ -d $p ]] | |
then | |
vcsup $p | |
fi | |
done | |
fi | |
else | |
echo "no such directory: $basePath" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment