I am working on a project containing a submodule and a submodule at the same time. As they are continually build locally, I need to update the submodule at least on every commit I make inside of it.
Here is a post-commit
hook inspired by this post on hooks and this post on submodules and also by this for cleaning the env and for the debugging
this is already a working solution, but if there is a better way I will accept an answer.
#!/bin/sh
### functions
exec_push()
{
ping -c 1 heise.de 2>&1 >> /dev/null # check connectivity
PING_RESULT=$?
if [ $PING_RESULT -eq "0" ]
then
git push --recurse-submodules=on-demand --quiet
else
echo "sorry no internet connectivity"
exit 1
fi
}
### end functions
echo "post-commit started"
branch="$(git rev-parse --abbrev-ref HEAD)"
echo "running on branch $branch"
superproject="$(git rev-parse --show-superproject-working-tree)"
echo "running for superproject $superproject"
current_submodule="$(pwd)"
echo "adding submodule $current_submodule"
if [ "$branch" = "master" ]
then
exec_push
env -i git -C "$superproject" add .
fi
echo "post-commit finished"
instead of commiting the change, it only stages them, so they are commited with the next full commit.