Created
January 10, 2025 07:49
-
-
Save eduard-un/42f67e6a934c38ff8858e0e1fa52a6a4 to your computer and use it in GitHub Desktop.
Switch Github Branches:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
ROOT_DIR=$(pwd) | |
BOLD=$(tput bold) | |
NORMAL=$(tput sgr0) | |
function green { | |
printf "\e[32m%s\e[0m\n" "${1}" | |
} | |
# Array of paths and their corresponding names | |
declare -A REPOS=( | |
["/"]="ROOT" | |
["/ai-app/"]="AI" | |
["/cloud/"]="CLOUD" | |
["/common/"]="COMMON" | |
["/core/"]="CORE" | |
["/epanel/"]="EPANEL" | |
["/includes/builder/"]="BUILDER" | |
["/includes/builder-5/"]="BUILDER5" | |
) | |
read -p "Enter branch name: " BRANCH | |
BRANCH=${BRANCH:-master} # Default to master if none entered | |
echo -e "\n${BOLD}Pulling latest changes from ${BRANCH} branch in all repos:${NORMAL}\n" | |
# Function to process each repository | |
process_repo() { | |
local path=$1 | |
local name=$2 | |
echo -e "\nProcessing ${BOLD}${name}${NORMAL} at ${ROOT_DIR}${path}" | |
repo_path="${ROOT_DIR}${path}" | |
if [ ! -d "${repo_path}" ]; then | |
echo "Directory ${repo_path} does not exist. Skipping..." | |
return | |
fi | |
# Change directory explicitly for clarity | |
cd "${repo_path}" | |
# Skip stash if no changes | |
if ! git diff --quiet; then | |
echo "Stashing local changes..." | |
git stash | |
git stash drop || echo "No stash entries found" | |
fi | |
echo "Fetching and checking branch ${BRANCH}..." | |
git fetch --quiet origin | |
# Checkout branch if exists locally or remotely | |
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then | |
git checkout "${BRANCH}" --quiet | |
elif git ls-remote --heads origin "${BRANCH}" &> /dev/null; then | |
git checkout -b "${BRANCH}" origin/"${BRANCH}" --quiet | |
else | |
echo "Branch ${BRANCH} does not exist in ${name}" | |
return | |
fi | |
git pull --quiet || echo "Failed to pull latest changes in ${name}" | |
echo "${BOLD}${name}${NORMAL} updated to branch ${BRANCH}." | |
} | |
# Run all repository processing in parallel | |
for path in "${!REPOS[@]}"; do | |
process_repo "$path" "${REPOS[$path]}" & | |
done | |
# Wait for all background tasks to finish | |
wait | |
# Delete the et-cache folder | |
ET_CACHE_PATH="/Users/ed/Herd/d5/wp-content/et-cache" | |
if [ -d "$ET_CACHE_PATH" ]; then | |
echo -e "\nDeleting et-cache folder at $ET_CACHE_PATH..." | |
rm -rf "$ET_CACHE_PATH" | |
green "et-cache folder deleted successfully!" | |
else | |
echo -e "\net-cache folder does not exist at $ET_CACHE_PATH." | |
fi | |
wp plugin activate svg-support | |
wp plugin deactivate svg-support | |
green "${BOLD}All tasks completed!" | |
cd "$ROOT_DIR" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment