diff --git a/utils/update-submodules b/utils/update-submodules new file mode 100755 index 0000000..00b8c0a --- /dev/null +++ b/utils/update-submodules @@ -0,0 +1,54 @@ +#! /usr/bin/env bash + +#------------------------------------------------------------------------------# +# This script updates any submodules that are set to track a specific branch +# to the HEAD of the specified branch. +# +# The script checks that: +# - The user is on the HEAD of the 'devel' branch of the current project. +# - The user does not have any uncommitted changes. +# +# This script should be used with some care because it will modify the remote. +#------------------------------------------------------------------------------# + +# Make sure that the user is on the devel branch +branch=`git branch | grep \* | cut -d ' ' -f2` + +if [ "$branch" != "devel" ] ; then + echo "ERROR: You must be on the devel branch to run this script!!!" + echo "Try: git checkout devel" + exit 1 +fi + +# Make sure that the user is on the HEAD of the devel branch +local_hash=`git rev-parse devel` +remote_hash=`git rev-parse origin/devel` + +if [ "$local_hash" != "$remote_hash" ] ; then + echo "ERROR: You're local devel branch is not up-to-date with the remote!!!" + echo "Try: git pull" + exit 1 +fi + +# Make sure that the user does not have any uncommitted changes +modfied=`git status | grep modified` + +if [ ! -z "${modified// }" ] ; then + echo "ERROR: You have uncommitted changes in your local repository!!!" + echo "You can only run this script on a clean devel branch" + exit 1 +fi + +# Pull in the latest HEAD for all submodules that track a branch +git submodule update --remote + +# Only add and commit if something actually changed +modfied=`git status | grep modified` + +if [ ! -z "${modified// }" ] ; then + git add -u + git commit -m "Updating submodules [update-submodules script]" + git push +else + echo "Everything up-to-date" +fi