diff --git a/service.yaml b/service.yaml index dc7f9e6..866591e 100644 --- a/service.yaml +++ b/service.yaml @@ -1 +1 @@ -version: 10.1.24 +version: 10.1.25 diff --git a/start.sh b/start.sh index 9a20c15..08026ed 100644 --- a/start.sh +++ b/start.sh @@ -76,6 +76,22 @@ git_checkout () { git checkout $revision } +init_and_add_remote() { + git_retry git init + git_retry git remote add origin $REPO +} + +init_and_fetch() { + init_and_add_remote + + if [ -n "$REVISION" ]; then + if [ -n "$DEPTH" ]; then + eval $GIT_FETCH_COMMAND + fi + git_checkout + fi +} + trap exit_trap EXIT set -e @@ -169,9 +185,9 @@ if [ -n "$SPARE_CHECKOUT" ]; then fi if [ -n "$DEPTH" ]; then - GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR --depth=$DEPTH" + GIT_FETCH_COMMAND="git_retry git fetch --depth=$DEPTH origin $REVISION" else - GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR" + GIT_FETCH_COMMAND="git_retry git fetch origin $REVISION" fi # Check if the cloned dir already exists from previous builds @@ -214,32 +230,14 @@ if [ -d "$CLONE_DIR" ]; then fi fi else - # The folder already exists but it is not a git repository - # Clean folder and clone a fresh copy on current directory - cd .. - rm -rf $CLONE_DIR - eval $GIT_COMMAND - cd $CLONE_DIR - - if [ -n "$REVISION" ]; then - if [ -n "$DEPTH" ]; then - git_retry git remote set-branches origin "*" - git_retry git fetch --depth=$DEPTH - fi - git_checkout - fi + # The folder already exists but it is not a git repository + echo 'Fetching updates according to revision' + init_and_fetch fi else - - # Clone a fresh copy - eval $GIT_COMMAND - cd $CLONE_DIR - if [ -n "$REVISION" ]; then - if [ -n "$DEPTH" ]; then - git_retry git remote set-branches origin "*" - git_retry git fetch --depth=$DEPTH - fi - git_checkout - fi - + # Fresh fetch + echo 'Fetching updates according to revision from fresh copy' + mkdir $CLONE_DIR + cd $CLONE_DIR + init_and_fetch fi