Last active
June 20, 2016 10:33
-
-
Save mdbooth/2e7661611e4e8345c691b4f94305af51 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
find ~/devstack ~/openstack -name .git -type d | while read dir; do | |
working=$(dirname "$dir") | |
pushd "$working" >/dev/null | |
# Don't update if we're not on the master branch | |
if [ $(git rev-parse HEAD master | uniq | wc -l) != "1" ]; then | |
echo "Skipping $working: not on master branch" | |
continue | |
fi | |
out=$(mktemp) | |
error= | |
# Check the working tree and the index for uncommitted changes | |
if git diff --no-ext-diff --quiet --exit-code && \ | |
git diff-index --cached --quiet HEAD -- | |
then | |
stashed= | |
else | |
stashed="yes" | |
echo "Stashing changes in $working before pulling" | |
git stash >>"$out" | |
fi | |
git pull >>"$out" 2>&1 | |
if [ $? != 0 ]; then | |
error="yes" | |
fi | |
if [ -n "$stashed" ]; then | |
git stash pop >>"$out" | |
if [ $? != 0 ]; then | |
error="yes" | |
fi | |
fi | |
if [ -n "$error" ]; then | |
echo "Error updating $working:" | |
cat "$out" | |
echo | |
fi | |
rm "$out" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment