summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2018-07-07 16:12:37 +0200
committerSlávek Banko <slavek.banko@axis.cz>2018-07-07 16:12:37 +0200
commitb0d74087e54845129610e901f5c4a2e662e8c9bd (patch)
treecdca6cd98191e1a0d2ec94602c1a9aedce4d0d9f
parenta4ee97323870ce23c10714233408f36f372b296e (diff)
downloadscripts-b0d74087e54845129610e901f5c4a2e662e8c9bd.tar.gz
scripts-b0d74087e54845129610e901f5c4a2e662e8c9bd.zip
Update update_all_submodules
+ create lock specific by branch + initialize submodules only if they have not yet been initialized + use --no-recurse-submodules at git pull for better overview of the update progress Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
-rwxr-xr-xupdate_all_submodules57
1 files changed, 35 insertions, 22 deletions
diff --git a/update_all_submodules b/update_all_submodules
index b70bb97..776fff8 100755
--- a/update_all_submodules
+++ b/update_all_submodules
@@ -1,11 +1,17 @@
#!/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
+# echo in bold
+echobd () {
+ if [ -p /dev/stdout ]; then
+ echo "$1"
+ else
+ echo -ne "\033[1m"
+ echo -n "$1"
+ echo -e "\033[0m"
+ fi
+}
+# verify git directory and branch
if [[ ! -e .git ]] &&
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
echo "Current directory does not contain a .git folder. Exiting..."
@@ -13,29 +19,25 @@ if [[ ! -e .git ]] &&
fi
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" ]] ||
[[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
echo "There is not active upstream branch. Exiting..."
exit 1
fi
+# get git user
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
-}
+if [[ -n "`git pull --help |grep -- '--\[no-\]recurse-submodules'`" ]]; then
+ GIT_NO_RECURSE_SUBMODULES="--no-recurse-submodules"
+fi
# commmit changed module
commitModule() {
@@ -53,7 +55,7 @@ commitModule() {
fi
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
echo "Push changes for $PWD"
- git pull --rebase
+ git pull --rebase $GIT_NO_RECURSE_SUBMODULES
git push origin HEAD
fi
}
@@ -75,7 +77,7 @@ updateModule() {
if [[ "$1" != "" ]]; then
git checkout $branch
fi
- git pull --rebase
+ git pull --rebase $GIT_NO_RECURSE_SUBMODULES
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
echo "Push changes for $PWD"
git push origin HEAD
@@ -89,8 +91,12 @@ updateModule() {
while read submodule; do
echobd "Attempting to reset submodule ${MODULE}${submodule}"
cd $PARENTDIR/$MODULE
- git submodule init -- $submodule
- git submodule update -- $submodule
+ 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
@@ -100,10 +106,17 @@ updateModule() {
}
# Update from top module
-touch /var/lock/update-tde-git-submodules
+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
+rm /var/lock/update-tde-git-submodules-$branch