Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch depth with sha #70

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion service.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: 10.1.24
version: 10.1.25
54 changes: 26 additions & 28 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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