Merge pull request #3533 from expsa/moutazmuhammad-patch-1
Update clone.sh
This commit is contained in:
commit
b5965c50f0
48
clone.sh
48
clone.sh
|
|
@ -1,14 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Moutaz Muhammad <moutazmuhamad@gmail.com>
|
||||
|
||||
# Git repository URL
|
||||
USERNAME=$1
|
||||
TOKEN=$2
|
||||
REPO_URL="https://github.com/expsa/odex25-standard-modules.git"
|
||||
|
||||
# Argument: which environment to clone (optional)
|
||||
TARGET_ENV=$1
|
||||
|
||||
# Branch types and their corresponding directories
|
||||
declare -A branch_dirs=(
|
||||
["dev"]="test"
|
||||
["preprod"]="preprod"
|
||||
["master"]="master"
|
||||
)
|
||||
# List of branches
|
||||
|
||||
# All available branches
|
||||
branches=(
|
||||
"dev_odex-event"
|
||||
"dev_odex25_accounting"
|
||||
|
|
@ -74,24 +81,33 @@ branches=(
|
|||
"master_odex25_ensan"
|
||||
"master_odex25_donation"
|
||||
)
|
||||
# Loop through each branch
|
||||
|
||||
for branch in "${branches[@]}"; do
|
||||
# Extract the prefix (dev, preprod, master) and the branch name
|
||||
prefix="${branch%%_*}"
|
||||
folder_name="${branch#*_}"
|
||||
# Determine the base directory based on the prefix
|
||||
prefix="${branch%%_*}" # dev, preprod, master
|
||||
folder_name="${branch#*_}" # odex25_xxx
|
||||
base_dir="${branch_dirs[$prefix]}"
|
||||
# Full path for the folder inside the corresponding directory
|
||||
full_path="$base_dir/$folder_name"
|
||||
# Create the directory if it doesn't exist
|
||||
|
||||
if [[ -n "$TARGET_ENV" && "${branch_dirs[$prefix]}" != "$TARGET_ENV" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -d "$full_path/.git" ]]; then
|
||||
echo "Skipped $branch (already cloned)"
|
||||
continue
|
||||
elif [[ -d "$full_path" ]]; then
|
||||
echo "⚠️ Found existing folder without .git for $branch, deleting and recloning..."
|
||||
rm -rf "$full_path"
|
||||
fi
|
||||
|
||||
echo "Cloning $branch into $full_path..."
|
||||
mkdir -p "$full_path"
|
||||
# Clone the specific branch into the designated folder using token-based authentication
|
||||
git clone --depth=1 -b "$branch" "https://github.com/expsa/odex25-standard-modules.git" "$full_path"
|
||||
# Check if the clone was successful
|
||||
git clone --depth=1 -b "$branch" "$REPO_URL" "$full_path"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully cloned $branch into $full_path"
|
||||
echo "✅ Successfully cloned $branch into $full_path"
|
||||
else
|
||||
echo "Failed to clone $branch"
|
||||
exit 1
|
||||
echo "❌ Failed to clone $branch"
|
||||
rm -rf "$full_path" # Cleanup if clone failed
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in New Issue