From d9da3d1182bfe8484776548db3645147b906ad39 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 08:48:58 +0200 Subject: [PATCH 01/11] test 1 approuch to fetch with sha --- start.sh | 75 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/start.sh b/start.sh index 9a20c15..fb3e9f0 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 +} + +git_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 @@ -174,6 +190,14 @@ else GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR" fi +if [ -n "$FETCH" ]; then + if [ -n "$DEPTH" ]; then + GIT_FETCH_COMMAND = "git_retry fetch --depth=$DEPTH origin $REVISION" + else + GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" + fi +fi + # Check if the cloned dir already exists from previous builds if [ -d "$CLONE_DIR" ]; then @@ -215,31 +239,40 @@ if [ -d "$CLONE_DIR" ]; then 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 + if [ -n "$FETCH" ]; then + git_init_and_fetch + else + # 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 fi 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 + if [ -n "$FETCH" ]; then + mkdir $CLONE_DIR + cd $CLONE_DIR + git_init_and_fetch + else + 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 fi - fi From 40df70d39f6621a7b15969125849be93babee620 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 09:07:57 +0200 Subject: [PATCH 02/11] bump --- service.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2ba4d41fb7817dde830577d12e9553974cced6f8 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 11:24:44 +0200 Subject: [PATCH 03/11] [fix GIT_FETCH_COMMAND --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index fb3e9f0..8b09c7d 100644 --- a/start.sh +++ b/start.sh @@ -192,7 +192,7 @@ fi if [ -n "$FETCH" ]; then if [ -n "$DEPTH" ]; then - GIT_FETCH_COMMAND = "git_retry fetch --depth=$DEPTH origin $REVISION" + GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" --depth=$DEPTH else GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" fi From 6740f17c87480c720467cfab2478a8d295010201 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 11:40:30 +0200 Subject: [PATCH 04/11] add logs --- start.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/start.sh b/start.sh index 8b09c7d..e84b7f9 100644 --- a/start.sh +++ b/start.sh @@ -240,16 +240,19 @@ if [ -d "$CLONE_DIR" ]; then else # The folder already exists but it is not a git repository if [ -n "$FETCH" ]; then + echo 'Fetching updates according to revision' git_init_and_fetch else # Clean folder and clone a fresh copy on current directory cd .. rm -rf $CLONE_DIR + echo 'cloning repository' eval $GIT_COMMAND cd $CLONE_DIR if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then + echo 'Shallow fetch' git_retry git remote set-branches origin "*" git_retry git fetch --depth=$DEPTH fi @@ -261,14 +264,17 @@ else # Clone a fresh copy if [ -n "$FETCH" ]; then + echo 'Fetching updates according to revision from fresh copy' mkdir $CLONE_DIR cd $CLONE_DIR git_init_and_fetch else + echo 'cloning repository from fresh copy' eval $GIT_COMMAND cd $CLONE_DIR if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then + echo 'Shallow fetch' git_retry git remote set-branches origin "*" git_retry git fetch --depth=$DEPTH fi From 67fe87b18c8de74da96b9ff3af6d0ae45987ab3c Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 12:00:49 +0200 Subject: [PATCH 05/11] fix GIT_FETCH_COMMAND --- start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/start.sh b/start.sh index e84b7f9..7a7bb21 100644 --- a/start.sh +++ b/start.sh @@ -185,7 +185,7 @@ if [ -n "$SPARE_CHECKOUT" ]; then fi if [ -n "$DEPTH" ]; then - GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR --depth=$DEPTH" + GIT_COMMAND="git_retry git clone --depth=$DEPTH" $REPO $CLONE_DIR else GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR" fi @@ -263,6 +263,7 @@ if [ -d "$CLONE_DIR" ]; then else # Clone a fresh copy + if [ -n "$FETCH" ]; then echo 'Fetching updates according to revision from fresh copy' mkdir $CLONE_DIR From 79cb352b5da3e9aed5c6d3d326c5265f335c993a Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 12:01:24 +0200 Subject: [PATCH 06/11] fix GIT_FETCH_COMMAND --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 7a7bb21..81687f2 100644 --- a/start.sh +++ b/start.sh @@ -185,14 +185,14 @@ if [ -n "$SPARE_CHECKOUT" ]; then fi if [ -n "$DEPTH" ]; then - GIT_COMMAND="git_retry git clone --depth=$DEPTH" $REPO $CLONE_DIR + GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR --depth=$DEPTH" else GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR" fi if [ -n "$FETCH" ]; then if [ -n "$DEPTH" ]; then - GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" --depth=$DEPTH + GIT_FETCH_COMMAND = "git_retry fetch--depth=$DEPTH origin $REVISION" else GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" fi From 19d76572360405debd45a5b12cf1f5ac0878aaaa Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 12:08:57 +0200 Subject: [PATCH 07/11] fix GIT_FETCH_COMMAND --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 81687f2..5279578 100644 --- a/start.sh +++ b/start.sh @@ -192,9 +192,9 @@ fi if [ -n "$FETCH" ]; then if [ -n "$DEPTH" ]; then - GIT_FETCH_COMMAND = "git_retry fetch--depth=$DEPTH origin $REVISION" + GIT_FETCH_COMMAND = "git_retry git fetch --depth=$DEPTH origin $REVISION" else - GIT_FETCH_COMMAND = "git_retry fetch origin $REVISION" + GIT_FETCH_COMMAND = "git_retry git fetch origin $REVISION" fi fi From a46273e31a6e23ec114500c993b80a646d80fbb1 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 12:16:30 +0200 Subject: [PATCH 08/11] fix GIT_FETCH_COMMAND --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 5279578..83cc935 100644 --- a/start.sh +++ b/start.sh @@ -192,9 +192,9 @@ fi if [ -n "$FETCH" ]; then if [ -n "$DEPTH" ]; then - GIT_FETCH_COMMAND = "git_retry git fetch --depth=$DEPTH origin $REVISION" + GIT_FETCH_COMMAND="git_retry git fetch --depth=$DEPTH origin $REVISION" else - GIT_FETCH_COMMAND = "git_retry git fetch origin $REVISION" + GIT_FETCH_COMMAND="git_retry git fetch origin $REVISION" fi fi From d0f25f61e394fac60c3ca875a057518a238bee96 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 14:32:35 +0200 Subject: [PATCH 09/11] init and add remote instead of clone --- start.sh | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/start.sh b/start.sh index 83cc935..31662d9 100644 --- a/start.sh +++ b/start.sh @@ -81,7 +81,7 @@ init_and_add_remote() { git_retry git remote add origin $REPO } -git_init_and_fetch() { +init_and_fetch() { init_and_add_remote if [ -n "$REVISION" ]; then @@ -238,48 +238,14 @@ if [ -d "$CLONE_DIR" ]; then fi fi else - # The folder already exists but it is not a git repository - if [ -n "$FETCH" ]; then - echo 'Fetching updates according to revision' - git_init_and_fetch - else - # Clean folder and clone a fresh copy on current directory - cd .. - rm -rf $CLONE_DIR - echo 'cloning repository' - eval $GIT_COMMAND - cd $CLONE_DIR - - if [ -n "$REVISION" ]; then - if [ -n "$DEPTH" ]; then - echo 'Shallow fetch' - git_retry git remote set-branches origin "*" - git_retry git fetch --depth=$DEPTH - fi - git_checkout - fi - 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 - - if [ -n "$FETCH" ]; then + # Fresh fetch echo 'Fetching updates according to revision from fresh copy' mkdir $CLONE_DIR cd $CLONE_DIR - git_init_and_fetch - else - echo 'cloning repository from fresh copy' - eval $GIT_COMMAND - cd $CLONE_DIR - if [ -n "$REVISION" ]; then - if [ -n "$DEPTH" ]; then - echo 'Shallow fetch' - git_retry git remote set-branches origin "*" - git_retry git fetch --depth=$DEPTH - fi - git_checkout - fi - fi + init_and_fetch fi From a05d2e1292fb200c8c57e033995d0ec1e16e41a3 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 15:33:55 +0200 Subject: [PATCH 10/11] remove redundent code --- start.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/start.sh b/start.sh index 31662d9..7c6471d 100644 --- a/start.sh +++ b/start.sh @@ -184,12 +184,6 @@ if [ -n "$SPARE_CHECKOUT" ]; then exit 0 fi -if [ -n "$DEPTH" ]; then - GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR --depth=$DEPTH" -else - GIT_COMMAND="git_retry git clone $REPO $CLONE_DIR" -fi - if [ -n "$FETCH" ]; then if [ -n "$DEPTH" ]; then GIT_FETCH_COMMAND="git_retry git fetch --depth=$DEPTH origin $REVISION" From ca1960856aef231a15212f360aa090b4b628e1bf Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 25 Dec 2023 16:13:20 +0200 Subject: [PATCH 11/11] remove fetch flag --- start.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/start.sh b/start.sh index 7c6471d..08026ed 100644 --- a/start.sh +++ b/start.sh @@ -184,12 +184,10 @@ if [ -n "$SPARE_CHECKOUT" ]; then exit 0 fi -if [ -n "$FETCH" ]; then - if [ -n "$DEPTH" ]; then - GIT_FETCH_COMMAND="git_retry git fetch --depth=$DEPTH origin $REVISION" - else - GIT_FETCH_COMMAND="git_retry git fetch origin $REVISION" - fi +if [ -n "$DEPTH" ]; then + GIT_FETCH_COMMAND="git_retry git fetch --depth=$DEPTH origin $REVISION" +else + GIT_FETCH_COMMAND="git_retry git fetch origin $REVISION" fi # Check if the cloned dir already exists from previous builds