Skip to content

Instantly share code, notes, and snippets.

@mdbooth
Last active June 20, 2016 10:33
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 mdbooth/2e7661611e4e8345c691b4f94305af51 to your computer and use it in GitHub Desktop.
Save mdbooth/2e7661611e4e8345c691b4f94305af51 to your computer and use it in GitHub Desktop.
#!/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