Skip to content

Instantly share code, notes, and snippets.

@arjan
Created May 16, 2012 08:48
Show Gist options
  • Save arjan/2708804 to your computer and use it in GitHub Desktop.
Save arjan/2708804 to your computer and use it in GitHub Desktop.
Automatically update and commit a parent repository when a submodule changed
#!/bin/bash
# Arjan Scherpenisse, 2012-05-16
#
# Automatically update and commit a parent repository when a submodule changed
DIR=$(dirname $PWD)
PART=$(basename $PWD)
cd ..
while [ "$DIR" != "/" ]; do
PARENTREPO=$(basename $DIR)
if [ -d "$DIR/.git" ]; then
if $(git diff $PART|grep "dirty" >/dev/null); then
echo "This repository is dirty, cannot updated parent repository $PARENTREPO.";
exit 1
fi
git add $PART
git commit -m "Updated submodule `basename $PART`"
git push
echo "Commited and pushed to $PARENTREPO."
break
fi
PART="`basename $DIR`/$PART"
DIR=$(dirname $DIR)
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment