summaryrefslogtreecommitdiffstats
path: root/update_all_submodules
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2016-03-16 03:23:13 +0100
committerSlávek Banko <slavek.banko@axis.cz>2016-03-16 03:23:54 +0100
commit8f6eb245416c3613c8f34c565cc329978440292f (patch)
tree4796067d67d22a1d8a0da407cdb00f4d029c2647 /update_all_submodules
parent7742941f74f644567a812c25cba7a5e94cb16b25 (diff)
downloadscripts-8f6eb245416c3613c8f34c565cc329978440292f.tar.gz
scripts-8f6eb245416c3613c8f34c565cc329978440292f.zip
Revamp update_all_submodules
+ submodules file is no longer needed + list of submodules is loaded from .gitmodules + order of the submodules is determined by .gitmodules + nested submodules are processed recursively by .gitmodules + all submodules, including nested, are updated in one cycle Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 9f54f5880931758748347f73ddd146ae13b7b6b6)
Diffstat (limited to 'update_all_submodules')
-rwxr-xr-xupdate_all_submodules124
1 files changed, 79 insertions, 45 deletions
diff --git a/update_all_submodules b/update_all_submodules
index 563b3bd..b70bb97 100755
--- a/update_all_submodules
+++ b/update_all_submodules
@@ -6,7 +6,7 @@ if [[ -e /var/lock/update-tde-git-submodules ]]; then
exit 0
fi
-if [[ ! -e .git ]] ||
+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
@@ -19,57 +19,91 @@ if [[ -z "$branch" ]] ||
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
-touch /var/lock/update-tde-git-submodules
+# echo in bold
+echobd () {
+ if [ -p /dev/stdout ]; then
+ echo "$1"
+ else
+ echo -ne "\033[1m"
+ echo -n "$1"
+ echo -e "\033[0m"
+ fi
+}
-PARENTDIR=$PWD
-echo "Working in $PARENTDIR"
-git pull
-if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
- git reset --hard HEAD
- git clean -dxff
-fi
+# commmit changed module
+commitModule() {
+ if [[ "$1" == "" ]]; then
+ return
+ fi
+ local MODULE=$1
-exec 3< submodules
-while read <&3
-do
- cd $PARENTDIR
- DIR2UPDATE=$REPLY
- if [[ $DIR2UPDATE != "" ]]; then
- echo "Attempting to reset submodule $DIR2UPDATE"
- cd $PARENTDIR/$DIR2UPDATE/..
- cd `git rev-parse --show-toplevel`
- if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
- echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
- git submodule init
- git submodule update
- fi
- cd $PARENTDIR/$DIR2UPDATE
- if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
- 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>&-
+ 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
+}
-# Let the disk subsystem recover
-sleep 60
+# 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