From 6944591557afbaebbf5fba465da034bb720a2009 Mon Sep 17 00:00:00 2001 From: Andre Challier Date: Thu, 11 Dec 2025 13:22:54 +0100 Subject: [PATCH] fix: slashes in branch names not supported added support for slashes in branch names --- webhooks-git/dadi-staging-hook.sh | 10 ++++++---- webhooks-git/dadi-staging-init.sh | 6 +++--- webhooks-git/generate_index_html.sh | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/webhooks-git/dadi-staging-hook.sh b/webhooks-git/dadi-staging-hook.sh index 66b680c..a4a581a 100644 --- a/webhooks-git/dadi-staging-hook.sh +++ b/webhooks-git/dadi-staging-hook.sh @@ -7,7 +7,7 @@ if [ "$#" -ne 2 ]; then fi repository_name="$1" -branch_name=$(basename "$2") +branch_name="${2#refs/heads}" BRANCHES_FOLDER="/html/branches" DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" @@ -16,18 +16,20 @@ DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" echo "Webhook recieved for repository: $repository_name and branch: $branch_name" # Check if the branch directory exists -branch_dir="$BRANCHES_FOLDER/$(basename "$branch_name")" +safe_branch_name="${branch_name//\//-}" +branch_dir="$BRANCHES_FOLDER/$safe_branch_name" + if [ -d "$branch_dir" ]; then echo "Directory $branch_dir exists, performing git pull..." # Change directory to branch directory cd "$branch_dir" # Perform git pull echo "Updating $branch_dir" - git pull origin "$(basename "$branch_name")" + git pull origin "$branch_name" else echo "Directory $branch_dir does not exist, cloning branch..." # Create branches directory if it doesn't exist - mkdir -p branches + mkdir -p "$BRANCHES_FOLDER" # Clone the branch git clone --depth 1 --branch "$branch_name" --single-branch "$DADI_STAGING_REPOSITORY" "$branch_dir" # reinitialize index.html diff --git a/webhooks-git/dadi-staging-init.sh b/webhooks-git/dadi-staging-init.sh index 765755e..fcfaaab 100644 --- a/webhooks-git/dadi-staging-init.sh +++ b/webhooks-git/dadi-staging-init.sh @@ -16,7 +16,6 @@ DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git" for dir in "$BRANCHES_FOLDER"/*/; do dir_name=$(basename "$dir") - echo "Deleting directory: $dir" rm -rf "$dir" done @@ -34,6 +33,7 @@ while read -r ref; do 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" + safe_branch_name="${branch//\//-}" + echo "cloning $branch into $safe_branch_name" + git clone --depth 1 --branch "$branch" --single-branch "$DADI_STAGING_REPOSITORY" "$BRANCHES_FOLDER/$safe_branch_name" done diff --git a/webhooks-git/generate_index_html.sh b/webhooks-git/generate_index_html.sh index b4bdcab..7aa1a1a 100644 --- a/webhooks-git/generate_index_html.sh +++ b/webhooks-git/generate_index_html.sh @@ -21,7 +21,8 @@ EOF # Loop through folders in ./branches/ for branch_folder in "$BRANCHES_DIR"/*; do branch_name=$(basename "$branch_folder") - echo "
  • $branch_name
  • " + display_name="${branch_name//-/\/}" + echo "
  • $display_name
  • " done cat <