diff --git a/service.yaml b/service.yaml index e177dcf..f147b01 100644 --- a/service.yaml +++ b/service.yaml @@ -1 +1 @@ -version: 10.1.14 +version: 10.1.15 diff --git a/start.sh b/start.sh index 3a65ba1..8608737 100644 --- a/start.sh +++ b/start.sh @@ -2,9 +2,22 @@ exit_trap () { local lc="$BASH_COMMAND" rc=$? - if [ $rc != 0 ]; then - echo "Command [$lc] exited with code [$rc]" + if [ "$rc" = 0 ]; then + return fi + if [ "$CLEAN_GIT_LOCK_FILES" = "true" ] && [ "$IS_RETRY" != "true" ]; then + retry_script + exit $? + fi + echo "Command [$lc] exited with code [$rc]" +} + +retry_script () { + echo "Retrying git clone operation..." + cd ../ + rm -rf $CLONE_DIR + export IS_RETRY=true + ./$0 $@ } git_retry () { @@ -31,10 +44,24 @@ git_retry () { ) } +upsert_remote_alias () { + remoteAlias=$1 + remoteUrl=$2 + isOriginAliasExisted=$(git remote -v | awk '$1 ~ /^'$remoteAlias'$/{print $1; exit}') + if [ "$isOriginAliasExisted" = "$remoteAlias" ]; then + git remote set-url $remoteAlias $remoteUrl + else + git remote add $remoteAlias $remoteUrl + fi +} + +delete_process_lock_files () { + find ./.git -type f -iname '*.lock' -delete +} + trap exit_trap EXIT set -e - [ -z "$REVISION" ] && (echo "missing REVISION var" | tee /dev/stderr) && exit 1 @@ -107,8 +134,11 @@ if [ -d "$CLONE_DIR" ]; then # Make sure the CLONE_DIR folder is a git folder if git status &> /dev/null ; then + if [ "$CLEAN_GIT_LOCK_FILES" = "true" ]; then + delete_process_lock_files + fi # Reset the remote URL because the embedded user token may have changed - git remote set-url origin $REPO + upsert_remote_alias origin $REPO echo "Cleaning up the working directory" git reset -q --hard