create setup_git script

This commit is contained in:
2026-03-28 11:50:49 +01:00
parent 846398049c
commit 0f331692ae
+36
View File
@@ -0,0 +1,36 @@
#!/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"
}