37 lines
947 B
Bash
Executable File
37 lines
947 B
Bash
Executable File
#!/bin/sh
|
|
|
|
setup_git() {
|
|
echo "Setting up Git..."
|
|
|
|
GIT_URL="https://oauth2:${GIT_TOKEN}@${BACKEND_GIT_REPO}"
|
|
BRANCH="${BACKEND_GIT_BRANCH:-main}"
|
|
FORCE_CLONE="${FORCE_CLONE:-false}"
|
|
|
|
git config --global --add safe.directory "$APP_DIR"
|
|
|
|
if [ ! -d "$APP_DIR/.git" ]; then
|
|
echo "Cloning repo..."
|
|
git clone -b "$BRANCH" "$GIT_URL" "$APP_DIR"
|
|
else
|
|
echo "Updating repo..."
|
|
cd "$APP_DIR"
|
|
CURRENT_BRANCH=$(run git rev-parse --abbrev-ref HEAD)
|
|
|
|
if [ "$CURRENT_BRANCH" = "$BRANCH" ]; then
|
|
run git fetch origin
|
|
run git reset --hard origin/"$CURRENT_BRANCH"
|
|
else
|
|
if [ "$FORCE_CLONE" = "true" ]; then
|
|
rm -rf "$APP_DIR"
|
|
mkdir -p "$APP_DIR"
|
|
git clone -b "$BRANCH" "$GIT_URL" "$APP_DIR"
|
|
else
|
|
run git fetch origin
|
|
run git reset --hard origin/"$BRANCH"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
cd "$APP_DIR"
|
|
}
|