From 07c2da3863de8ad27f76456c4845d08c12a30539 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Wed, 7 Jun 2023 16:00:22 +0300 Subject: [PATCH 1/9] support Git Clone depth with different branches --- service.yaml | 2 +- start.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/service.yaml b/service.yaml index e7bf1a0..9bd68bc 100644 --- a/service.yaml +++ b/service.yaml @@ -1 +1 @@ -version: 10.1.19 +version: 10.1.20 diff --git a/start.sh b/start.sh index 9941ecf..74e0b5a 100644 --- a/start.sh +++ b/start.sh @@ -196,6 +196,10 @@ if [ -d "$CLONE_DIR" ]; then 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 @@ -204,7 +208,12 @@ 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 From 9c700062f0a31d5ad00bb6496dc3522f5a9b3c9d Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Thu, 8 Jun 2023 10:50:37 +0300 Subject: [PATCH 2/9] add logs --- start.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 74e0b5a..2aead6b 100644 --- a/start.sh +++ b/start.sh @@ -194,11 +194,15 @@ if [ -d "$CLONE_DIR" ]; then rm -rf $CLONE_DIR eval $GIT_COMMAND cd $CLONE_DIR - + echo 'cloned successfully' if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then + echo 'git remote set-branches origin '*' - before' git_retry git remote set-branches origin '*' + echo 'git remote set-branches origin '*' - after' + echo 'git fetch --depth=$DEPTH' git_retry git fetch --depth=$DEPTH + echo 'git fetch --depth=$DEPTH - after' fi git_checkout fi @@ -208,11 +212,15 @@ else # Clone a fresh copy eval $GIT_COMMAND cd $CLONE_DIR - + echo 'cloned successfully' if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then + echo 'git remote set-branches origin '*' - before' git_retry git remote set-branches origin '*' + echo 'git remote set-branches origin '*' - after' + echo 'git fetch --depth=$DEPTH' git_retry git fetch --depth=$DEPTH + echo 'git fetch --depth=$DEPTH - after' fi git_checkout fi From c13e8617bff957aabec3b8d03f3911602c533fc0 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Thu, 8 Jun 2023 13:55:04 +0300 Subject: [PATCH 3/9] add logs --- start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/start.sh b/start.sh index 2aead6b..acfd3db 100644 --- a/start.sh +++ b/start.sh @@ -194,7 +194,7 @@ if [ -d "$CLONE_DIR" ]; then rm -rf $CLONE_DIR eval $GIT_COMMAND cd $CLONE_DIR - echo 'cloned successfully' + echo "The folder already exists but it is not a git repository - cloned successfully into $CLONE_DIR" if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then echo 'git remote set-branches origin '*' - before' @@ -212,13 +212,13 @@ else # Clone a fresh copy eval $GIT_COMMAND cd $CLONE_DIR - echo 'cloned successfully' + echo "cloned successfully into $CLONE_DIR" if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then echo 'git remote set-branches origin '*' - before' git_retry git remote set-branches origin '*' echo 'git remote set-branches origin '*' - after' - echo 'git fetch --depth=$DEPTH' + echo "git fetch --depth=$DEPTH" git_retry git fetch --depth=$DEPTH echo 'git fetch --depth=$DEPTH - after' fi From 43c5eb629da365e09ee36872c587cb53f97ab335 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 10 Jun 2023 04:11:28 +0300 Subject: [PATCH 4/9] remove logs --- start.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/start.sh b/start.sh index acfd3db..e8d4fcd 100644 --- a/start.sh +++ b/start.sh @@ -194,15 +194,11 @@ if [ -d "$CLONE_DIR" ]; then rm -rf $CLONE_DIR eval $GIT_COMMAND cd $CLONE_DIR - echo "The folder already exists but it is not a git repository - cloned successfully into $CLONE_DIR" + if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then - echo 'git remote set-branches origin '*' - before' git_retry git remote set-branches origin '*' - echo 'git remote set-branches origin '*' - after' - echo 'git fetch --depth=$DEPTH' git_retry git fetch --depth=$DEPTH - echo 'git fetch --depth=$DEPTH - after' fi git_checkout fi @@ -215,12 +211,8 @@ else echo "cloned successfully into $CLONE_DIR" if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then - echo 'git remote set-branches origin '*' - before' - git_retry git remote set-branches origin '*' - echo 'git remote set-branches origin '*' - after' - echo "git fetch --depth=$DEPTH" - git_retry git fetch --depth=$DEPTH - echo 'git fetch --depth=$DEPTH - after' + git remote set-branches origin '*' + git fetch --depth=$DEPTH fi git_checkout fi From ec173afac5cd6e45b87696fff28a0ba4bd9c5667 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 10 Jun 2023 04:41:17 +0300 Subject: [PATCH 5/9] fix git_retry to handel quotes --- start.sh | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/start.sh b/start.sh index e8d4fcd..f6c9fb8 100644 --- a/start.sh +++ b/start.sh @@ -20,28 +20,28 @@ retry_script () { $0 $@ } -git_retry () { -# Retry git on exit code 128 -( - set +e - RETRY_ON_SIGNAL=128 - COMMAND=$@ - local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 - until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do - $COMMAND - EXIT_CODE=$? - if [[ $EXIT_CODE == 0 ]]; then - break - elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then - echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM " - TRY_NUM=$(( ${TRY_NUM} + 1 )) - sleep $RETRY_WAIT - else - break - fi - done - return $EXIT_CODE - ) +git_retry() { + # Retry git on exit code 128 + ( + set +e + RETRY_ON_SIGNAL=128 + COMMAND=("$@") # Store the command and arguments as an array + local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 + until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do + "${COMMAND[@]}" # Use "${COMMAND[@]}" to preserve arguments with quotes + EXIT_CODE=$? + if [[ $EXIT_CODE == 0 ]]; then + break + elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then + echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM" + TRY_NUM=$((TRY_NUM + 1)) + sleep $RETRY_WAIT + else + break + fi + done + return $EXIT_CODE + ) } upsert_remote_alias () { @@ -211,8 +211,8 @@ else echo "cloned successfully into $CLONE_DIR" if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then - git remote set-branches origin '*' - git fetch --depth=$DEPTH + git_retry git remote set-branches origin "*" + git_retry git fetch --depth=$DEPTH fi git_checkout fi From 227c780d229614c7fa2babbd681c404ccb4d0c0e Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 10 Jun 2023 04:42:02 +0300 Subject: [PATCH 6/9] lint --- start.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/start.sh b/start.sh index f6c9fb8..46c795c 100644 --- a/start.sh +++ b/start.sh @@ -22,26 +22,26 @@ retry_script () { git_retry() { # Retry git on exit code 128 - ( - set +e - RETRY_ON_SIGNAL=128 - COMMAND=("$@") # Store the command and arguments as an array - local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 - until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do - "${COMMAND[@]}" # Use "${COMMAND[@]}" to preserve arguments with quotes - EXIT_CODE=$? - if [[ $EXIT_CODE == 0 ]]; then - break - elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then - echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM" - TRY_NUM=$((TRY_NUM + 1)) - sleep $RETRY_WAIT - else - break - fi - done - return $EXIT_CODE - ) +( + set +e + RETRY_ON_SIGNAL=128 + COMMAND=("$@") # Store the command and arguments as an array + local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 + until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do + "${COMMAND[@]}" # Use "${COMMAND[@]}" to preserve arguments with quotes + EXIT_CODE=$? + if [[ $EXIT_CODE == 0 ]]; then + break + elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then + echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM" + TRY_NUM=$((TRY_NUM + 1)) + sleep $RETRY_WAIT + else + break + fi + done + return $EXIT_CODE +) } upsert_remote_alias () { From 0fbf5a3d50b1a989943beba2aaf69fd475ff8aae Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 10 Jun 2023 04:42:14 +0300 Subject: [PATCH 7/9] lint --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 46c795c..2232a4a 100644 --- a/start.sh +++ b/start.sh @@ -21,7 +21,7 @@ retry_script () { } git_retry() { - # Retry git on exit code 128 +# Retry git on exit code 128 ( set +e RETRY_ON_SIGNAL=128 From 085625f51e2e6625cdef3f5bbe90ea6569f76772 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sat, 10 Jun 2023 04:45:50 +0300 Subject: [PATCH 8/9] lint --- start.sh | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/start.sh b/start.sh index 2232a4a..d639790 100644 --- a/start.sh +++ b/start.sh @@ -20,28 +20,28 @@ retry_script () { $0 $@ } -git_retry() { +git_retry () { # Retry git on exit code 128 ( - set +e - RETRY_ON_SIGNAL=128 - COMMAND=("$@") # Store the command and arguments as an array - local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 - until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do - "${COMMAND[@]}" # Use "${COMMAND[@]}" to preserve arguments with quotes - EXIT_CODE=$? - if [[ $EXIT_CODE == 0 ]]; then - break - elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then - echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM" - TRY_NUM=$((TRY_NUM + 1)) - sleep $RETRY_WAIT - else - break - fi - done - return $EXIT_CODE -) + set +e + RETRY_ON_SIGNAL=128 + COMMAND=("$@") # Store the command and arguments as an array + local TRY_NUM=1 MAX_TRIES=4 RETRY_WAIT=5 + until [[ "$TRY_NUM" -ge "$MAX_TRIES" ]]; do + "${COMMAND[@]}" # Use "${COMMAND[@]}" to preserve arguments with quotes + EXIT_CODE=$? + if [[ $EXIT_CODE == 0 ]]; then + break + elif [[ $EXIT_CODE == "$RETRY_ON_SIGNAL" ]]; then + echo "Failed with Exit Code $EXIT_CODE - try $TRY_NUM " + TRY_NUM=$(( ${TRY_NUM} + 1 )) + sleep $RETRY_WAIT + else + break + fi + done + return $EXIT_CODE + ) } upsert_remote_alias () { @@ -208,7 +208,6 @@ else # Clone a fresh copy eval $GIT_COMMAND cd $CLONE_DIR - echo "cloned successfully into $CLONE_DIR" if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then git_retry git remote set-branches origin "*" From aa5f83ef2c55b16a41193778464a6af7f89a09c8 Mon Sep 17 00:00:00 2001 From: eti-codefresh Date: Sun, 11 Jun 2023 16:22:36 +0300 Subject: [PATCH 9/9] lint --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index d639790..91d5a20 100644 --- a/start.sh +++ b/start.sh @@ -197,7 +197,7 @@ if [ -d "$CLONE_DIR" ]; then if [ -n "$REVISION" ]; then if [ -n "$DEPTH" ]; then - git_retry git remote set-branches origin '*' + git_retry git remote set-branches origin "*" git_retry git fetch --depth=$DEPTH fi git_checkout