Compare commits
15 Commits
Author | SHA1 | Date |
---|---|---|
|
9be6e5e6f0 | 7 years ago |
|
c58fea6319 | 7 years ago |
|
d356f38213 | 7 years ago |
|
d46100143d | 7 years ago |
|
c0339738cf | 7 years ago |
|
9982b4a55e | 9 years ago |
|
558e70b263 | 10 years ago |
|
0e9786f3a5 | 10 years ago |
|
2b30dcc138 | 10 years ago |
|
8eb2ea0f54 | 10 years ago |
|
6d53459401 | 10 years ago |
|
5097cbe74c | 10 years ago |
|
4b764e3a1f | 10 years ago |
|
41bd09eab9 | 11 years ago |
|
580cb8e6f8 | 11 years ago |
@ -1,75 +1,122 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ -e /var/lock/update-tde-git-submodules ]]; then
|
# echo in bold
|
||||||
echo "TDE GIT submodules are currently being updated"
|
echobd () {
|
||||||
echo "If this is not the case, please remove the lockfile /var/lock/update-tde-git-submodules"
|
if [ -p /dev/stdout ]; then
|
||||||
exit 0
|
echo "$1"
|
||||||
fi
|
else
|
||||||
|
echo -ne "\033[1m"
|
||||||
|
echo -n "$1"
|
||||||
|
echo -e "\033[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [[ ! -e .git ]] ||
|
# verify git directory and branch
|
||||||
|
if [[ ! -e .git ]] &&
|
||||||
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
|
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
|
||||||
echo "Current directory does not contain a .git folder. Exiting..."
|
echo "Current directory does not contain a .git folder. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
|
branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
|
||||||
|
if [[ -z "$branch" ]]; then
|
||||||
|
branch=`git branch --contains HEAD | egrep -v "no branch|detached" | head -n1 | cut -c 3-`
|
||||||
|
fi
|
||||||
if [[ -z "$branch" ]] ||
|
if [[ -z "$branch" ]] ||
|
||||||
[[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
|
[[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
|
||||||
echo "There is not active upstream branch. Exiting..."
|
echo "There is not active upstream branch. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# get git user
|
||||||
|
GITUSER="Automated System <$(git config --get user.email)>"
|
||||||
|
|
||||||
# check git abilities
|
# check git abilities
|
||||||
if [[ -n "`git status --help 2>/dev/null|grep -- '--ignore-submodules'`" ]]; then
|
if [[ -n "`git status --help 2>/dev/null|grep -- '--ignore-submodules'`" ]]; then
|
||||||
GIT_IGNORE_SUBMODULES="--ignore-submodules"
|
GIT_IGNORE_SUBMODULES="--ignore-submodules"
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "`git pull --help |grep -- '--\[no-\]recurse-submodules'`" ]]; then
|
||||||
|
GIT_NO_RECURSE_SUBMODULES="--no-recurse-submodules"
|
||||||
|
fi
|
||||||
|
|
||||||
touch /var/lock/update-tde-git-submodules
|
# commmit changed module
|
||||||
|
commitModule() {
|
||||||
|
if [[ "$1" == "" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local MODULE=$1
|
||||||
|
|
||||||
PARENTDIR=$PWD
|
cd $PARENTDIR/$MODULE/..
|
||||||
echo "Working in $PARENTDIR"
|
cd `git rev-parse --show-toplevel`
|
||||||
git pull
|
if [[ ! -z "`git status --porcelain $PARENTDIR/$MODULE`" ]]; then
|
||||||
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
|
echo "Committing changes to $PWD"
|
||||||
git reset --hard HEAD
|
git add $PARENTDIR/$MODULE
|
||||||
git clean -dxff
|
git commit $PARENTDIR/$MODULE --author "$GITUSER" -m "Reset submodule $MODULE to latest HEAD"
|
||||||
fi
|
fi
|
||||||
|
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
|
||||||
|
echo "Push changes for $PWD"
|
||||||
|
git pull --rebase $GIT_NO_RECURSE_SUBMODULES
|
||||||
|
git push origin HEAD
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# update module and submodules
|
||||||
|
updateModule() {
|
||||||
|
local MODULE
|
||||||
|
if [[ "$1" != "" ]]; then
|
||||||
|
MODULE=$1/
|
||||||
|
else
|
||||||
|
MODULE=""
|
||||||
|
fi
|
||||||
|
|
||||||
exec 3< submodules
|
cd $PARENTDIR/$MODULE
|
||||||
while read <&3
|
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
|
||||||
do
|
git reset --hard HEAD
|
||||||
cd $PARENTDIR
|
git clean -dxff
|
||||||
DIR2UPDATE=$REPLY
|
fi
|
||||||
if [[ $DIR2UPDATE != "" ]]; then
|
if [[ "$1" != "" ]]; then
|
||||||
echo "Attempting to reset submodule $DIR2UPDATE"
|
git checkout $branch
|
||||||
cd $PARENTDIR/$DIR2UPDATE/..
|
fi
|
||||||
cd `git rev-parse --show-toplevel`
|
git pull --rebase $GIT_NO_RECURSE_SUBMODULES
|
||||||
if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
|
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
|
||||||
echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
|
echo "Push changes for $PWD"
|
||||||
git submodule init
|
git push origin HEAD
|
||||||
git submodule update
|
fi
|
||||||
fi
|
if [[ "$1" != "" ]]; then
|
||||||
cd $PARENTDIR/$DIR2UPDATE
|
commitModule $1
|
||||||
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
|
fi
|
||||||
git reset --hard HEAD
|
|
||||||
git clean -dxff
|
|
||||||
fi
|
|
||||||
git checkout $branch
|
|
||||||
git pull
|
|
||||||
cd ..
|
|
||||||
cd `git rev-parse --show-toplevel`
|
|
||||||
echo "Committing changes to $PWD"
|
|
||||||
if [[ ! -z "`git status --porcelain $PARENTDIR/$DIR2UPDATE`" ]]; then
|
|
||||||
git add $PARENTDIR/$DIR2UPDATE
|
|
||||||
git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
|
|
||||||
fi
|
|
||||||
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
|
|
||||||
git push origin HEAD
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
exec 3>&-
|
|
||||||
|
|
||||||
# Let the disk subsystem recover
|
if [[ -e $PARENTDIR/$MODULE.gitmodules ]]; then
|
||||||
sleep 60
|
sed -n "s|^\[submodule \"\([^\"]*\)\"\]$|\1|p" <$PARENTDIR/$MODULE.gitmodules |\
|
||||||
|
while read submodule; do
|
||||||
|
echobd "Attempting to reset submodule ${MODULE}${submodule}"
|
||||||
|
cd $PARENTDIR/$MODULE
|
||||||
|
if [[ -z "`git config --get submodule.$submodule.url`" ]]; then
|
||||||
|
git submodule init -- $submodule
|
||||||
|
fi
|
||||||
|
if [[ ! -e "$submodule/.git" ]]; then
|
||||||
|
git submodule update -- $submodule
|
||||||
|
fi
|
||||||
|
updateModule ${MODULE}${submodule}
|
||||||
|
done
|
||||||
|
if [[ "$1" != "" ]]; then
|
||||||
|
commitModule $1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
rm /var/lock/update-tde-git-submodules
|
# Update from top module
|
||||||
|
if [[ -e /var/lock/update-tde-git-submodules-$branch ]]; then
|
||||||
|
echo "TDE GIT submodules are currently being updated"
|
||||||
|
echo "If this is not the case, please remove the lockfile"
|
||||||
|
echo "/var/lock/update-tde-git-submodules-$branch"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
touch /var/lock/update-tde-git-submodules-$branch
|
||||||
|
echobd "Updating submodules in $(git rev-parse --show-toplevel | xargs -r basename) $branch branch"
|
||||||
|
cd `git rev-parse --show-toplevel`
|
||||||
|
PARENTDIR=$PWD
|
||||||
|
echobd "Working in $PARENTDIR"
|
||||||
|
updateModule
|
||||||
|
echobd "Done in $PARENTDIR"
|
||||||
|
rm /var/lock/update-tde-git-submodules-$branch
|
||||||
|
Loading…
Reference in New Issue