You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scripts/update_all_submodules

110 lines
2.9 KiB

#!/bin/bash
if [[ -e /var/lock/update-tde-git-submodules ]]; then
echo "TDE GIT submodules are currently being updated"
echo "If this is not the case, please remove the lockfile /var/lock/update-tde-git-submodules"
exit 0
fi
if [[ ! -e .git ]] &&
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
echo "Current directory does not contain a .git folder. Exiting..."
exit 1
fi
branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
if [[ -z "$branch" ]] ||
[[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
echo "There is not active upstream branch. Exiting..."
exit 1
fi
GITUSER="Automated System <$(git config --get user.email)>"
# check git abilities
if [[ -n "`git status --help 2>/dev/null|grep -- '--ignore-submodules'`" ]]; then
GIT_IGNORE_SUBMODULES="--ignore-submodules"
fi
# echo in bold
echobd () {
if [ -p /dev/stdout ]; then
echo "$1"
else
echo -ne "\033[1m"
echo -n "$1"
echo -e "\033[0m"
fi
}
# commmit changed module
commitModule() {
if [[ "$1" == "" ]]; then
return
fi
local MODULE=$1
cd $PARENTDIR/$MODULE/..
cd `git rev-parse --show-toplevel`
if [[ ! -z "`git status --porcelain $PARENTDIR/$MODULE`" ]]; then
echo "Committing changes to $PWD"
git add $PARENTDIR/$MODULE
git commit $PARENTDIR/$MODULE --author "$GITUSER" -m "Reset submodule $MODULE to latest HEAD"
fi
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
echo "Push changes for $PWD"
git pull --rebase
git push origin HEAD
fi
}
# update module and submodules
updateModule() {
local MODULE
if [[ "$1" != "" ]]; then
MODULE=$1/
else
MODULE=""
fi
cd $PARENTDIR/$MODULE
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
git reset --hard HEAD
git clean -dxff
fi
if [[ "$1" != "" ]]; then
git checkout $branch
fi
git pull --rebase
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
echo "Push changes for $PWD"
git push origin HEAD
fi
if [[ "$1" != "" ]]; then
commitModule $1
fi
if [[ -e $PARENTDIR/$MODULE.gitmodules ]]; then
sed -n "s|^\[submodule \"\([^\"]*\)\"\]$|\1|p" <$PARENTDIR/$MODULE.gitmodules |\
while read submodule; do
echobd "Attempting to reset submodule ${MODULE}${submodule}"
cd $PARENTDIR/$MODULE
git submodule init -- $submodule
git submodule update -- $submodule
updateModule ${MODULE}${submodule}
done
if [[ "$1" != "" ]]; then
commitModule $1
fi
fi
}
# Update from top module
touch /var/lock/update-tde-git-submodules
cd `git rev-parse --show-toplevel`
PARENTDIR=$PWD
echobd "Working in $PARENTDIR"
updateModule
echobd "Done in $PARENTDIR"
rm /var/lock/update-tde-git-submodules