Skip to content

Commit

Permalink
Adding some utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxfan committed Oct 8, 2018
1 parent a04ecb7 commit 1461a74
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions utils/update-submodules
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1461a74

Please sign in to comment.