fix: slashes in branch names not supported

added support for slashes in branch names
main
Andre Challier 2025-12-11 13:22:54 +01:00
parent f6cac641d6
commit 6944591557
3 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -21,7 +21,8 @@ EOF
# Loop through folders in ./branches/
for branch_folder in "$BRANCHES_DIR"/*; do
branch_name=$(basename "$branch_folder")
echo " <li><a href=\"branches/$branch_name/index.html\">$branch_name</a></li>"
display_name="${branch_name//-/\/}"
echo " <li><a href=\"branches/$branch_name/index.html\">$display_name</a></li>"
done
cat <<EOF