From 0f331692ae6f5d652d7761ab2169ffb0d12a9ab6 Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sat, 28 Mar 2026 11:50:49 +0100 Subject: [PATCH] create setup_git script --- docker/php/scripts/setup_git.sh | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/php/scripts/setup_git.sh diff --git a/docker/php/scripts/setup_git.sh b/docker/php/scripts/setup_git.sh new file mode 100644 index 0000000..4a2c9a1 --- /dev/null +++ b/docker/php/scripts/setup_git.sh @@ -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" +}