diff --git a/2 b/2 new file mode 100644 index 0000000..765755e --- /dev/null +++ b/2 @@ -0,0 +1,39 @@ +#!/bin/bash + +# +# Initialize dadi staging folder from repository +# +# - delete existing dadi staging folder +# + +HTML_HOME="/html" +BRANCHES_FOLDER="/html/branches" +DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" + +# +# Remove all branch folders +# + +for dir in "$BRANCHES_FOLDER"/*/; do + dir_name=$(basename "$dir") + + echo "Deleting directory: $dir" + rm -rf "$dir" +done + +# +# Fetch all branch names +# +branches=() +while read -r ref; do + # Extract branch name from the reference + branch_name=$(echo "$ref" | awk '{print $2}' | sed 's/refs\/heads\///') + + # put into array + branches+=("$branch_name") +done < <(git ls-remote --heads "$DADI_STAGING_REPOSITORY") + +for branch in "${branches[@]}"; do + echo "cloning $branch" + git clone --depth 1 --branch "$branch" --single-branch "$DADI_STAGING_REPOSITORY" "$BRANCHES_FOLDER"/"$branch" +done diff --git a/webhooks-git/dadi-staging-init.sh b/webhooks-git/dadi-staging-init.sh index 3c075ba..765755e 100644 --- a/webhooks-git/dadi-staging-init.sh +++ b/webhooks-git/dadi-staging-init.sh @@ -8,7 +8,7 @@ HTML_HOME="/html" BRANCHES_FOLDER="/html/branches" -DADI_STAGING_REPOSITORY="git_dadi_staging:AG-IT/KlDaDiSeite.git" +DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" # # Remove all branch folders