update submodules only in intervall not every init

MYSHELLCONFIG_GIT_SUBMODULES_INTERVALL=<time in hours>
This commit is contained in:
Jakobus Schürz 2020-10-30 13:53:34 +01:00
parent 235008768f
commit 4151446013
2 changed files with 35 additions and 28 deletions

View file

@ -40,6 +40,7 @@ if [[ $- = *i* ]] ; then
[ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && export MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s [ -z "${MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT+x}" ] && export MYSHELLCONFIG_GIT_CHECKOUT_TIMEOUT=20s
[ -z "${MYSHELLCONFIG_GIT_SYNC+x}" ] && export MYSHELLCONFIG_GIT_SYNC=true [ -z "${MYSHELLCONFIG_GIT_SYNC+x}" ] && export MYSHELLCONFIG_GIT_SYNC=true
[ -z "${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT+x}" ] && export MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT=true [ -z "${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT+x}" ] && export MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT=true
[ -z "${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_INTERVALL+x}" ] && export MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_INTERVALL=2 #intervall in hours
[ -z "${MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT+x}" ] && export MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT="git://git.schuerz.at/github.com/" [ -z "${MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT+x}" ] && export MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT="git://git.schuerz.at/github.com/"
# hardcoded git # hardcoded git
export SGIT="git -C ${MYSHELLCONFIG_BASE}" export SGIT="git -C ${MYSHELLCONFIG_BASE}"

View file

@ -84,35 +84,41 @@ fi
loginfo -n "repo synced" loginfo -n "repo synced"
if ${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE-${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT-true}}; then if ${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE-${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_DEFAULT-true}}; then
logdebug "update submodules" updated=$(cat ${MYSHELLCONFIG_BASE%/}${MYSHELLCONFIG_BASE:+/}.last_udate_submodules 2>/dev/null || echo 0 )
rc=0 if [ $updated -lt $(date --date="${MYSHELLCONFIG_GIT_SUBMODULES_UPDATE_INTERVALL} hours ago" "+%s") ]; then
# srv="${MYSHELLCONFIG_GIT_SUBMODULES_SERVER-${MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT}}" logdebug "update submodules"
# logwarn "srv $srv" rc=0
# $SGIT config --file=.gitmodules -l | \ # srv="${MYSHELLCONFIG_GIT_SUBMODULES_SERVER-${MYSHELLCONFIG_GIT_SUBMODULES_SERVER_DEFAULT}}"
# grep url= | \ # logwarn "srv $srv"
# awk -F "=" -v srv="${srv%/}${srv:+/}" \ # $SGIT config --file=.gitmodules -l | \
# '{gsub(/^.*github.com\//,srv,$2); print $1" "$2}' | \ # grep url= | \
# while read a b; do # awk -F "=" -v srv="${srv%/}${srv:+/}" \
# logdebug "$SGIT config --file=.gitmodules ${a} ${b}" # '{gsub(/^.*github.com\//,srv,$2); print $1" "$2}' | \
# $SGIT config --file=.gitmodules "${a}" "${b}" # while read a b; do
# done # logdebug "$SGIT config --file=.gitmodules ${a} ${b}"
# $SGIT config --file=.gitmodules "${a}" "${b}"
# done
# Submodules always have origin and master as repo and branch to track # Submodules always have origin and master as repo and branch to track
#$SGIT submodule init 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { logwarn "update submodules failed on ini"; rc=5; } #$SGIT submodule init 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { logwarn "update submodules failed on ini"; rc=5; }
#$SGIT submodule foreach "git checkout master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn "checkout master submodules failed on set upstream"; rc=7; } #$SGIT submodule foreach "git checkout master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn "checkout master submodules failed on set upstream"; rc=7; }
#$SGIT submodule foreach "git branch -u origin/master master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { logwarn "set-upstream submodules failed on set upstream"; rc=8; } #$SGIT submodule foreach "git branch -u origin/master master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { logwarn "set-upstream submodules failed on set upstream"; rc=8; }
#$SGIT submodule update --init --recursive --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn " update submodules failed on update"; rc=9; } #$SGIT submodule update --init --recursive --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn " update submodules failed on update"; rc=9; }
# run git submodule sync only ich local repo should use submodule urls from main-project # run git submodule sync only ich local repo should use submodule urls from main-project
# so don't use it here # so don't use it here
# logdebug "$($SGIT submodule sync)" || { logwarn "sync submodules failed on sync"; rc=6; } # logdebug "$($SGIT submodule sync)" || { logwarn "sync submodules failed on sync"; rc=6; }
logdebug "$($SGIT submodule update --remote)" logdebug "$($SGIT submodule update --remote)"
logdebug "$($SGIT submodule update --init --recursive)" logdebug "$($SGIT submodule update --init --recursive)"
logdebug "$($SGIT commit .gitmodules -m 'update submodules')" logdebug "$($SGIT commit .gitmodules -m 'update submodules')"
#$SGIT submodule update --init --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn " update submodules failed on update"; rc=9; } #$SGIT submodule update --init --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1 || { logwarn " update submodules failed on update"; rc=9; }
#$SGIT checkout .gitmodules #$SGIT checkout .gitmodules
logdebug "submodules updated successfully" logdebug "submodules updated successfully"
loginfo -n ", submodules synced" loginfo -n ", submodules synced"
date "+%s" > ${MYSHELLCONFIG_BASE%/}${MYSHELLCONFIG_BASE:+/}.last_udate_submodules
else
logdebug "submodules not updated. last update is less then ${MYSHELLCONFIG_GIT_SUBMODULE_UPDATE_INTERVALL} hours ago"
fi
else else
loginfo -n ", submodules not synced" loginfo -n ", submodules not synced"