Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@swobspace
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swobspace/1f8be56915cf5191f6e3 to your computer and use it in GitHub Desktop.
Save swobspace/1f8be56915cf5191f6e3 to your computer and use it in GitHub Desktop.
Update local git repositories if possible
#!/bin/bash
# check existing git directories for open commits/pushes
# and update via pull
export TO_COMMIT=()
export TO_PUSH=()
# REPOs=`find . -name .git`
# only one level
REPOs=`ls -d */.git`
function pull_repo {
current=$1
echo "# -- repo $current"
git status --porcelain
open_commits=`git status --porcelain | wc -l`
if [ $open_commits -gt 0 ]; then
echo "open commits, no pull, please commit first"
$SLEEP
else
git pull
fi
echo ""
}
# -- not pushed
function not_pushed {
x=`git status | egrep -ic 'your branch is ahead'`
if [ $x -gt 0 ]; then
TO_PUSH[${#TO_PUSH[*]}]="$1"
fi
}
# -- not committed
function not_committed {
y=` git status --porcelain | wc -l`
if [ $y -gt 0 ]; then
TO_COMMIT[${#TO_COMMIT[*]}]="$1"
fi
}
for REPO in $REPOs; do
remote=`grep remote $REPO/config`
if [ "$remote" != "" ]; then
GITHUB=`grep url $REPO/config`
if ! [[ "$GITHUB" =~ "github" ]] || [[ "$REPO" =~ "github" ]] || [[ `pwd` =~ "github" ]] ; then
repo=${REPO%/.git}
echo $repo
oldpath=`pwd`
cd $repo
pull_repo $repo
not_pushed $repo
not_committed $repo
cd $oldpath
fi
fi
done
echo "#### Summary ####"
echo "# Sites to push: ${TO_PUSH[*]}"
echo "# Sites not committed: ${TO_COMMIT[*]}"
echo "#################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment