Last active
December 11, 2015 02:29
-
-
Save jonentropy/4531476 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Update all git repos in a directory by calling git pull | |
# | |
# | |
#Init | |
FAILED_DIRS=() | |
FAILED_MSGS=() | |
UPDATED_REPOS=() | |
NUM_FAILED=0 | |
NUM_UPDATED=0 | |
MSG="" | |
DIR_CHANGED="" | |
#Look in all directories for git repos to pull | |
for dir in `ls -d */`; | |
do | |
cd "$dir" | |
DIR_CHANGED="$?" | |
if [ $DIR_CHANGED -eq 0 ]; then | |
#Directory change succeeded | |
#Only continue if this is a git repo | |
if [ -d ".git" ]; then | |
#Only continue if this has a remote called origin... | |
git ls-remote origin > /dev/null 2>&1 | |
if test $? = 0; then | |
MSG=`git pull 2>&1` | |
RETVAL=$? | |
#Save details of any failures | |
PULLED=1 | |
echo $MSG | grep -q "Already up-to-date." && PULLED=0 | |
[ $RETVAL -eq 0 ] && [ $PULLED -eq 0 ] && echo -ne "." | |
[ $RETVAL -eq 0 ] && [ $PULLED -eq 1 ] && echo -ne "o" && UPDATED_REPOS[$NUM_UPDATED]="$dir" && ((NUM_UPDATED++)) | |
[ $RETVAL -ne 0 ] && echo -ne "X" && FAILED_DIRS[$NUM_FAILED]="$dir" && FAILED_MSGS[$NUM_FAILED]="$MSG" && ((NUM_FAILED++)) | |
fi | |
fi | |
cd .. | |
fi | |
done | |
if [ ${#UPDATED_REPOS[@]} -ne 0 ]; then | |
echo | |
echo | |
echo "Updated repos:" | |
echo | |
for (( i=0; i<${#UPDATED_REPOS[@]}; i++ )); | |
do | |
echo "${UPDATED_REPOS[$i]}" | |
echo | |
done | |
echo | |
fi | |
if [ ${#FAILED_DIRS[@]} -ne 0 ]; then | |
echo | |
echo | |
echo "Failures:" | |
for (( i=0; i<${#FAILED_DIRS[@]}; i++ )); | |
do | |
echo | |
echo "${FAILED_DIRS[$i]} FAILED, message = ${FAILED_MSGS[$i]}" | |
echo | |
done | |
echo | |
else | |
echo | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment