Last active
August 29, 2015 14:06
-
-
Save swobspace/1f8be56915cf5191f6e3 to your computer and use it in GitHub Desktop.
Update local git repositories if possible
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
#!/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